From 5358d6f8eeb6b4d513dab3a145a22a9cef282cc5 Mon Sep 17 00:00:00 2001 From: mockuser404 <53865090+mockuser404@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:55:27 +0530 Subject: [PATCH 1/6] fix podcast existing episodes not skipping Skip if existing episodes. --- zspotify/podcast.py | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/zspotify/podcast.py b/zspotify/podcast.py index 4b0b3b60..437e769e 100644 --- a/zspotify/podcast.py +++ b/zspotify/podcast.py @@ -5,11 +5,11 @@ from librespot.audio.decoders import VorbisOnlyAudioQuality from librespot.metadata import EpisodeId from tqdm import tqdm -from const import NAME, ERROR, SHOW, ITEMS, ID, ROOT_PODCAST_PATH, CHUNK_SIZE -from utils import sanitize_data, create_download_directory, MusicFormat +from const import (CHUNK_SIZE, ERROR, ID, ITEMS, NAME, ROOT_PODCAST_PATH, SHOW, + SKIP_EXISTING_FILES) +from utils import MusicFormat, create_download_directory, sanitize_data from zspotify import ZSpotify - EPISODE_INFO_URL = 'https://api.spotify.com/v1/episodes' SHOWS_URL = 'https://api.spotify.com/v1/shows' @@ -55,16 +55,32 @@ def download_episode(episode_id) -> None: ZSpotify.get_config(ROOT_PODCAST_PATH), extra_paths, ) + download_directory = os.path.realpath(download_directory) create_download_directory(download_directory) total_size = stream.input_stream.size - with open(os.path.join(download_directory, f"{filename}.ogg"), - 'wb') as file, tqdm( - desc=filename, - total=total_size, - unit='B', - unit_scale=True, - unit_divisor=1024 + + filepath = os.path.join(download_directory, f"{filename}.ogg") + if ( + os.path.isfile(filepath) + and os.path.getsize(filepath) == total_size + and ZSpotify.get_config(SKIP_EXISTING_FILES) + ): + print( + "\n### SKIPPING:", + podcast_name, + "-", + episode_name, + "(EPISODE ALREADY EXISTS) ###", + ) + return + + with open(filepath, 'wb') as file, tqdm( + desc=filename, + total=total_size, + unit='B', + unit_scale=True, + unit_divisor=1024 ) as bar: for _ in range(int(total_size / ZSpotify.get_config(CHUNK_SIZE)) + 1): bar.update(file.write( From 8e77cea4d1361b2490369194378a44db5f31841d Mon Sep 17 00:00:00 2001 From: mockuser404 <53865090+mockuser404@users.noreply.github.com> Date: Wed, 27 Oct 2021 12:58:14 +0530 Subject: [PATCH 2/6] Update podcast.py --- zspotify/podcast.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zspotify/podcast.py b/zspotify/podcast.py index 437e769e..03bc7b35 100644 --- a/zspotify/podcast.py +++ b/zspotify/podcast.py @@ -7,7 +7,7 @@ from tqdm import tqdm from const import (CHUNK_SIZE, ERROR, ID, ITEMS, NAME, ROOT_PODCAST_PATH, SHOW, SKIP_EXISTING_FILES) -from utils import MusicFormat, create_download_directory, sanitize_data +from utils import create_download_directory, sanitize_data from zspotify import ZSpotify EPISODE_INFO_URL = 'https://api.spotify.com/v1/episodes' From 0915741249f3ac711065eaba6f39ac7d49608a8e Mon Sep 17 00:00:00 2001 From: yiannisha Date: Wed, 27 Oct 2021 21:43:35 +0300 Subject: [PATCH 3/6] Added digit prefixes to playlist track names --- zspotify/playlist.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zspotify/playlist.py b/zspotify/playlist.py index 9a1304c2..cf333d1b 100644 --- a/zspotify/playlist.py +++ b/zspotify/playlist.py @@ -52,10 +52,12 @@ def download_playlist(playlist): playlist_songs = [song for song in get_playlist_songs(playlist[ID]) if song[TRACK][ID]] p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True) + enum = 1 for song in p_bar: download_track(song[TRACK][ID], sanitize_data(playlist[NAME].strip()) + '/', - disable_progressbar=True) + prefix=True, prefix_value=str(enum) ,disable_progressbar=True) p_bar.set_description(song[TRACK][NAME]) + enum += 1 def download_from_user_playlist(): From 371de63d21f6b0e4c2173dbb8eb131f7ed385b78 Mon Sep 17 00:00:00 2001 From: yiannisha Date: Wed, 27 Oct 2021 22:14:35 +0300 Subject: [PATCH 4/6] Revert "Added digit prefixes to playlist track names" This reverts commit 0915741249f3ac711065eaba6f39ac7d49608a8e. --- zspotify/playlist.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/zspotify/playlist.py b/zspotify/playlist.py index cf333d1b..9a1304c2 100644 --- a/zspotify/playlist.py +++ b/zspotify/playlist.py @@ -52,12 +52,10 @@ def download_playlist(playlist): playlist_songs = [song for song in get_playlist_songs(playlist[ID]) if song[TRACK][ID]] p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True) - enum = 1 for song in p_bar: download_track(song[TRACK][ID], sanitize_data(playlist[NAME].strip()) + '/', - prefix=True, prefix_value=str(enum) ,disable_progressbar=True) + disable_progressbar=True) p_bar.set_description(song[TRACK][NAME]) - enum += 1 def download_from_user_playlist(): From 9ec6c9d1b102e2ee941e9aff081bbe2a4f6d1217 Mon Sep 17 00:00:00 2001 From: yiannisha Date: Wed, 27 Oct 2021 22:18:39 +0300 Subject: [PATCH 5/6] Added digit prefixes to playlist track names fixes#138 --- zspotify/playlist.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/zspotify/playlist.py b/zspotify/playlist.py index 9a1304c2..cf333d1b 100644 --- a/zspotify/playlist.py +++ b/zspotify/playlist.py @@ -52,10 +52,12 @@ def download_playlist(playlist): playlist_songs = [song for song in get_playlist_songs(playlist[ID]) if song[TRACK][ID]] p_bar = tqdm(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True) + enum = 1 for song in p_bar: download_track(song[TRACK][ID], sanitize_data(playlist[NAME].strip()) + '/', - disable_progressbar=True) + prefix=True, prefix_value=str(enum) ,disable_progressbar=True) p_bar.set_description(song[TRACK][NAME]) + enum += 1 def download_from_user_playlist(): From 8ff7c07ccf3c9b3f03606d510e83a5838ea9367c Mon Sep 17 00:00:00 2001 From: yiannisha Date: Wed, 27 Oct 2021 22:23:40 +0300 Subject: [PATCH 6/6] Added 'user-library-read' token for saved tracks fixes#154 --- zspotify/const.py | 2 ++ zspotify/zspotify.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/zspotify/const.py b/zspotify/const.py index 1ec7594a..73c5e9c1 100644 --- a/zspotify/const.py +++ b/zspotify/const.py @@ -72,6 +72,8 @@ USER_READ_EMAIL = 'user-read-email' PLAYLIST_READ_PRIVATE = 'playlist-read-private' +USER_LIBRARY_READ = 'user-library-read' + WINDOWS_SYSTEM = 'Windows' CREDENTIALS_JSON = 'credentials.json' diff --git a/zspotify/zspotify.py b/zspotify/zspotify.py index 5739dfa5..7d934454 100644 --- a/zspotify/zspotify.py +++ b/zspotify/zspotify.py @@ -18,7 +18,7 @@ from librespot.core import Session from const import CREDENTIALS_JSON, TYPE, \ PREMIUM, USER_READ_EMAIL, AUTHORIZATION, OFFSET, LIMIT, CONFIG_FILE_PATH, FORCE_PREMIUM, \ - PLAYLIST_READ_PRIVATE, CONFIG_DEFAULT_SETTINGS + PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ, CONFIG_DEFAULT_SETTINGS from utils import MusicFormat @@ -74,7 +74,7 @@ class ZSpotify: @classmethod def __get_auth_token(cls): - return cls.SESSION.tokens().get_token(USER_READ_EMAIL, PLAYLIST_READ_PRIVATE).access_token + return cls.SESSION.tokens().get_token(USER_READ_EMAIL, PLAYLIST_READ_PRIVATE, USER_LIBRARY_READ).access_token @classmethod def get_auth_header(cls):