Revert "get_charts: removed trending category (no longer available on YTM)"

This reverts commit da492e49f6.
This commit is contained in:
sigma67 2024-02-22 14:21:14 +01:00 • committed by sigma67
commit e1bcb88c92
7 changed files with 15 additions and 14 deletions

View file

@ -6,7 +6,7 @@ import pytest
class TestBrowsing:
def test_get_home(self, yt, yt_auth):
result = yt.get_home()
assert len(result) >= 2
assert len(result) == 2
result = yt_auth.get_home(limit=15)
assert len(result) >= 15

View file

@ -9,10 +9,9 @@ class TestExplore:
def test_get_charts(self, yt, yt_oauth):
charts = yt_oauth.get_charts()
assert len(charts) == 4
# songs section appears to be removed currently (US)
assert len(charts) >= 3
charts = yt.get_charts(country="US")
assert len(charts) == 4
charts = yt_oauth.get_charts(country="US")
assert len(charts) == 5
charts = yt.get_charts(country="BE")
assert len(charts) == 3
assert len(charts) == 4

View file

@ -66,7 +66,7 @@ class TestPlaylists:
)
assert response["status"] == "STATUS_SUCCEEDED", "Adding playlist item failed"
assert len(response["playlistEditResults"]) > 0, "Adding playlist item failed"
time.sleep(5)
time.sleep(3)
yt_brand.edit_playlist(playlist_id, addToTop=False)
playlist = yt_brand.get_playlist(playlist_id, related=True)
assert len(playlist["tracks"]) == 46, "Getting playlist items failed"

View file

@ -17,7 +17,7 @@ yt_brand = YTMusic(Path(__file__).parent.joinpath("oauth.json").as_posix(), bran
def populate_account():
"""idempotent requests to populate an account"""
# subscribe to some artists
# library
playlist_id = "RDCLAK5uy_l9ex2d91-Qb1i-W7d0MLCEl_ZjRXss0Dk" # fixed playlist with many artists
yt_playlist = yt_brand.get_playlist(playlist_id)
artists = [track["artists"] for track in yt_playlist["tracks"]]

View file

@ -1,5 +1,5 @@
"""protocol that defines the functions available to mixins"""
from typing import Dict, Optional, Protocol, Union
from typing import Dict, Optional, Protocol
from requests import Response
@ -10,8 +10,6 @@ from ytmusicapi.parsers.i18n import Parser
class MixinProtocol(Protocol):
"""protocol that defines the functions available to mixins"""
auth: Optional[Union[str, Dict]]
auth_type: AuthType
parser: Parser

View file

@ -424,9 +424,7 @@ class BrowsingMixin(MixinProtocol):
params = {"list": audioPlaylistId}
response = self._send_get_request(YTM_DOMAIN + "/playlist", params)
with warnings.catch_warnings():
# merge this with statement with catch_warnings on Python>=3.11
warnings.simplefilter(action="ignore", category=DeprecationWarning)
with warnings.catch_warnings(action="ignore", category=DeprecationWarning):
decoded = response.text.encode("utf8").decode("unicode_escape")
matches = re.search(r"\"MPRE.+?\"", decoded)

View file

@ -220,15 +220,18 @@ class ExploreMixin(MixinProtocol):
charts_categories = ["videos", "artists"]
has_genres = country == "US"
has_trending = country != "ZZ"
# use result length to determine if songs category is present
# could also be done via an is_premium attribute on YTMusic instance
has_songs = (len(results) - 1) > (len(charts_categories) + has_genres)
has_songs = (len(results) - 1) > (len(charts_categories) + has_genres + has_trending)
if has_songs:
charts_categories.insert(0, "songs")
if has_genres:
charts_categories.append("genres")
if has_trending:
charts_categories.append("trending")
parse_chart = lambda i, parse_func, key: parse_content_list(
nav(results[i + has_songs], CAROUSEL_CONTENTS), parse_func, key
@ -247,4 +250,7 @@ class ExploreMixin(MixinProtocol):
if has_genres:
charts["genres"] = parse_chart(3, parse_playlist, MTRIR)
if has_trending:
charts["trending"]["items"] = parse_chart(3 + has_genres, parse_chart_trending, MRLIR)
return charts