Exposed Spotify Client ID/Secret in config.yml

This commit is contained in:
Manveer Basra
2018-10-30 14:12:37 -04:00
committed by Ritiek Malhotra
parent 0492c711cc
commit d215ce685d
3 changed files with 37 additions and 10 deletions

View File

@@ -34,6 +34,8 @@ default_conf = {
"skip": None, "skip": None,
"write-successful": None, "write-successful": None,
"log-level": "INFO", "log-level": "INFO",
"spotify_client_id": "4fe3fecfe5334023a1472516cc99d805",
"spotify_client_secret": "0f02b7c483c04257984695007a4a8d5c"
} }
} }
@@ -260,6 +262,18 @@ def get_arguments(raw_args=None, to_group=True, to_merge=True):
default=config["write-successful"], default=config["write-successful"],
help="path to file to write successful tracks to", help="path to file to write successful tracks to",
) )
parser.add_argument(
"-sci",
"--spotify-client-id",
default=config["spotify_client_id"],
help=argparse.SUPPRESS
)
parser.add_argument(
"-scs",
"--spotify-client-secret",
default=config["spotify_client_secret"],
help=argparse.SUPPRESS
)
parser.add_argument( parser.add_argument(
"-c", "--config", default=None, help="path to custom config.yml file" "-c", "--config", default=None, help="path to custom config.yml file"
) )

View File

@@ -51,6 +51,7 @@ def main():
internals.filter_path(const.args.folder) internals.filter_path(const.args.folder)
youtube_tools.set_api_key() youtube_tools.set_api_key()
spotify_tools.set_client_credentials()
logzero.setup_default_logger(formatter=const._formatter, level=const.args.log_level) logzero.setup_default_logger(formatter=const._formatter, level=const.args.log_level)

View File

@@ -12,9 +12,18 @@ import os
from spotdl import const from spotdl import const
from spotdl import internals from spotdl import internals
spotify = None
def generate_token(): def generate_token():
""" Generate the token. Please respect these credentials :) """ """ Generate the token. """
if const.args.spotify_client_id and const.args.spotify_client_secret:
credentials = oauth2.SpotifyClientCredentials(
client_id=const.args.spotify_client_id,
client_secret=const.args.spotify_client_secret,
)
else:
# Please respect these credentials :)
credentials = oauth2.SpotifyClientCredentials( credentials = oauth2.SpotifyClientCredentials(
client_id="4fe3fecfe5334023a1472516cc99d805", client_id="4fe3fecfe5334023a1472516cc99d805",
client_secret="0f02b7c483c04257984695007a4a8d5c", client_secret="0f02b7c483c04257984695007a4a8d5c",
@@ -24,16 +33,19 @@ def generate_token():
def refresh_token(): def refresh_token():
""" Refresh expired token""" """ Refresh expired token. """
global spotify global spotify
new_token = generate_token() new_token = generate_token()
spotify = spotipy.Spotify(auth=new_token) spotify = spotipy.Spotify(auth=new_token)
def set_client_credentials():
""" Setup and initialize Spotipy object. """
# token is mandatory when using Spotify's API # token is mandatory when using Spotify's API
# https://developer.spotify.com/news-stories/2017/01/27/removing-unauthenticated-calls-to-the-web-api/ # https://developer.spotify.com/news-stories/2017/01/27/removing-unauthenticated-calls-to-the-web-api/
_token = generate_token() global spotify
spotify = spotipy.Spotify(auth=_token) token = generate_token()
spotify = spotipy.Spotify(auth=token)
def generate_metadata(raw_song): def generate_metadata(raw_song):