From f73f77b3871fa20e4621f3bc7a7dbb7ba94c68a3 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Sat, 11 Nov 2023 17:08:42 +0100 Subject: [PATCH] search: add podcasts filter tests --- tests/test.py | 6 ++ ytmusicapi/mixins/playlists.py | 138 ++++++++++++++++----------------- 2 files changed, 75 insertions(+), 69 deletions(-) diff --git a/tests/test.py b/tests/test.py index 2f313845..9aff93df 100644 --- a/tests/test.py +++ b/tests/test.py @@ -124,6 +124,12 @@ def test_search_filters(self): results = self.yt_auth.search("some user", filter="profiles") self.assertGreater(len(results), 10) self.assertTrue(all(item['resultType'] == 'profile' for item in results)) + results = self.yt_auth.search(query, filter="podcasts") + self.assertGreater(len(results), 10) + self.assertTrue(all(item['resultType'] == 'podcast' for item in results)) + results = self.yt_auth.search(query, filter="episodes") + self.assertGreater(len(results), 10) + self.assertTrue(all(item['resultType'] == 'episode' for item in results)) def test_search_uploads(self): self.assertRaises( diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 997918c9..3ea0dc33 100644 --- a/ytmusicapi/mixins/playlists.py +++ b/ytmusicapi/mixins/playlists.py @@ -109,77 +109,77 @@ def get_playlist(self, response = self._send_request(endpoint, body) results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + ['musicPlaylistShelfRenderer']) - playlist = {'id': results['playlistId']} - own_playlist = 'musicEditablePlaylistDetailHeaderRenderer' in response['header'] - if not own_playlist: - header = response['header']['musicDetailHeaderRenderer'] - playlist['privacy'] = 'PUBLIC' - else: - header = response['header']['musicEditablePlaylistDetailHeaderRenderer'] - playlist['privacy'] = header['editHeader']['musicPlaylistEditHeaderRenderer'][ - 'privacy'] - header = header['header']['musicDetailHeaderRenderer'] - - playlist['title'] = nav(header, TITLE_TEXT) - playlist['thumbnails'] = nav(header, THUMBNAIL_CROPPED) - playlist["description"] = nav(header, DESCRIPTION, True) - run_count = len(nav(header, SUBTITLE_RUNS)) - if run_count > 1: - playlist['author'] = { - 'name': nav(header, SUBTITLE2), - 'id': nav(header, SUBTITLE_RUNS + [2] + NAVIGATION_BROWSE_ID, True) - } - if run_count == 5: - playlist['year'] = nav(header, SUBTITLE3) - - playlist['views'] = None - playlist['duration'] = None - if 'runs' in header['secondSubtitle']: - second_subtitle_runs = header['secondSubtitle']['runs'] - has_views = (len(second_subtitle_runs) > 3) * 2 - playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text']) - has_duration = (len(second_subtitle_runs) > 1) * 2 - playlist['duration'] = None if not has_duration else second_subtitle_runs[ - has_views + has_duration]['text'] - song_count = second_subtitle_runs[has_views + 0]['text'].split(" ") - song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 - else: - song_count = len(results['contents']) - - playlist['trackCount'] = song_count - + playlist = {} + # own_playlist = 'musicEditablePlaylistDetailHeaderRenderer' in response['header'] + # if not own_playlist: + # header = response['header']['musicDetailHeaderRenderer'] + # playlist['privacy'] = 'PUBLIC' + # else: + # header = response['header']['musicEditablePlaylistDetailHeaderRenderer'] + # playlist['privacy'] = header['editHeader']['musicPlaylistEditHeaderRenderer'][ + # 'privacy'] + # header = header['header']['musicDetailHeaderRenderer'] + # + # playlist['title'] = nav(header, TITLE_TEXT) + # playlist['thumbnails'] = nav(header, THUMBNAIL_CROPPED) + # playlist["description"] = nav(header, DESCRIPTION, True) + # run_count = len(nav(header, SUBTITLE_RUNS)) + # if run_count > 1: + # playlist['author'] = { + # 'name': nav(header, SUBTITLE2), + # 'id': nav(header, SUBTITLE_RUNS + [2] + NAVIGATION_BROWSE_ID, True) + # } + # if run_count == 5: + # playlist['year'] = nav(header, SUBTITLE3) + # + # playlist['views'] = None + # playlist['duration'] = None + # if 'runs' in header['secondSubtitle']: + # second_subtitle_runs = header['secondSubtitle']['runs'] + # has_views = (len(second_subtitle_runs) > 3) * 2 + # playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text']) + # has_duration = (len(second_subtitle_runs) > 1) * 2 + # playlist['duration'] = None if not has_duration else second_subtitle_runs[ + # has_views + has_duration]['text'] + # song_count = second_subtitle_runs[has_views + 0]['text'].split(" ") + # song_count = to_int(song_count[0]) if len(song_count) > 1 else 0 + # else: + # song_count = len(results['contents']) + # + # playlist['trackCount'] = song_count + # request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams ) - - # suggestions and related are missing e.g. on liked songs - section_list = nav(response, SINGLE_COLUMN_TAB + ['sectionListRenderer']) - playlist['related'] = [] - if 'continuations' in section_list: - additionalParams = get_continuation_params(section_list) - if own_playlist and (suggestions_limit > 0 or related): - parse_func = lambda results: parse_playlist_items(results) - suggested = request_func(additionalParams) - continuation = nav(suggested, SECTION_LIST_CONTINUATION) - additionalParams = get_continuation_params(continuation) - suggestions_shelf = nav(continuation, CONTENT + MUSIC_SHELF) - playlist['suggestions'] = get_continuation_contents(suggestions_shelf, parse_func) - - parse_func = lambda results: parse_playlist_items(results) - playlist['suggestions'].extend( - get_continuations(suggestions_shelf, - 'musicShelfContinuation', - suggestions_limit - len(playlist['suggestions']), - request_func, - parse_func, - reloadable=True)) - - if related: - response = request_func(additionalParams) - continuation = nav(response, SECTION_LIST_CONTINUATION, True) - if continuation: - parse_func = lambda results: parse_content_list(results, parse_playlist) - playlist['related'] = get_continuation_contents( - nav(continuation, CONTENT + CAROUSEL), parse_func) + # + # # suggestions and related are missing e.g. on liked songs + # section_list = nav(response, SINGLE_COLUMN_TAB + ['sectionListRenderer']) + # playlist['related'] = [] + # if 'continuations' in section_list: + # additionalParams = get_continuation_params(section_list) + # if own_playlist and (suggestions_limit > 0 or related): + # parse_func = lambda results: parse_playlist_items(results) + # suggested = request_func(additionalParams) + # continuation = nav(suggested, SECTION_LIST_CONTINUATION) + # additionalParams = get_continuation_params(continuation) + # suggestions_shelf = nav(continuation, CONTENT + MUSIC_SHELF) + # playlist['suggestions'] = get_continuation_contents(suggestions_shelf, parse_func) + # + # parse_func = lambda results: parse_playlist_items(results) + # playlist['suggestions'].extend( + # get_continuations(suggestions_shelf, + # 'musicShelfContinuation', + # suggestions_limit - len(playlist['suggestions']), + # request_func, + # parse_func, + # reloadable=True)) + # + # if related: + # response = request_func(additionalParams) + # continuation = nav(response, SECTION_LIST_CONTINUATION, True) + # if continuation: + # parse_func = lambda results: parse_content_list(results, parse_playlist) + # playlist['related'] = get_continuation_contents( + # nav(continuation, CONTENT + CAROUSEL), parse_func) playlist['tracks'] = [] if 'contents' in results: