Fix parsing of album and views in parse_playlist_items (#552)
* Fix parsing of album and views in parse_playlist_items
Parse album and views columns as a function of flex column count and is_album property to cater for varying layouts with three and four flex columns
* Add "own_playlist" attribute to playlists
To allow for an easy distinction between owned / editable and community / non-editable playlists,in applications incorporating ytmusicapi, a boolean "own_playlist" dictionary entry is added to playlists based on existing code already identifying this property.
* Add thumbnails to episodes
Add thumbnails to episodes for visual rendering in Kodi etc.
* Add unit test for playlist "own_playlist" attribut
Add unit test for playlist "own_playlist" attribut
* Improvements as requested
- rename attribute for own playlists to playlist("owned")
- filter out episode thumbnails with an non-functional URL
* Fix linter in test_playlists.py
Fix test for playlist["owned"]
* Auto-Formatting on playlists.py
* format parsers/podcasts.py
* Remove filtering of podcast thumbnails
No idea why I had seen useless images for those thumbnails before - maybe Google fixed something to make them work?
This commit is contained in:
parent
7ffe990c93
commit
d143480ae4
4 changed files with 9 additions and 6 deletions
|
|
@ -11,6 +11,7 @@ class TestPlaylists:
|
|||
assert len(playlist["duration"]) > 5
|
||||
assert len(playlist["tracks"]) > 200
|
||||
assert "suggestions" not in playlist
|
||||
assert playlist["owned"] is False
|
||||
|
||||
yt.get_playlist("RDATgXd-")
|
||||
assert len(playlist["tracks"]) >= 100
|
||||
|
|
@ -24,6 +25,7 @@ class TestPlaylists:
|
|||
assert len(playlist["tracks"]) < 100
|
||||
assert len(playlist["suggestions"]) == 21
|
||||
assert len(playlist["related"]) == 10
|
||||
assert playlist["owned"] is True
|
||||
|
||||
def test_edit_playlist(self, config, yt_brand):
|
||||
playlist = yt_brand.get_playlist(config["playlists"]["own"])
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ class PlaylistsMixin(MixinProtocol):
|
|||
header = response["header"]["musicEditablePlaylistDetailHeaderRenderer"]
|
||||
playlist["privacy"] = header["editHeader"]["musicPlaylistEditHeaderRenderer"]["privacy"]
|
||||
header = header["header"]["musicDetailHeaderRenderer"]
|
||||
playlist["owned"] = own_playlist
|
||||
|
||||
playlist["title"] = nav(header, TITLE_TEXT)
|
||||
playlist["thumbnails"] = nav(header, THUMBNAIL_CROPPED)
|
||||
|
|
|
|||
|
|
@ -44,15 +44,13 @@ def parse_playlist_items(results, menu_entries: Optional[List[List]] = None, is_
|
|||
if title == "Song deleted":
|
||||
continue
|
||||
|
||||
flex_column_count = len(data["flexColumns"])
|
||||
|
||||
artists = parse_song_artists(data, 1)
|
||||
|
||||
album = parse_song_album(data, 2)
|
||||
album = parse_song_album(data, flex_column_count - 1) if not is_album else None
|
||||
|
||||
views = None
|
||||
if album and album["id"] is None:
|
||||
# views currently only present on albums and formatting is localization-dependent -> no parsing
|
||||
if (views := (get_item_text(data, 2))) is not None:
|
||||
album = None
|
||||
views = get_item_text(data, 2) if flex_column_count == 4 or is_album else None
|
||||
|
||||
duration = None
|
||||
if "fixedColumns" in data:
|
||||
|
|
|
|||
|
|
@ -103,6 +103,7 @@ def parse_episodes(results) -> List[Dict]:
|
|||
episodes = []
|
||||
for result in results:
|
||||
data = nav(result, ["musicMultiRowListItemRenderer"])
|
||||
thumbnails = nav(data, THUMBNAILS)
|
||||
if len(nav(data, SUBTITLE_RUNS)) == 1:
|
||||
duration = nav(data, SUBTITLE)
|
||||
else:
|
||||
|
|
@ -124,6 +125,7 @@ def parse_episodes(results) -> List[Dict]:
|
|||
"browseId": browseId,
|
||||
"videoType": videoType,
|
||||
"date": date,
|
||||
"thumbnails": thumbnails,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue