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: | ||||
|             exit_code = convert_with_ffmpeg(input_song, output_song, verbose) | ||||
|         return exit_code | ||||
|     return None | ||||
|     return 0 | ||||
|  | ||||
|  | ||||
| def convert_with_avconv(input_song, output_song, verbose): | ||||
|   | ||||
| @@ -110,7 +110,7 @@ def generate_token(): | ||||
| def generate_search_url(song): | ||||
|     """Generate YouTube search URL for the given song.""" | ||||
|     # 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)) | ||||
|     return url | ||||
|  | ||||
| @@ -135,7 +135,7 @@ def filter_path(path): | ||||
|         os.makedirs(path) | ||||
|     for temp in os.listdir(path): | ||||
|         if temp.endswith('.temp'): | ||||
|             os.remove('{0}/{1}'.format(path, temp)) | ||||
|             os.remove(u'{0}/{1}'.format(path, temp)) | ||||
|  | ||||
|  | ||||
| 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.""" | ||||
|     if misc.is_spotify(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) | ||||
|  | ||||
|  | ||||
| @@ -76,7 +76,7 @@ def generate_youtube_url(raw_song): | ||||
|         for x in items_parse.find_all('h3', {'class': 'yt-lockup-title'}): | ||||
|             # confirm the video result is not an advertisement | ||||
|             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']) | ||||
|                 check += 1 | ||||
|         print('') | ||||
| @@ -96,7 +96,7 @@ def generate_youtube_url(raw_song): | ||||
|                 attrs={'class': 'yt-uix-tile-link'})[check]['href'] | ||||
|             check += 1 | ||||
|  | ||||
|     full_link = 'youtube.com{0}'.format(result) | ||||
|     full_link = u'youtube.com{0}'.format(result) | ||||
|     return full_link | ||||
|  | ||||
|  | ||||
| @@ -115,7 +115,7 @@ def get_youtube_title(content, number=None): | ||||
|     if number is None: | ||||
|         return title | ||||
|     else: | ||||
|         return '{0}. {1}'.format(number, title) | ||||
|         return u'{0}. {1}'.format(number, title) | ||||
|  | ||||
|  | ||||
| def feed_playlist(username): | ||||
| @@ -129,7 +129,7 @@ def feed_playlist(username): | ||||
|             # in rare cases, playlists may not be found, so playlists['next'] | ||||
|             # is None. Skip these. Also see Issue #91. | ||||
|             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'])), | ||||
|                     playlist['tracks']['total']) | ||||
|                 links.append(playlist) | ||||
| @@ -144,8 +144,8 @@ def feed_playlist(username): | ||||
|     results = spotify.user_playlist( | ||||
|         playlist['owner']['id'], playlist['id'], fields='tracks,next') | ||||
|     print('') | ||||
|     file = '{0}.txt'.format(slugify(playlist['name'], ok='-_()[]{}')) | ||||
|     print('Feeding {0} tracks to {1}'.format(playlist['tracks']['total'], file)) | ||||
|     file = u'{0}.txt'.format(slugify(playlist['name'], ok='-_()[]{}')) | ||||
|     print(u'Feeding {0} tracks to {1}'.format(playlist['tracks']['total'], file)) | ||||
|  | ||||
|     tracks = results['tracks'] | ||||
|     with open(file, 'a') as file_out: | ||||
| @@ -155,7 +155,7 @@ def feed_playlist(username): | ||||
|                 try: | ||||
|                     file_out.write(track['external_urls']['spotify'] + '\n') | ||||
|                 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'])) | ||||
|             # 1 page = 50 results | ||||
|             # check if there are more pages | ||||
| @@ -188,7 +188,7 @@ def check_exists(music_file, raw_song, islist=True): | ||||
|     files = os.listdir('Music') | ||||
|     for file in files: | ||||
|         if file.endswith('.temp'): | ||||
|             os.remove('Music/{0}'.format(file)) | ||||
|             os.remove(u'Music/{0}'.format(file)) | ||||
|             continue | ||||
|         # check if any file with similar name is already present in Music/ | ||||
|         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 misc.is_spotify(raw_song) and not already_tagged: | ||||
|                 os.remove('Music/{0}'.format(file)) | ||||
|                 os.remove(u'Music/{0}'.format(file)) | ||||
|                 return False | ||||
|  | ||||
|             # 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. ' | ||||
|                     'Re-download? (y/n): ').lower() | ||||
|                 if prompt == 'y': | ||||
|                     os.remove('Music/{0}'.format(file)) | ||||
|                     os.remove(u'Music/{0}'.format(file)) | ||||
|                     return False | ||||
|                 else: | ||||
|                     return True | ||||
| @@ -228,7 +228,7 @@ def grab_list(file): | ||||
|         lines.remove('') | ||||
|     except ValueError: | ||||
|         pass | ||||
|     print('Total songs in list: {0} songs'.format(len(lines))) | ||||
|     print(u'Total songs in list: {0} songs'.format(len(lines))) | ||||
|     print('') | ||||
|     # nth input song | ||||
|     number = 1 | ||||
| @@ -283,7 +283,7 @@ def grab_single(raw_song, number=None): | ||||
|             output_song = music_file + args.output_ext | ||||
|             convert.song(input_song, output_song, avconv=args.avconv, | ||||
|                          verbose=args.verbose) | ||||
|             os.remove('Music/{0}'.format(file)) | ||||
|             os.remove(u'Music/{0}'.format(file)) | ||||
|             meta_tags = generate_metadata(raw_song) | ||||
|             if not args.no_metadata: | ||||
|                 metadata.embed(output_song, meta_tags) | ||||
|   | ||||
| @@ -41,8 +41,8 @@ def test_download(): | ||||
|  | ||||
|  | ||||
| def test_convert(): | ||||
|     # exit code None = success | ||||
|     expect_convert = None | ||||
|     # exit code 0 = success | ||||
|     expect_convert = 0 | ||||
|     content = spotdl.go_pafy(raw_song) | ||||
|     music_file = spotdl.misc.generate_filename(content.title) | ||||
|     music_file = spotdl.misc.fix_decoding(music_file) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user