From c9b6577f5a74df47d12a0f73d64e4fb7c048001e Mon Sep 17 00:00:00 2001 From: Karan Date: Thu, 28 Jan 2016 14:22:36 +0530 Subject: [PATCH] user download option --- spotify-dl.py | 13 ++++++++++++- spotify.py | 6 +++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spotify-dl.py b/spotify-dl.py index 3bcec887..974234dc 100644 --- a/spotify-dl.py +++ b/spotify-dl.py @@ -15,11 +15,22 @@ parser = argparse.ArgumentParser(prog='spotify-dl') parser.add_argument('-d', '--download', action='store_true', help='Download using youtube-dl') parser.add_argument('-V', '--verbose', action='store_true', help='Show more information on what''s happening.') + parser.add_argument('-o' , '--output',type=str,action='store',nargs='*',help='Specify download diretory.') args = parser.parse_args() if args.verbose: log.setLevel(logging.DEBUG) token = authenticate() + if args.output: + download_directory = args.output[0] + #Check whether directory has a trailing slash or not + if len(download_directory) >=0 and download_directory[-1] != '/': + download_directory+='/' + else: + download_directory='' + + + sp = spotipy.Spotify(auth=token) songs = fetch_saved_tracks(sp) url = [] @@ -29,4 +40,4 @@ url.append(link) save_songs_to_file(url) if args.download == True: - download_songs(url) + download_songs(url,download_directory) diff --git a/spotify.py b/spotify.py index ca86922e..b1bb121e 100644 --- a/spotify.py +++ b/spotify.py @@ -9,7 +9,7 @@ def authenticate(): - return util.prompt_for_user_token(username,scope, CLIENT_ID, CLIENT_SECRET, REDIRECT_URL) + return util.prompt_for_user_token(username,scope, CLIENT_ID, CLIENT_SECRET) def fetch_saved_tracks(sp): @@ -37,11 +37,11 @@ def save_songs_to_file(songs): f.close() -def download_songs(songs): +def download_songs(songs,download_directory): ydl_opts = { 'format': 'bestaudio/best', 'download_archive': 'downloaded_songs.txt', - 'outtmpl': '~/Music/%(title)s.%(ext)s', + 'outtmpl': download_directory+'%(title)s.%(ext)s', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3',