fix get_charts, add get_explore (#797)
* get_charts: move to a new class * get_charts: update * get_explore: init
This commit is contained in:
parent
7f42e8d5f0
commit
f6295e50be
6 changed files with 247 additions and 128 deletions
|
|
@ -1,15 +1,33 @@
|
|||
from ytmusicapi.parsers.browsing import *
|
||||
from ytmusicapi.parsers.podcasts import *
|
||||
from ytmusicapi.parsers.songs import *
|
||||
from ytmusicapi.type_alias import JsonDict
|
||||
|
||||
TRENDS = {"ARROW_DROP_UP": "up", "ARROW_DROP_DOWN": "down", "ARROW_CHART_NEUTRAL": "neutral"}
|
||||
|
||||
|
||||
def parse_chart_song(data: JsonDict) -> JsonDict:
|
||||
parsed = parse_song_flat(data)
|
||||
parsed = parse_trending_song(data)
|
||||
parsed.update(parse_ranking(data))
|
||||
return parsed
|
||||
|
||||
|
||||
def parse_chart_playlist(data: JsonDict) -> JsonDict:
|
||||
return {
|
||||
"title": nav(data, TITLE_TEXT),
|
||||
"playlistId": nav(data, TITLE + NAVIGATION_BROWSE_ID)[2:],
|
||||
"thumbnails": nav(data, THUMBNAIL_RENDERER),
|
||||
}
|
||||
|
||||
|
||||
def parse_chart_episode(data: JsonDict) -> JsonDict:
|
||||
episode = parse_episode(data)
|
||||
del episode["index"]
|
||||
episode["podcast"] = parse_id_name(nav(data, ["secondTitle", "runs", 0]))
|
||||
episode["duration"] = nav(data, SUBTITLE2, True)
|
||||
return episode
|
||||
|
||||
|
||||
def parse_chart_artist(data: JsonDict) -> JsonDict:
|
||||
subscribers = get_flex_column_item(data, 1)
|
||||
if subscribers:
|
||||
|
|
@ -25,19 +43,15 @@ def parse_chart_artist(data: JsonDict) -> JsonDict:
|
|||
return parsed
|
||||
|
||||
|
||||
def parse_chart_trending(data: JsonDict) -> JsonDict:
|
||||
def parse_trending_song(data: JsonDict) -> JsonDict:
|
||||
flex_0 = get_flex_column_item(data, 0)
|
||||
artists = parse_song_artists(data, 1)
|
||||
index = get_dot_separator_index(artists)
|
||||
# last item is views for some reason
|
||||
views = None if index == len(artists) else artists.pop()["name"].split(" ")[0]
|
||||
return {
|
||||
"title": nav(flex_0, TEXT_RUN_TEXT),
|
||||
"videoId": nav(flex_0, TEXT_RUN + NAVIGATION_VIDEO_ID, True),
|
||||
**(parse_song_runs(nav(get_flex_column_item(data, 1), TEXT_RUNS))),
|
||||
"playlistId": nav(flex_0, TEXT_RUN + NAVIGATION_PLAYLIST_ID, True),
|
||||
"artists": artists,
|
||||
"thumbnails": nav(data, THUMBNAILS),
|
||||
"views": views,
|
||||
"isExplicit": nav(data, BADGE_LABEL, True) is not None,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue