Message on unavailable local tracks

This commit is contained in:
Ritiek
2017-06-18 02:16:25 +05:30
parent 9236affd0e
commit c270aa8365
2 changed files with 13 additions and 12 deletions

View File

@@ -64,6 +64,17 @@ def is_spotify(raw_song):
else: else:
return False return False
# write tracks into list file
def feed_tracks(file, tracks):
with open(file, 'a') as fout:
for item in tracks['items']:
track = item['track']
try:
fout.write(track['external_urls']['spotify'] + '\n')
except KeyError:
title = track['name'] + ' by '+ track['artists'][0]['name']
print('Skipping track ' + title + ' (local only?)')
# generate filename of the song to be downloaded # generate filename of the song to be downloaded
def generate_filename(title): def generate_filename(title):
raw_title = title.replace(' ', '_') raw_title = title.replace(' ', '_')

View File

@@ -98,16 +98,6 @@ def get_YouTube_title(content, number):
else: else:
return str(number) + '. ' + title return str(number) + '. ' + title
# write tracks into list file
def feed_tracks(file, tracks):
with open(file, 'a') as fout:
for item in tracks['items']:
track = item['track']
try:
fout.write(track['external_urls']['spotify'] + '\n')
except KeyError:
pass
# fetch user playlists when using -u option # fetch user playlists when using -u option
def feed_playlist(username): def feed_playlist(username):
playlists = spotify.user_playlists(username) playlists = spotify.user_playlists(username)
@@ -125,10 +115,10 @@ def feed_playlist(username):
file = slugify(playlist['name'], ok='-_()[]{}') + '.txt' file = slugify(playlist['name'], ok='-_()[]{}') + '.txt'
print('Feeding ' + str(playlist['tracks']['total']) + ' tracks to ' + file) print('Feeding ' + str(playlist['tracks']['total']) + ' tracks to ' + file)
tracks = results['tracks'] tracks = results['tracks']
feed_tracks(file, tracks) misc.feed_tracks(file, tracks)
while tracks['next']: while tracks['next']:
tracks = spotify.next(tracks) tracks = spotify.next(tracks)
feed_tracks(file, tracks) misc.feed_tracks(file, tracks)
def download_song(content): def download_song(content):
music_file = misc.generate_filename(content.title) music_file = misc.generate_filename(content.title)