Fix library album parsing
This commit is contained in:
parent
667a6edc81
commit
51100b7e24
3 changed files with 22 additions and 16 deletions
|
|
@ -100,7 +100,7 @@ class TestYTMusic(unittest.TestCase):
|
|||
|
||||
def test_rate_playlist(self):
|
||||
response = youtube_auth.rate_playlist('OLAK5uy_l3g4WcHZsEx_QuEDZzWEiyFzZl6pL0xZ4',
|
||||
'DISLIKE')
|
||||
'LIKE')
|
||||
self.assertIn('actions', response)
|
||||
response = youtube_auth.rate_playlist('OLAK5uy_l3g4WcHZsEx_QuEDZzWEiyFzZl6pL0xZ4',
|
||||
'INDIFFERENT')
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ def parse_artists(results, uploaded=False):
|
|||
return artists
|
||||
|
||||
|
||||
def parse_albums(results):
|
||||
def parse_albums(results, upload=True):
|
||||
albums = []
|
||||
for result in results:
|
||||
data = result['musicTwoRowItemRenderer']
|
||||
|
|
@ -75,24 +75,30 @@ def parse_albums(results):
|
|||
album['artists'] = []
|
||||
run_count = len(data['subtitle']['runs'])
|
||||
has_artists = False
|
||||
if run_count == 3:
|
||||
if nav(data, SUBTITLE2).isdigit():
|
||||
album['year'] = nav(data, SUBTITLE2)
|
||||
else:
|
||||
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)
|
||||
has_artists = True
|
||||
|
||||
elif run_count > 3:
|
||||
album['year'] = nav(data, SUBTITLE3)
|
||||
has_artists = True
|
||||
|
||||
if has_artists:
|
||||
for i in range(1, int(run_count / 2)):
|
||||
if has_artists:
|
||||
subtitle = data['subtitle']['runs'][2]
|
||||
album['artists'].append({
|
||||
'name':
|
||||
data['subtitle']['runs'][i * 2]['text'],
|
||||
subtitle['text'],
|
||||
'id':
|
||||
nav(data['subtitle']['runs'][i * 2], NAVIGATION_BROWSE_ID)
|
||||
nav(subtitle, NAVIGATION_BROWSE_ID)
|
||||
})
|
||||
else:
|
||||
album['artists'] = nav(data, SUBTITLE)
|
||||
album['year'] = nav(data, SUBTITLE2)
|
||||
album['trackCount'] = nav(data, SUBTITLE3).split(' ')[0]
|
||||
|
||||
albums.append(album)
|
||||
|
||||
return albums
|
||||
|
|
|
|||
|
|
@ -543,12 +543,12 @@ class YTMusic:
|
|||
return []
|
||||
else:
|
||||
results = results['gridRenderer']
|
||||
albums = parse_albums(results['items'])
|
||||
albums = parse_albums(results['items'], False)
|
||||
|
||||
if 'continuations' in results:
|
||||
request_func = lambda additionalParams: self.__send_request(
|
||||
endpoint, body, additionalParams)
|
||||
parse_func = lambda contents: parse_albums(contents)
|
||||
parse_func = lambda contents: parse_albums(contents, False)
|
||||
albums.extend(
|
||||
get_continuations(results, 'gridContinuation', 25, limit, request_func,
|
||||
parse_func))
|
||||
|
|
|
|||
Loading…
Reference in a new issue