From 6a808b68b388ff42260dc40f5b4d6a2783ff4e2f Mon Sep 17 00:00:00 2001 From: Footsiefat <12180913+Footsiefat@users.noreply.github.com> Date: Fri, 22 Oct 2021 17:26:28 +1300 Subject: [PATCH 1/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0114cf4..fb4ffba 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

-[Discord Server](https://discord.gg/skVNQKtyFq) - [Matrix Server](https://matrix.to/#/#zspotify:matrix.org) - [Gitea Mirror](https://git.robinsmediateam.dev/Footsiefat/zspotify) +[Discord Server](https://discord.gg/skVNQKtyFq) - [Matrix Server](https://matrix.to/#/#zspotify:matrix.org) - [Gitea Mirror](https://git.robinsmediateam.dev/Footsiefat/zspotify) - [Main Site](https://footsiefat.github.io/) ``` Requirements: From b1df2c42d95cbb8f77dc976486b8af3c50755993 Mon Sep 17 00:00:00 2001 From: logykk Date: Fri, 22 Oct 2021 18:17:05 +1300 Subject: [PATCH 2/3] added support for selecting multiple options in search --- zspotify.py | 54 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/zspotify.py b/zspotify.py index 4f2b8b6..340dcb7 100755 --- a/zspotify.py +++ b/zspotify.py @@ -44,6 +44,8 @@ OVERRIDE_AUTO_WAIT = False CHUNK_SIZE = 50000 # miscellaneous functions for general use + + def clear(): """ Clear the console window """ if platform.system() == "Windows": @@ -67,6 +69,20 @@ def sanitize_data(value): return value.replace("|", "-") +def split_input(selection): + """ Returns a list of inputted strings """ + inputs = [] + if "-" in selection: + for number in range(int(selection.split("-")[0]), int(selection.split("-")[1]) + 1): + inputs.append(number) + return inputs + else: + selections = selection.split(",") + for i in selections: + inputs.append(i.strip()) + return inputs + + def splash(): """ Displays splash screen """ print("=================================\n" @@ -366,22 +382,25 @@ def search(search_term): if len(tracks) + len(albums) + len(playlists) == 0: print("NO RESULTS FOUND - EXITING...") else: - position = int(input("SELECT ITEM BY ID: ")) - - if position <= total_tracks: - track_id = tracks[position - 1]["id"] - download_track(track_id) - elif position <= total_albums + total_tracks: - download_album(albums[position - total_tracks - 1]["id"]) - else: - playlist_choice = playlists[position - - total_tracks - total_albums - 1] - playlist_songs = get_playlist_songs(token, playlist_choice['id']) - for song in playlist_songs: - if song['track']['id'] is not None: - download_track(song['track']['id'], sanitize_data( - playlist_choice['name'].strip()) + "/") - print("\n") + selection = str(input("SELECT ITEM(S) BY ID: ")) + inputs = split_input(selection) + for pos in inputs: + position = int(pos) + if position <= total_tracks: + track_id = tracks[position - 1]["id"] + download_track(track_id) + elif position <= total_albums + total_tracks: + download_album(albums[position - total_tracks - 1]["id"]) + else: + playlist_choice = playlists[position - + total_tracks - total_albums - 1] + playlist_songs = get_playlist_songs( + token, playlist_choice['id']) + for song in playlist_songs: + if song['track']['id'] is not None: + download_track(song['track']['id'], sanitize_data( + playlist_choice['name'].strip()) + "/") + print("\n") def get_song_info(song_id): @@ -600,7 +619,8 @@ def download_track(track_id_str: str, extra_paths=""): unit_divisor=1024 ) as bar: for _ in range(int(total_size / CHUNK_SIZE) + 1): - bar.update(file.write(stream.input_stream.stream().read(CHUNK_SIZE))) + bar.update(file.write( + stream.input_stream.stream().read(CHUNK_SIZE))) if not RAW_AUDIO_AS_IS: convert_audio_format(filename) From cb7173280b0bd1b1cd78b0eef99f3276bbdf4da9 Mon Sep 17 00:00:00 2001 From: Logykk <35679186+logykk@users.noreply.github.com> Date: Fri, 22 Oct 2021 18:17:59 +1300 Subject: [PATCH 3/3] Support for selecting multiple options from search --- zspotify.py | 54 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/zspotify.py b/zspotify.py index 4f2b8b6..340dcb7 100755 --- a/zspotify.py +++ b/zspotify.py @@ -44,6 +44,8 @@ OVERRIDE_AUTO_WAIT = False CHUNK_SIZE = 50000 # miscellaneous functions for general use + + def clear(): """ Clear the console window """ if platform.system() == "Windows": @@ -67,6 +69,20 @@ def sanitize_data(value): return value.replace("|", "-") +def split_input(selection): + """ Returns a list of inputted strings """ + inputs = [] + if "-" in selection: + for number in range(int(selection.split("-")[0]), int(selection.split("-")[1]) + 1): + inputs.append(number) + return inputs + else: + selections = selection.split(",") + for i in selections: + inputs.append(i.strip()) + return inputs + + def splash(): """ Displays splash screen """ print("=================================\n" @@ -366,22 +382,25 @@ def search(search_term): if len(tracks) + len(albums) + len(playlists) == 0: print("NO RESULTS FOUND - EXITING...") else: - position = int(input("SELECT ITEM BY ID: ")) - - if position <= total_tracks: - track_id = tracks[position - 1]["id"] - download_track(track_id) - elif position <= total_albums + total_tracks: - download_album(albums[position - total_tracks - 1]["id"]) - else: - playlist_choice = playlists[position - - total_tracks - total_albums - 1] - playlist_songs = get_playlist_songs(token, playlist_choice['id']) - for song in playlist_songs: - if song['track']['id'] is not None: - download_track(song['track']['id'], sanitize_data( - playlist_choice['name'].strip()) + "/") - print("\n") + selection = str(input("SELECT ITEM(S) BY ID: ")) + inputs = split_input(selection) + for pos in inputs: + position = int(pos) + if position <= total_tracks: + track_id = tracks[position - 1]["id"] + download_track(track_id) + elif position <= total_albums + total_tracks: + download_album(albums[position - total_tracks - 1]["id"]) + else: + playlist_choice = playlists[position - + total_tracks - total_albums - 1] + playlist_songs = get_playlist_songs( + token, playlist_choice['id']) + for song in playlist_songs: + if song['track']['id'] is not None: + download_track(song['track']['id'], sanitize_data( + playlist_choice['name'].strip()) + "/") + print("\n") def get_song_info(song_id): @@ -600,7 +619,8 @@ def download_track(track_id_str: str, extra_paths=""): unit_divisor=1024 ) as bar: for _ in range(int(total_size / CHUNK_SIZE) + 1): - bar.update(file.write(stream.input_stream.stream().read(CHUNK_SIZE))) + bar.update(file.write( + stream.input_stream.stream().read(CHUNK_SIZE))) if not RAW_AUDIO_AS_IS: convert_audio_format(filename)