Update get_artist_albums and get_user_playlists to work with new YTMusic update (closes #160)

Overall code quality improved through more consistent usage of nav() shortcuts
This commit is contained in:
sigma67 2021-01-28 15:38:52 +01:00
commit eee9d38f55
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
6 changed files with 41 additions and 88 deletions

View file

@ -2,8 +2,10 @@
TAB_CONTENT = ['tabs', 0, 'tabRenderer', 'content']
SINGLE_COLUMN_TAB = ['contents', 'singleColumnBrowseResultsRenderer'] + TAB_CONTENT
SECTION_LIST = ['sectionListRenderer', 'contents']
SECTION_LIST_ITEM = ['sectionListRenderer', 'contents', 0]
ITEM_SECTION = ['itemSectionRenderer', 'contents', 0]
MUSIC_SHELF = [0, 'musicShelfRenderer']
MUSIC_SHELF = ['musicShelfRenderer']
GRID_ITEMS = ['gridRenderer', 'items']
MENU = ['menu', 'menuRenderer']
MENU_ITEMS = MENU + ['items']
MENU_LIKE_STATUS = MENU + ['topLevelButtons', 0, 'likeButtonRenderer', 'likeStatus']

View file

@ -21,7 +21,7 @@ def parse_artists(results, uploaded=False):
return artists
def parse_albums(results, upload=True):
def parse_albums(results):
albums = []
for result in results:
data = result['musicTwoRowItemRenderer']
@ -33,29 +33,22 @@ def parse_albums(results, upload=True):
album['artists'] = []
run_count = len(data['subtitle']['runs'])
has_artists = False
if upload:
if run_count == 3:
if nav(data, SUBTITLE2).isdigit():
album['year'] = nav(data, SUBTITLE2)
else:
has_artists = True
elif run_count > 3:
album['year'] = nav(data, SUBTITLE3)
if run_count == 3:
if nav(data, SUBTITLE2).isdigit():
album['year'] = nav(data, SUBTITLE2)
else:
has_artists = True
if has_artists:
subtitle = data['subtitle']['runs'][2]
album['artists'].append({
'name': subtitle['text'],
'id': nav(subtitle, NAVIGATION_BROWSE_ID)
})
else:
album['artists'] = {
'name': nav(data, SUBTITLE2),
'id': nav(data, ['subtitle', 'runs', 2] + NAVIGATION_BROWSE_ID, True)
}
album['year'] = nav(data, SUBTITLE3, True)
elif run_count > 3:
album['year'] = nav(data, SUBTITLE3)
has_artists = True
if has_artists:
subtitle = data['subtitle']['runs'][2]
album['artists'].append({
'name': subtitle['text'],
'id': nav(subtitle, NAVIGATION_BROWSE_ID, True)
})
albums.append(album)