From 6075a829e501bcc0a4522aa82961104de7bccfff Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Thu, 30 Nov 2017 10:44:46 +0530 Subject: [PATCH] Return codes depicting success/failure (#164) * Add error codes for fetch playlist failures * Add return codes to README.md --- README.md | 8 ++++++++ spotdl.py | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a567777..6c70de7 100755 --- a/README.md +++ b/README.md @@ -204,6 +204,14 @@ Beside some other characters, spaces will be replaced by underscores. There's no Just make sure your working directory is the one you have the music files in. +## Return codes + +- `0` - Success +- `1` - Unknown error +- `2` - Command line error (e.g. invalid args) +- `10` - Invalid playlist URL +- `11` - Playlist not found + ## Running tests ``` diff --git a/spotdl.py b/spotdl.py index aa7ca58..6c6c000 100755 --- a/spotdl.py +++ b/spotdl.py @@ -337,13 +337,19 @@ def grab_playlist(playlist): else: splits = playlist.split(':') - username = splits[-3] + try: + username = splits[-3] + except IndexError: + # Wrong format, in either case + print('The provided playlist URL is not in a recognized format!') + sys.exit(10) playlist_id = splits[-1] try: write_playlist(username, playlist_id) except spotipy.client.SpotifyException: print('Unable to find playlist') print('Make sure the playlist is set to publicly visible and then try again') + sys.exit(11) def grab_album(album):