get_album: add other versions (closes #279)

also added isExplicit label to all album type results
This commit is contained in:
sigma67 2022-10-01 14:56:59 +02:00
commit dd5d753432
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
4 changed files with 24 additions and 6 deletions

View file

@ -137,6 +137,7 @@ class TestYTMusic(unittest.TestCase):
self.assertGreaterEqual(len(results), 9)
self.assertTrue(results['tracks'][0]['isExplicit'])
self.assertIn('feedbackTokens', results['tracks'][0])
self.assertEqual(len(results['other_versions']), 2)
results = self.yt.get_album("MPREb_BQZvl3BFGay")
self.assertEqual(len(results['tracks']), 7)
@ -319,12 +320,16 @@ class TestYTMusic(unittest.TestCase):
self.assertGreater(len(playlist['tracks']), 200)
self.assertNotIn('suggestions', playlist)
playlist = self.yt.get_playlist("RDCLAK5uy_kpxnNxJpPZjLKbL9WgvrPuErWkUxMP6x4", limit=None, related=True)
playlist = self.yt.get_playlist("RDCLAK5uy_kpxnNxJpPZjLKbL9WgvrPuErWkUxMP6x4",
limit=None,
related=True)
self.assertGreater(len(playlist['tracks']), 100)
self.assertEqual(len(playlist['related']), 10)
def test_get_owned_playlist(self):
playlist = self.yt_brand.get_playlist(config['playlists']['own'], related=True, suggestions_limit=21)
playlist = self.yt_brand.get_playlist(config['playlists']['own'],
related=True,
suggestions_limit=21)
self.assertLess(len(playlist['tracks']), 100)
self.assertEqual(len(playlist['suggestions']), 21)
self.assertEqual(len(playlist['related']), 10)

View file

@ -392,6 +392,15 @@ class BrowsingMixin:
}
}
],
"other_versions": [
{
"title": "Revival",
"year": "Eminem",
"browseId": "MPREb_fefKFOTEZSp",
"thumbnails": [...],
"isExplicit": false
},
],
"duration_seconds": 4657
}
"""
@ -401,6 +410,9 @@ class BrowsingMixin:
album = parse_album_header(response)
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF)
album['tracks'] = parse_playlist_items(results['contents'])
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST + [1] + CAROUSEL, True)
if results is not None:
album['other_versions'] = parse_content_list(results['contents'], parse_album)
album['duration_seconds'] = sum_total_duration(album)
for i, track in enumerate(album['tracks']):
album['tracks'][i]['album'] = album['title']

View file

@ -50,9 +50,9 @@ THUMBNAILS = ['thumbnail', 'musicThumbnailRenderer'] + THUMBNAIL
THUMBNAIL_RENDERER = ['thumbnailRenderer', 'musicThumbnailRenderer'] + THUMBNAIL
THUMBNAIL_CROPPED = ['thumbnail', 'croppedSquareThumbnailRenderer'] + THUMBNAIL
FEEDBACK_TOKEN = ['feedbackEndpoint', 'feedbackToken']
BADGE_LABEL = [
'badges', 0, 'musicInlineBadgeRenderer', 'accessibilityData', 'accessibilityData', 'label'
]
BADGE_PATH = [0, 'musicInlineBadgeRenderer', 'accessibilityData', 'accessibilityData', 'label']
BADGE_LABEL = ['badges'] + BADGE_PATH
SUBTITLE_BADGE_LABEL = ['subtitleBadges'] + BADGE_PATH
CATEGORY_TITLE = ['musicNavigationButtonRenderer', 'buttonText'] + RUN_TEXT
CATEGORY_PARAMS = ['musicNavigationButtonRenderer', 'clickCommand', 'browseEndpoint', 'params']
MRLIR = 'musicResponsiveListItemRenderer'

View file

@ -205,7 +205,8 @@ def parse_album(result):
'title': nav(result, TITLE_TEXT),
'year': nav(result, SUBTITLE2, True),
'browseId': nav(result, TITLE + NAVIGATION_BROWSE_ID),
'thumbnails': nav(result, THUMBNAIL_RENDERER)
'thumbnails': nav(result, THUMBNAIL_RENDERER),
'isExplicit': nav(result, SUBTITLE_BADGE_LABEL, True) is not None
}