From 8f7970b2643379c26f2cfcc739df69b31baabd7b Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 18 Dec 2023 20:34:36 +0100 Subject: [PATCH 1/6] get_library_songs, get_library_upload_songs: fix empty result for libraries containing exactly 1 song --- ytmusicapi/mixins/uploads.py | 7 +++++-- ytmusicapi/parsers/library.py | 9 ++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ytmusicapi/mixins/uploads.py b/ytmusicapi/mixins/uploads.py index e63bb19..924dc9d 100644 --- a/ytmusicapi/mixins/uploads.py +++ b/ytmusicapi/mixins/uploads.py @@ -7,12 +7,14 @@ from ytmusicapi.helpers import * from ytmusicapi.navigation import * from ytmusicapi.continuations import get_continuations -from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists, get_library_contents +from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists, get_library_contents, \ + pop_songs_random_mix from ytmusicapi.parsers.albums import parse_album_header from ytmusicapi.parsers.uploads import parse_uploaded_items class UploadsMixin: + def get_library_upload_songs(self, limit: int = 25, order: str = None) -> List[Dict]: """ Returns a list of uploaded songs @@ -44,9 +46,10 @@ def get_library_upload_songs(self, limit: int = 25, order: str = None) -> List[D body["params"] = prepare_order_params(order) response = self._send_request(endpoint, body) results = get_library_contents(response, MUSIC_SHELF) + pop_songs_random_mix(results['contents']) if results is None: return [] - songs = parse_uploaded_items(results['contents'][1:]) + songs = parse_uploaded_items(results['contents']) if 'continuations' in results: request_func = lambda additionalParams: self._send_request( diff --git a/ytmusicapi/parsers/library.py b/ytmusicapi/parsers/library.py index 1fa35c1..48249f0 100644 --- a/ytmusicapi/parsers/library.py +++ b/ytmusicapi/parsers/library.py @@ -75,11 +75,18 @@ def parse_library_artists(response, request_func, limit): return artists +def pop_songs_random_mix(results) -> None: + """remove the random mix that conditionally appears at the start of library songs""" + if len(results) >= 2: + results.pop(0) + + def parse_library_songs(response): results = get_library_contents(response, MUSIC_SHELF) + pop_songs_random_mix(results['contents']) return { 'results': results, - 'parsed': parse_playlist_items(results['contents'][1:]) if results else results + 'parsed': parse_playlist_items(results['contents']) if results else results } From bd7a6b452d8dd80e3f82db9b4c2c45733121acb4 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 18 Dec 2023 21:02:29 +0100 Subject: [PATCH 2/6] fix poop_songs_random_mix --- ytmusicapi/mixins/uploads.py | 2 +- ytmusicapi/parsers/library.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ytmusicapi/mixins/uploads.py b/ytmusicapi/mixins/uploads.py index 924dc9d..c4bbcf4 100644 --- a/ytmusicapi/mixins/uploads.py +++ b/ytmusicapi/mixins/uploads.py @@ -46,7 +46,7 @@ def get_library_upload_songs(self, limit: int = 25, order: str = None) -> List[D body["params"] = prepare_order_params(order) response = self._send_request(endpoint, body) results = get_library_contents(response, MUSIC_SHELF) - pop_songs_random_mix(results['contents']) + pop_songs_random_mix(results) if results is None: return [] songs = parse_uploaded_items(results['contents']) diff --git a/ytmusicapi/parsers/library.py b/ytmusicapi/parsers/library.py index 48249f0..1c6e07d 100644 --- a/ytmusicapi/parsers/library.py +++ b/ytmusicapi/parsers/library.py @@ -77,13 +77,14 @@ def parse_library_artists(response, request_func, limit): def pop_songs_random_mix(results) -> None: """remove the random mix that conditionally appears at the start of library songs""" - if len(results) >= 2: - results.pop(0) + if results: + if len(results['contents']) >= 2: + results['contents'].pop(0) def parse_library_songs(response): results = get_library_contents(response, MUSIC_SHELF) - pop_songs_random_mix(results['contents']) + pop_songs_random_mix(results) return { 'results': results, 'parsed': parse_playlist_items(results['contents']) if results else results From 67d8b7c8accded1ee45a2e67695514bb766cf66b Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 18 Dec 2023 21:06:21 +0100 Subject: [PATCH 3/6] fix broken test playlist id --- tests/test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.py b/tests/test.py index 9aff93d..cb6161b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -306,7 +306,7 @@ def test_get_watch_playlist(self): playlist = self.yt_oauth.get_watch_playlist("UoAf_y9Ok4k") # private track self.assertGreaterEqual(len(playlist["tracks"]), 25) playlist = self.yt.get_watch_playlist( - playlistId="OLAK5uy_lKgoGvlrWhX0EIPavQUXxyPed8Cj38AWc", shuffle=True) + playlistId="OLAK5uy_kt7zOXlNCGsYFEdNc5Pvnr4JFfMkspmc8", shuffle=True) self.assertEqual(len(playlist["tracks"]), 12) playlist = self.yt_brand.get_watch_playlist(playlistId=config["playlists"]["own"], shuffle=True) From 11bf25f0aa4b54e24f7376374fc2fda1c508c944 Mon Sep 17 00:00:00 2001 From: theyak Date: Tue, 26 Dec 2023 15:20:39 -0800 Subject: [PATCH 4/6] Move pop_songs_random_mix to be after results check. --- ytmusicapi/mixins/uploads.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ytmusicapi/mixins/uploads.py b/ytmusicapi/mixins/uploads.py index c4bbcf4..91655bf 100644 --- a/ytmusicapi/mixins/uploads.py +++ b/ytmusicapi/mixins/uploads.py @@ -46,9 +46,9 @@ def get_library_upload_songs(self, limit: int = 25, order: str = None) -> List[D body["params"] = prepare_order_params(order) response = self._send_request(endpoint, body) results = get_library_contents(response, MUSIC_SHELF) - pop_songs_random_mix(results) if results is None: return [] + pop_songs_random_mix(results) songs = parse_uploaded_items(results['contents']) if 'continuations' in results: From b51603af90700fe852ae05773b6a903461a52cec Mon Sep 17 00:00:00 2001 From: sigma67 Date: Wed, 27 Dec 2023 22:15:41 +0100 Subject: [PATCH 5/6] update get_artist docstring (closes #489) --- ytmusicapi/mixins/browsing.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index 61cf9ab..d929971 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -120,10 +120,10 @@ def get_artist(self, channelId: str) -> Dict: """ Get information about an artist and their top releases (songs, albums, singles, videos, and related artists). The top lists - contain pointers for getting the full list of releases. For - songs/videos, pass the browseId to :py:func:`get_playlist`. - For albums/singles, pass browseId and params to :py:func: - `get_artist_albums`. + contain pointers for getting the full list of releases. + + For songs/videos, pass the browseId to :py:func:`get_playlist`. + For albums/singles, pass browseId and params to :py:func:`get_artist_albums`. :param channelId: channel id of the artist :return: Dictionary with requested information. @@ -243,7 +243,7 @@ def get_artist_albums(self, channelId: str, params: str) -> List[Dict]: """ Get the full list of an artist's albums or singles - :param channelId: channel Id of the artist + :param channelId: browseId of the artist as returned by :py:func:`get_artist` :param params: params obtained by :py:func:`get_artist` :return: List of albums in the format of :py:func:`get_library_albums`, except artists key is missing. From e85ce83d3644c62d197c16f55bbc790411fdaac5 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Wed, 27 Dec 2023 22:35:29 +0100 Subject: [PATCH 6/6] update get_artist docstring once more (closes #480) --- ytmusicapi/mixins/browsing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index d929971..f64b330 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -128,6 +128,11 @@ def get_artist(self, channelId: str) -> Dict: :param channelId: channel id of the artist :return: Dictionary with requested information. + .. warning:: + + The returned channelId is not the same as the one passed to the function. + It should be used only with :py:func:`subscribe_artists`. + Example:: {