From 14ae7852eaee2fa2a595ae405306df6cafc08841 Mon Sep 17 00:00:00 2001 From: sigma67 <16363825+sigma67@users.noreply.github.com> Date: Sat, 13 Jul 2024 21:18:19 +0200 Subject: [PATCH] coverage: remove code for old playlist format (#619) * coverage: remove temporary code for new playlist format * fix flaky search test * improve rate_song coverage * test invalid order raise * fix workflow --- .github/workflows/coverage.yml | 4 ++- tests/mixins/test_library.py | 10 +++++- tests/mixins/test_search.py | 2 +- ytmusicapi/mixins/playlists.py | 66 ---------------------------------- 4 files changed, 13 insertions(+), 69 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index fb1f9d2..c02491c 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -17,10 +17,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@master + with: + ref: ${{ github.event.workflow_run.head_sha }} - name: Setup Python uses: actions/setup-python@v5 with: - python-version: 3.x + python-version: 3.9 - name: Setup PDM uses: pdm-project/setup-pdm@v4 - name: create-json diff --git a/tests/mixins/test_library.py b/tests/mixins/test_library.py index c47d2b4..3c12e06 100644 --- a/tests/mixins/test_library.py +++ b/tests/mixins/test_library.py @@ -26,6 +26,10 @@ class TestLibrary: songs = yt_empty.get_library_songs() assert len(songs) == 0 + def test_get_library_albums_invalid_order(self, yt): + with pytest.raises(Exception): + yt.get_library_albums(100, order="invalid") + def test_get_library_albums(self, yt_oauth, yt_brand, yt_empty): albums = yt_oauth.get_library_albums(100) assert len(albums) > 50 @@ -102,8 +106,12 @@ class TestLibrary: def test_rate_song(self, yt_auth, sample_video): response = yt_auth.rate_song(sample_video, "LIKE") assert "actions" in response - response = yt_auth.rate_song(sample_video, "INDIFFERENT") + response = yt_auth.rate_song(sample_video, "DISLIKE") assert "actions" in response + response = yt_auth.rate_song(sample_video, "INDIFFERENT") + assert response + response = yt_auth.rate_song(sample_video, "notexist") + assert not response def test_edit_song_library_status(self, yt_brand, sample_album): album = yt_brand.get_album(sample_album) diff --git a/tests/mixins/test_search.py b/tests/mixins/test_search.py index 2d348d6..0a51ae2 100644 --- a/tests/mixins/test_search.py +++ b/tests/mixins/test_search.py @@ -77,7 +77,7 @@ class TestSearch: assert len(results) > 10 assert all(item["resultType"] == "podcast" for item in results) results = yt_auth.search(query, filter="episodes") - assert len(results) > 5 + assert len(results) >= 5 assert all(item["resultType"] == "episode" for item in results) def test_search_top_result(self, yt): diff --git a/ytmusicapi/mixins/playlists.py b/ytmusicapi/mixins/playlists.py index 4ba4225..c8d6387 100644 --- a/ytmusicapi/mixins/playlists.py +++ b/ytmusicapi/mixins/playlists.py @@ -106,72 +106,6 @@ class PlaylistsMixin(MixinProtocol): body = {"browseId": browseId} endpoint = "browse" response = self._send_request(endpoint, body) - results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + ["musicPlaylistShelfRenderer"], True) - if not results: - return self._parse_new_playlist_format( - response, endpoint, body, suggestions_limit, related, limit - ) - - playlist = {"id": results["playlistId"]} - playlist.update(parse_playlist_header(response)) - if playlist["trackCount"] is None: - playlist["trackCount"] = len(results["contents"]) - - 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 playlist["owned"] 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: - playlist["tracks"] = parse_playlist_items(results["contents"]) - - parse_func = lambda contents: parse_playlist_items(contents) - if "continuations" in results: - playlist["tracks"].extend( - get_continuations( - results, "musicPlaylistShelfContinuation", limit, request_func, parse_func - ) - ) - - playlist["duration_seconds"] = sum_total_duration(playlist) - return playlist - - def _parse_new_playlist_format( - self, response: dict, endpoint, body, suggestions_limit, related, limit - ) -> dict: # pragma: no cover - """temporary function to avoid too many ifs in get_playlist during a/b test""" header_data = nav(response, [*TWO_COLUMN_RENDERER, *TAB_CONTENT, *SECTION_LIST_ITEM]) section_list = nav(response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION])