get_charts: removed trending category (no longer available on YTM)
This commit is contained in:
parent
cc26a63264
commit
da492e49f6
7 changed files with 14 additions and 15 deletions
|
|
@ -6,7 +6,7 @@ import pytest
|
||||||
class TestBrowsing:
|
class TestBrowsing:
|
||||||
def test_get_home(self, yt, yt_auth):
|
def test_get_home(self, yt, yt_auth):
|
||||||
result = yt.get_home()
|
result = yt.get_home()
|
||||||
assert len(result) == 2
|
assert len(result) >= 2
|
||||||
result = yt_auth.get_home(limit=15)
|
result = yt_auth.get_home(limit=15)
|
||||||
assert len(result) >= 15
|
assert len(result) >= 15
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,10 @@ class TestExplore:
|
||||||
|
|
||||||
def test_get_charts(self, yt, yt_oauth):
|
def test_get_charts(self, yt, yt_oauth):
|
||||||
charts = yt_oauth.get_charts()
|
charts = yt_oauth.get_charts()
|
||||||
# songs section appears to be removed currently (US)
|
assert len(charts) == 4
|
||||||
assert len(charts) >= 3
|
|
||||||
charts = yt.get_charts(country="US")
|
charts = yt.get_charts(country="US")
|
||||||
|
assert len(charts) == 4
|
||||||
|
charts = yt_oauth.get_charts(country="US")
|
||||||
assert len(charts) == 5
|
assert len(charts) == 5
|
||||||
charts = yt.get_charts(country="BE")
|
charts = yt.get_charts(country="BE")
|
||||||
assert len(charts) == 4
|
assert len(charts) == 3
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ class TestPlaylists:
|
||||||
)
|
)
|
||||||
assert response["status"] == "STATUS_SUCCEEDED", "Adding playlist item failed"
|
assert response["status"] == "STATUS_SUCCEEDED", "Adding playlist item failed"
|
||||||
assert len(response["playlistEditResults"]) > 0, "Adding playlist item failed"
|
assert len(response["playlistEditResults"]) > 0, "Adding playlist item failed"
|
||||||
time.sleep(3)
|
time.sleep(5)
|
||||||
yt_brand.edit_playlist(playlist_id, addToTop=False)
|
yt_brand.edit_playlist(playlist_id, addToTop=False)
|
||||||
playlist = yt_brand.get_playlist(playlist_id, related=True)
|
playlist = yt_brand.get_playlist(playlist_id, related=True)
|
||||||
assert len(playlist["tracks"]) == 46, "Getting playlist items failed"
|
assert len(playlist["tracks"]) == 46, "Getting playlist items failed"
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ yt_brand = YTMusic(Path(__file__).parent.joinpath("oauth.json").as_posix(), bran
|
||||||
|
|
||||||
def populate_account():
|
def populate_account():
|
||||||
"""idempotent requests to populate an account"""
|
"""idempotent requests to populate an account"""
|
||||||
# library
|
# subscribe to some artists
|
||||||
playlist_id = "RDCLAK5uy_l9ex2d91-Qb1i-W7d0MLCEl_ZjRXss0Dk" # fixed playlist with many artists
|
playlist_id = "RDCLAK5uy_l9ex2d91-Qb1i-W7d0MLCEl_ZjRXss0Dk" # fixed playlist with many artists
|
||||||
yt_playlist = yt_brand.get_playlist(playlist_id)
|
yt_playlist = yt_brand.get_playlist(playlist_id)
|
||||||
artists = [track["artists"] for track in yt_playlist["tracks"]]
|
artists = [track["artists"] for track in yt_playlist["tracks"]]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
"""protocol that defines the functions available to mixins"""
|
"""protocol that defines the functions available to mixins"""
|
||||||
from typing import Dict, Optional, Protocol
|
from typing import Dict, Optional, Protocol, Union
|
||||||
|
|
||||||
from requests import Response
|
from requests import Response
|
||||||
|
|
||||||
|
|
@ -10,6 +10,8 @@ from ytmusicapi.parsers.i18n import Parser
|
||||||
class MixinProtocol(Protocol):
|
class MixinProtocol(Protocol):
|
||||||
"""protocol that defines the functions available to mixins"""
|
"""protocol that defines the functions available to mixins"""
|
||||||
|
|
||||||
|
auth: Optional[Union[str, Dict]]
|
||||||
|
|
||||||
auth_type: AuthType
|
auth_type: AuthType
|
||||||
|
|
||||||
parser: Parser
|
parser: Parser
|
||||||
|
|
|
||||||
|
|
@ -424,7 +424,9 @@ class BrowsingMixin(MixinProtocol):
|
||||||
params = {"list": audioPlaylistId}
|
params = {"list": audioPlaylistId}
|
||||||
response = self._send_get_request(YTM_DOMAIN + "/playlist", params)
|
response = self._send_get_request(YTM_DOMAIN + "/playlist", params)
|
||||||
|
|
||||||
with warnings.catch_warnings(action="ignore", category=DeprecationWarning):
|
with warnings.catch_warnings():
|
||||||
|
# merge this with statement with catch_warnings on Python>=3.11
|
||||||
|
warnings.simplefilter(action="ignore", category=DeprecationWarning)
|
||||||
decoded = response.text.encode("utf8").decode("unicode_escape")
|
decoded = response.text.encode("utf8").decode("unicode_escape")
|
||||||
|
|
||||||
matches = re.search(r"\"MPRE.+?\"", decoded)
|
matches = re.search(r"\"MPRE.+?\"", decoded)
|
||||||
|
|
|
||||||
|
|
@ -220,18 +220,15 @@ class ExploreMixin(MixinProtocol):
|
||||||
charts_categories = ["videos", "artists"]
|
charts_categories = ["videos", "artists"]
|
||||||
|
|
||||||
has_genres = country == "US"
|
has_genres = country == "US"
|
||||||
has_trending = country != "ZZ"
|
|
||||||
|
|
||||||
# use result length to determine if songs category is present
|
# use result length to determine if songs category is present
|
||||||
# could also be done via an is_premium attribute on YTMusic instance
|
# could also be done via an is_premium attribute on YTMusic instance
|
||||||
has_songs = (len(results) - 1) > (len(charts_categories) + has_genres + has_trending)
|
has_songs = (len(results) - 1) > (len(charts_categories) + has_genres)
|
||||||
|
|
||||||
if has_songs:
|
if has_songs:
|
||||||
charts_categories.insert(0, "songs")
|
charts_categories.insert(0, "songs")
|
||||||
if has_genres:
|
if has_genres:
|
||||||
charts_categories.append("genres")
|
charts_categories.append("genres")
|
||||||
if has_trending:
|
|
||||||
charts_categories.append("trending")
|
|
||||||
|
|
||||||
parse_chart = lambda i, parse_func, key: parse_content_list(
|
parse_chart = lambda i, parse_func, key: parse_content_list(
|
||||||
nav(results[i + has_songs], CAROUSEL_CONTENTS), parse_func, key
|
nav(results[i + has_songs], CAROUSEL_CONTENTS), parse_func, key
|
||||||
|
|
@ -250,7 +247,4 @@ class ExploreMixin(MixinProtocol):
|
||||||
if has_genres:
|
if has_genres:
|
||||||
charts["genres"] = parse_chart(3, parse_playlist, MTRIR)
|
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
|
return charts
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue