From beafd4e446c3b3872e14a3044eaa8ec1fa4e736b Mon Sep 17 00:00:00 2001 From: Aareon Sullivan Date: Sun, 14 Jan 2018 13:54:00 -0800 Subject: [PATCH 1/2] Use enumerate, remove random usages of exit codes As per the documentation for `sys.exit` most codes besides 0 and 1 are underdeveloped and produce mostly undefined results. Nothing wrong with sticking to the safe route. --- spotdl.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/spotdl.py b/spotdl.py index 17e5e65..c23c22d 100755 --- a/spotdl.py +++ b/spotdl.py @@ -72,12 +72,11 @@ def grab_list(text_file): except ValueError: pass log.info(u'Preparing to download {} songs'.format(len(lines))) - number = 1 - for raw_song in lines: + for number, raw_song in enumerate(lines): print('') try: - grab_single(raw_song, number=number) + grab_single(raw_song, number=number+1) # token expires after 1 hour except spotipy.client.SpotifyException: # refresh token when it expires @@ -100,7 +99,6 @@ def grab_list(text_file): log.debug('Removing downloaded song from text file') internals.trim_song(text_file) - number += 1 def grab_playlist(playlist): @@ -116,14 +114,14 @@ def grab_playlist(playlist): except IndexError: # Wrong format, in either case log.error('The provided playlist URL is not in a recognized format!') - sys.exit(10) + sys.exit(1) playlist_id = splits[-1] try: spotify_tools.write_playlist(username, playlist_id) except spotipy.client.SpotifyException: log.error('Unable to find playlist') log.info('Make sure the playlist is set to publicly visible and then try again') - sys.exit(11) + sys.exit(1) def grab_single(raw_song, number=None): @@ -221,4 +219,4 @@ if __name__ == '__main__': except KeyboardInterrupt as e: log.exception(e) - sys.exit(3) + sys.exit(1) From bb76220e864885f2ccd9e88f1fdc82592f6a2e2a Mon Sep 17 00:00:00 2001 From: Aareon Sullivan Date: Sun, 14 Jan 2018 14:18:24 -0800 Subject: [PATCH 2/2] Update spotdl.py --- spotdl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spotdl.py b/spotdl.py index c23c22d..66ded32 100755 --- a/spotdl.py +++ b/spotdl.py @@ -114,14 +114,14 @@ def grab_playlist(playlist): except IndexError: # Wrong format, in either case log.error('The provided playlist URL is not in a recognized format!') - sys.exit(1) + sys.exit(10) playlist_id = splits[-1] try: spotify_tools.write_playlist(username, playlist_id) except spotipy.client.SpotifyException: log.error('Unable to find playlist') log.info('Make sure the playlist is set to publicly visible and then try again') - sys.exit(1) + sys.exit(11) def grab_single(raw_song, number=None): @@ -219,4 +219,4 @@ if __name__ == '__main__': except KeyboardInterrupt as e: log.exception(e) - sys.exit(1) + sys.exit(3)