Skip to content

Commit

Permalink
user download option
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan authored and Karan committed Jan 28, 2016
1 parent d2f2a03 commit c9b6577
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion spotify-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -29,4 +40,4 @@
url.append(link)
save_songs_to_file(url)
if args.download == True:
download_songs(url)
download_songs(url,download_directory)
6 changes: 3 additions & 3 deletions spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit c9b6577

Please sign in to comment.