Skip to content

Commit

Permalink
get_home: small fixes to runs parsing (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Feb 27, 2022
1 parent c1313aa commit 64a1f1d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def test_setup(self):
###############

def test_get_home(self):
result = self.yt.get_home(limit=6)
self.assertGreaterEqual(len(result), 6)
result = self.yt_auth.get_home(limit=15)
self.assertGreaterEqual(len(result), 15)

Expand Down
2 changes: 1 addition & 1 deletion ytmusicapi/mixins/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def get_home(self, limit=3) -> List[Dict]:
}
],
"thumbnails": [...],
"views": "10M views"
"views": "10M"
}
]
}
Expand Down
17 changes: 10 additions & 7 deletions ytmusicapi/parsers/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ def parse_home(self, rows):
items = []
for row in rows:
contents = []
results = nav(row, CAROUSEL)
if CAROUSEL[0] in row:
results = nav(row, CAROUSEL)
elif 'musicImmersiveCarouselShelfRenderer' in row:
results = row['musicImmersiveCarouselShelfRenderer']
else:
continue
for result in results['contents']:
data = nav(result, [MTRIR], True)
content = None
Expand All @@ -34,17 +39,14 @@ def parse_home(self, rows):
content = {
'title': nav(columns[0], TEXT_RUN_TEXT),
'videoId': nav(columns[0], TEXT_RUN + NAVIGATION_VIDEO_ID),
'artists': parse_song_artists_runs(nav(columns[1], TEXT_RUNS)),
'thumbnails': nav(data, THUMBNAILS)
}
content.update(parse_song_runs(nav(columns[1], TEXT_RUNS)))
if len(columns) > 2 and columns[2] is not None:
content['album'] = {
'title': nav(columns[2], TEXT_RUN_TEXT),
'browseId': nav(columns[2], TEXT_RUN + NAVIGATION_BROWSE_ID)
}
else:
content['artists'].pop()
content['views'] = nav(columns[1], TEXT_RUNS + [2, 'text'])

contents.append(content)

Expand Down Expand Up @@ -222,13 +224,14 @@ def parse_single(result):


def parse_song(result):
return {
song = {
'title': nav(result, TITLE_TEXT),
'artists': parse_song_artists_runs(result['subtitle']['runs'][2:]),
'videoId': nav(result, NAVIGATION_VIDEO_ID),
'playlistId': nav(result, NAVIGATION_PLAYLIST_ID, True),
'thumbnails': nav(result, THUMBNAIL_RENDERER)
}
song.update(parse_song_runs(result['subtitle']['runs']))
return song


def parse_video(result):
Expand Down

0 comments on commit 64a1f1d

Please sign in to comment.