get_charts: fix unavailable song error in trending section

This commit is contained in:
sigma67 2022-01-30 14:50:41 +01:00
commit 2e8c09a430
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
3 changed files with 15 additions and 9 deletions

View file

@ -180,11 +180,7 @@ def parse_single(result):
def parse_video(result):
runs = result['subtitle']['runs']
artists_len = len(runs)
try:
artists_len = runs.index({'text': ' • '})
except ValueError:
pass
artists_len = get_dot_separator_index(runs)
video = {
'title': nav(result, TITLE_TEXT),
'videoId': nav(result, NAVIGATION_VIDEO_ID),

View file

@ -43,12 +43,13 @@ def parse_chart_artist(data):
def parse_chart_trending(data):
flex_0 = get_flex_column_item(data, 0)
artists = parse_song_artists(data, 1)
views = artists.pop() # last item is views for some reason
views = views['name'].split(' ')[0]
index = get_dot_separator_index(artists)
# last item is views for some reason
views = None if index == len(artists) else artists.pop()['name'].split(' ')[0]
return {
'title': nav(flex_0, TEXT_RUN_TEXT),
'videoId': nav(flex_0, TEXT_RUN + NAVIGATION_VIDEO_ID),
'playlistId': nav(flex_0, TEXT_RUN + NAVIGATION_PLAYLIST_ID),
'videoId': nav(flex_0, TEXT_RUN + NAVIGATION_VIDEO_ID, True),
'playlistId': nav(flex_0, TEXT_RUN + NAVIGATION_PLAYLIST_ID, True),
'artists': artists,
'thumbnails': nav(data, THUMBNAILS),
'views': views

View file

@ -172,3 +172,12 @@ def find_objects_by_key(object_list, key, nested=None):
if key in item:
objects.append(item)
return objects
def get_dot_separator_index(runs):
index = len(runs)
try:
index = runs.index({'text': ' • '})
except ValueError:
len(runs)
return index