mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Fix encoding errors
This commit is contained in:
@@ -16,7 +16,7 @@ def song(input_song, output_song, avconv=False, verbose=False):
|
|||||||
else:
|
else:
|
||||||
exit_code = convert_with_ffmpeg(input_song, output_song, verbose)
|
exit_code = convert_with_ffmpeg(input_song, output_song, verbose)
|
||||||
return exit_code
|
return exit_code
|
||||||
return None
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def convert_with_avconv(input_song, output_song, verbose):
|
def convert_with_avconv(input_song, output_song, verbose):
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ def generate_token():
|
|||||||
def generate_search_url(song):
|
def generate_search_url(song):
|
||||||
"""Generate YouTube search URL for the given song."""
|
"""Generate YouTube search URL for the given song."""
|
||||||
# urllib2.quote() encodes URL with special characters
|
# urllib2.quote() encodes URL with special characters
|
||||||
url = "https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q={0}".format(
|
url = u"https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q={0}".format(
|
||||||
quote(song))
|
quote(song))
|
||||||
return url
|
return url
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ def filter_path(path):
|
|||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
for temp in os.listdir(path):
|
for temp in os.listdir(path):
|
||||||
if temp.endswith('.temp'):
|
if temp.endswith('.temp'):
|
||||||
os.remove('{0}/{1}'.format(path, temp))
|
os.remove(u'{0}/{1}'.format(path, temp))
|
||||||
|
|
||||||
|
|
||||||
def grace_quit():
|
def grace_quit():
|
||||||
|
|||||||
26
spotdl.py
26
spotdl.py
@@ -23,7 +23,7 @@ def generate_songname(raw_song):
|
|||||||
"""Generate a string of the format '[artist] - [song]' for the given song."""
|
"""Generate a string of the format '[artist] - [song]' for the given song."""
|
||||||
if misc.is_spotify(raw_song):
|
if misc.is_spotify(raw_song):
|
||||||
tags = generate_metadata(raw_song)
|
tags = generate_metadata(raw_song)
|
||||||
raw_song = '{0} - {1}'.format(tags['artists'][0]['name'], tags['name'])
|
raw_song = u'{0} - {1}'.format(tags['artists'][0]['name'], tags['name'])
|
||||||
return misc.fix_encoding(raw_song)
|
return misc.fix_encoding(raw_song)
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ def generate_youtube_url(raw_song):
|
|||||||
for x in items_parse.find_all('h3', {'class': 'yt-lockup-title'}):
|
for x in items_parse.find_all('h3', {'class': 'yt-lockup-title'}):
|
||||||
# confirm the video result is not an advertisement
|
# confirm the video result is not an advertisement
|
||||||
if x.find('channel') > -1 or x.find('googleads') > -1:
|
if x.find('channel') > -1 or x.find('googleads') > -1:
|
||||||
print('{0}. {1}'.format(check, x.get_text()))
|
print(u'{0}. {1}'.format(check, x.get_text()))
|
||||||
links.append(x.find('a')['href'])
|
links.append(x.find('a')['href'])
|
||||||
check += 1
|
check += 1
|
||||||
print('')
|
print('')
|
||||||
@@ -96,7 +96,7 @@ def generate_youtube_url(raw_song):
|
|||||||
attrs={'class': 'yt-uix-tile-link'})[check]['href']
|
attrs={'class': 'yt-uix-tile-link'})[check]['href']
|
||||||
check += 1
|
check += 1
|
||||||
|
|
||||||
full_link = 'youtube.com{0}'.format(result)
|
full_link = u'youtube.com{0}'.format(result)
|
||||||
return full_link
|
return full_link
|
||||||
|
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ def get_youtube_title(content, number=None):
|
|||||||
if number is None:
|
if number is None:
|
||||||
return title
|
return title
|
||||||
else:
|
else:
|
||||||
return '{0}. {1}'.format(number, title)
|
return u'{0}. {1}'.format(number, title)
|
||||||
|
|
||||||
|
|
||||||
def feed_playlist(username):
|
def feed_playlist(username):
|
||||||
@@ -129,7 +129,7 @@ def feed_playlist(username):
|
|||||||
# in rare cases, playlists may not be found, so playlists['next']
|
# in rare cases, playlists may not be found, so playlists['next']
|
||||||
# is None. Skip these. Also see Issue #91.
|
# is None. Skip these. Also see Issue #91.
|
||||||
if playlist['name'] is not None:
|
if playlist['name'] is not None:
|
||||||
print('{0}. {1} ({2} tracks)'.format(
|
print(u'{0}. {1} ({2} tracks)'.format(
|
||||||
check, misc.fix_encoding(playlist['name'])),
|
check, misc.fix_encoding(playlist['name'])),
|
||||||
playlist['tracks']['total'])
|
playlist['tracks']['total'])
|
||||||
links.append(playlist)
|
links.append(playlist)
|
||||||
@@ -144,8 +144,8 @@ def feed_playlist(username):
|
|||||||
results = spotify.user_playlist(
|
results = spotify.user_playlist(
|
||||||
playlist['owner']['id'], playlist['id'], fields='tracks,next')
|
playlist['owner']['id'], playlist['id'], fields='tracks,next')
|
||||||
print('')
|
print('')
|
||||||
file = '{0}.txt'.format(slugify(playlist['name'], ok='-_()[]{}'))
|
file = u'{0}.txt'.format(slugify(playlist['name'], ok='-_()[]{}'))
|
||||||
print('Feeding {0} tracks to {1}'.format(playlist['tracks']['total'], file))
|
print(u'Feeding {0} tracks to {1}'.format(playlist['tracks']['total'], file))
|
||||||
|
|
||||||
tracks = results['tracks']
|
tracks = results['tracks']
|
||||||
with open(file, 'a') as file_out:
|
with open(file, 'a') as file_out:
|
||||||
@@ -155,7 +155,7 @@ def feed_playlist(username):
|
|||||||
try:
|
try:
|
||||||
file_out.write(track['external_urls']['spotify'] + '\n')
|
file_out.write(track['external_urls']['spotify'] + '\n')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print('Skipping track {0} by {1} (local only?)'.format(
|
print(u'Skipping track {0} by {1} (local only?)'.format(
|
||||||
track['name'], track['artists'][0]['name']))
|
track['name'], track['artists'][0]['name']))
|
||||||
# 1 page = 50 results
|
# 1 page = 50 results
|
||||||
# check if there are more pages
|
# check if there are more pages
|
||||||
@@ -188,7 +188,7 @@ def check_exists(music_file, raw_song, islist=True):
|
|||||||
files = os.listdir('Music')
|
files = os.listdir('Music')
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith('.temp'):
|
if file.endswith('.temp'):
|
||||||
os.remove('Music/{0}'.format(file))
|
os.remove(u'Music/{0}'.format(file))
|
||||||
continue
|
continue
|
||||||
# check if any file with similar name is already present in Music/
|
# check if any file with similar name is already present in Music/
|
||||||
dfile = misc.fix_decoding(file)
|
dfile = misc.fix_decoding(file)
|
||||||
@@ -199,7 +199,7 @@ def check_exists(music_file, raw_song, islist=True):
|
|||||||
|
|
||||||
# if not, remove it and download again without prompt
|
# if not, remove it and download again without prompt
|
||||||
if misc.is_spotify(raw_song) and not already_tagged:
|
if misc.is_spotify(raw_song) and not already_tagged:
|
||||||
os.remove('Music/{0}'.format(file))
|
os.remove(u'Music/{0}'.format(file))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# do not prompt and skip the current song
|
# do not prompt and skip the current song
|
||||||
@@ -212,7 +212,7 @@ def check_exists(music_file, raw_song, islist=True):
|
|||||||
'Song with same name has already been downloaded. '
|
'Song with same name has already been downloaded. '
|
||||||
'Re-download? (y/n): ').lower()
|
'Re-download? (y/n): ').lower()
|
||||||
if prompt == 'y':
|
if prompt == 'y':
|
||||||
os.remove('Music/{0}'.format(file))
|
os.remove(u'Music/{0}'.format(file))
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
@@ -228,7 +228,7 @@ def grab_list(file):
|
|||||||
lines.remove('')
|
lines.remove('')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
print('Total songs in list: {0} songs'.format(len(lines)))
|
print(u'Total songs in list: {0} songs'.format(len(lines)))
|
||||||
print('')
|
print('')
|
||||||
# nth input song
|
# nth input song
|
||||||
number = 1
|
number = 1
|
||||||
@@ -283,7 +283,7 @@ def grab_single(raw_song, number=None):
|
|||||||
output_song = music_file + args.output_ext
|
output_song = music_file + args.output_ext
|
||||||
convert.song(input_song, output_song, avconv=args.avconv,
|
convert.song(input_song, output_song, avconv=args.avconv,
|
||||||
verbose=args.verbose)
|
verbose=args.verbose)
|
||||||
os.remove('Music/{0}'.format(file))
|
os.remove(u'Music/{0}'.format(file))
|
||||||
meta_tags = generate_metadata(raw_song)
|
meta_tags = generate_metadata(raw_song)
|
||||||
if not args.no_metadata:
|
if not args.no_metadata:
|
||||||
metadata.embed(output_song, meta_tags)
|
metadata.embed(output_song, meta_tags)
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ def test_download():
|
|||||||
|
|
||||||
|
|
||||||
def test_convert():
|
def test_convert():
|
||||||
# exit code None = success
|
# exit code 0 = success
|
||||||
expect_convert = None
|
expect_convert = 0
|
||||||
content = spotdl.go_pafy(raw_song)
|
content = spotdl.go_pafy(raw_song)
|
||||||
music_file = spotdl.misc.generate_filename(content.title)
|
music_file = spotdl.misc.generate_filename(content.title)
|
||||||
music_file = spotdl.misc.fix_decoding(music_file)
|
music_file = spotdl.misc.fix_decoding(music_file)
|
||||||
|
|||||||
Reference in New Issue
Block a user