improve test coverage
This commit is contained in:
parent
d0ec2bbf72
commit
4594a748e3
3 changed files with 101 additions and 95 deletions
|
|
@ -12,89 +12,87 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
|||
continue
|
||||
data = result[MRLIR]
|
||||
|
||||
try:
|
||||
videoId = setVideoId = None
|
||||
like = None
|
||||
feedback_tokens = None
|
||||
videoId = setVideoId = None
|
||||
like = None
|
||||
feedback_tokens = None
|
||||
|
||||
# if the item has a menu, find its setVideoId
|
||||
if 'menu' in data:
|
||||
for item in nav(data, MENU_ITEMS):
|
||||
if 'menuServiceItemRenderer' in item:
|
||||
menu_service = nav(item, MENU_SERVICE)
|
||||
if 'playlistEditEndpoint' in menu_service:
|
||||
setVideoId = menu_service['playlistEditEndpoint']['actions'][0][
|
||||
'setVideoId']
|
||||
videoId = menu_service['playlistEditEndpoint']['actions'][0][
|
||||
'removedVideoId']
|
||||
# if the item has a menu, find its setVideoId
|
||||
if 'menu' in data:
|
||||
for item in nav(data, MENU_ITEMS):
|
||||
if 'menuServiceItemRenderer' in item:
|
||||
menu_service = nav(item, MENU_SERVICE)
|
||||
if 'playlistEditEndpoint' in menu_service:
|
||||
setVideoId = menu_service['playlistEditEndpoint']['actions'][0][
|
||||
'setVideoId']
|
||||
videoId = menu_service['playlistEditEndpoint']['actions'][0][
|
||||
'removedVideoId']
|
||||
|
||||
if TOGGLE_MENU in item:
|
||||
feedback_tokens = parse_song_menu_tokens(item)
|
||||
if TOGGLE_MENU in item:
|
||||
feedback_tokens = parse_song_menu_tokens(item)
|
||||
|
||||
# if item is not playable, the videoId was retrieved above
|
||||
if nav(data, PLAY_BUTTON, none_if_absent=True) != None:
|
||||
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
|
||||
videoId = nav(data,
|
||||
PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
|
||||
# if item is not playable, the videoId was retrieved above
|
||||
if nav(data, PLAY_BUTTON, none_if_absent=True) is not None:
|
||||
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
|
||||
videoId = nav(data,
|
||||
PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
|
||||
|
||||
if 'menu' in data:
|
||||
like = nav(data, MENU_LIKE_STATUS, True)
|
||||
if 'menu' in data:
|
||||
like = nav(data, MENU_LIKE_STATUS, True)
|
||||
|
||||
title = get_item_text(data, 0)
|
||||
if title == 'Song deleted':
|
||||
continue
|
||||
title = get_item_text(data, 0)
|
||||
if title == 'Song deleted':
|
||||
continue
|
||||
|
||||
artists = parse_song_artists(data, 1)
|
||||
artists = parse_song_artists(data, 1)
|
||||
|
||||
album = parse_song_album(data, 2)
|
||||
album = parse_song_album(data, 2)
|
||||
|
||||
duration = None
|
||||
if 'fixedColumns' in data:
|
||||
if 'simpleText' in get_fixed_column_item(data, 0)['text']:
|
||||
duration = get_fixed_column_item(data, 0)['text']['simpleText']
|
||||
else:
|
||||
duration = get_fixed_column_item(data, 0)['text']['runs'][0]['text']
|
||||
duration = None
|
||||
if 'fixedColumns' in data:
|
||||
if 'simpleText' in get_fixed_column_item(data, 0)['text']:
|
||||
duration = get_fixed_column_item(data, 0)['text']['simpleText']
|
||||
else:
|
||||
duration = get_fixed_column_item(data, 0)['text']['runs'][0]['text']
|
||||
|
||||
thumbnails = None
|
||||
if 'thumbnail' in data:
|
||||
thumbnails = nav(data, THUMBNAILS)
|
||||
thumbnails = None
|
||||
if 'thumbnail' in data:
|
||||
thumbnails = nav(data, THUMBNAILS)
|
||||
|
||||
isAvailable = True
|
||||
if 'musicItemRendererDisplayPolicy' in data:
|
||||
isAvailable = data[
|
||||
'musicItemRendererDisplayPolicy'] != 'MUSIC_ITEM_RENDERER_DISPLAY_POLICY_GREY_OUT'
|
||||
isAvailable = True
|
||||
if 'musicItemRendererDisplayPolicy' in data:
|
||||
isAvailable = data[
|
||||
'musicItemRendererDisplayPolicy'] != 'MUSIC_ITEM_RENDERER_DISPLAY_POLICY_GREY_OUT'
|
||||
|
||||
isExplicit = nav(data, BADGE_LABEL, True) is not None
|
||||
isExplicit = nav(data, BADGE_LABEL, True) is not None
|
||||
|
||||
videoType = nav(data, MENU_ITEMS + [0, 'menuNavigationItemRenderer', 'navigationEndpoint'] + NAVIGATION_VIDEO_TYPE, True)
|
||||
videoType = nav(
|
||||
data, MENU_ITEMS + [0, 'menuNavigationItemRenderer', 'navigationEndpoint']
|
||||
+ NAVIGATION_VIDEO_TYPE, True)
|
||||
|
||||
song = {
|
||||
'videoId': videoId,
|
||||
'title': title,
|
||||
'artists': artists,
|
||||
'album': album,
|
||||
'likeStatus': like,
|
||||
'thumbnails': thumbnails,
|
||||
'isAvailable': isAvailable,
|
||||
'isExplicit': isExplicit,
|
||||
'videoType': videoType
|
||||
}
|
||||
if duration:
|
||||
song['duration'] = duration
|
||||
song['duration_seconds'] = parse_duration(duration)
|
||||
if setVideoId:
|
||||
song['setVideoId'] = setVideoId
|
||||
if feedback_tokens:
|
||||
song['feedbackTokens'] = feedback_tokens
|
||||
song = {
|
||||
'videoId': videoId,
|
||||
'title': title,
|
||||
'artists': artists,
|
||||
'album': album,
|
||||
'likeStatus': like,
|
||||
'thumbnails': thumbnails,
|
||||
'isAvailable': isAvailable,
|
||||
'isExplicit': isExplicit,
|
||||
'videoType': videoType
|
||||
}
|
||||
if duration:
|
||||
song['duration'] = duration
|
||||
song['duration_seconds'] = parse_duration(duration)
|
||||
if setVideoId:
|
||||
song['setVideoId'] = setVideoId
|
||||
if feedback_tokens:
|
||||
song['feedbackTokens'] = feedback_tokens
|
||||
|
||||
if menu_entries:
|
||||
for menu_entry in menu_entries:
|
||||
song[menu_entry[-1]] = nav(data, MENU_ITEMS + menu_entry)
|
||||
if menu_entries:
|
||||
for menu_entry in menu_entries:
|
||||
song[menu_entry[-1]] = nav(data, MENU_ITEMS + menu_entry)
|
||||
|
||||
songs.append(song)
|
||||
|
||||
except Exception as e:
|
||||
print("Item " + str(count) + ": " + str(e))
|
||||
songs.append(song)
|
||||
|
||||
return songs
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue