Add shuffleId, radioId to artist results [search, get_artist, get_library_artists, get_library_subscriptions, get_library_upload_artists] (closes #153)
This commit is contained in:
parent
623f846e29
commit
1c664b6799
6 changed files with 28 additions and 25 deletions
|
|
@ -50,12 +50,12 @@ class TestYTMusic(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_artist(self):
|
def test_get_artist(self):
|
||||||
results = youtube.get_artist("MPLAUCmMUZbaYdNH0bEd1PAlAqsA")
|
results = youtube.get_artist("MPLAUCmMUZbaYdNH0bEd1PAlAqsA")
|
||||||
self.assertEqual(len(results), 11)
|
self.assertEqual(len(results), 13)
|
||||||
results = youtube.get_artist("UCLZ7tlKC06ResyDmEStSrOw") # no album year
|
results = youtube.get_artist("UCLZ7tlKC06ResyDmEStSrOw") # no album year
|
||||||
self.assertGreaterEqual(len(results), 9)
|
self.assertGreaterEqual(len(results), 11)
|
||||||
results = youtube.get_artist(
|
results = youtube.get_artist(
|
||||||
"UCDAPd3S5CBIEKXn-tvy57Lg") # no thumbnail, albums, subscribe count
|
"UCDAPd3S5CBIEKXn-tvy57Lg") # no thumbnail, albums, subscribe count
|
||||||
self.assertGreaterEqual(len(results), 9)
|
self.assertGreaterEqual(len(results), 11)
|
||||||
|
|
||||||
def test_get_artist_albums(self):
|
def test_get_artist_albums(self):
|
||||||
artist = youtube.get_artist("UCAeLFBCQS7FvI8PvBrWvSBg")
|
artist = youtube.get_artist("UCAeLFBCQS7FvI8PvBrWvSBg")
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,10 @@ class BrowsingMixin:
|
||||||
'subheader']['runs'][0]['text']
|
'subheader']['runs'][0]['text']
|
||||||
subscription_button = header['subscriptionButton']['subscribeButtonRenderer']
|
subscription_button = header['subscriptionButton']['subscribeButtonRenderer']
|
||||||
artist['channelId'] = subscription_button['channelId']
|
artist['channelId'] = subscription_button['channelId']
|
||||||
|
artist['shuffleId'] = nav(header,
|
||||||
|
['playButton', 'buttonRenderer'] + NAVIGATION_WATCH_PLAYLIST_ID)
|
||||||
|
artist['radioId'] = nav(header,
|
||||||
|
['startRadioButton', 'buttonRenderer'] + NAVIGATION_WATCH_PLAYLIST_ID)
|
||||||
artist['subscribers'] = nav(subscription_button,
|
artist['subscribers'] = nav(subscription_button,
|
||||||
['subscriberCountText', 'runs', 0, 'text'], True)
|
['subscriberCountText', 'runs', 0, 'text'], True)
|
||||||
artist['subscribed'] = subscription_button['subscribed']
|
artist['subscribed'] = subscription_button['subscribed']
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ PLAY_BUTTON = [
|
||||||
NAVIGATION_BROWSE_ID = ['navigationEndpoint', 'browseEndpoint', 'browseId']
|
NAVIGATION_BROWSE_ID = ['navigationEndpoint', 'browseEndpoint', 'browseId']
|
||||||
NAVIGATION_VIDEO_ID = ['navigationEndpoint', 'watchEndpoint', 'videoId']
|
NAVIGATION_VIDEO_ID = ['navigationEndpoint', 'watchEndpoint', 'videoId']
|
||||||
NAVIGATION_PLAYLIST_ID = ['navigationEndpoint', 'watchEndpoint', 'playlistId']
|
NAVIGATION_PLAYLIST_ID = ['navigationEndpoint', 'watchEndpoint', 'playlistId']
|
||||||
|
NAVIGATION_WATCH_PLAYLIST_ID = ['navigationEndpoint', 'watchPlaylistEndpoint', 'playlistId']
|
||||||
CAROUSEL_TITLE = ['header', 'musicCarouselShelfBasicHeaderRenderer', 'title', 'runs', 0]
|
CAROUSEL_TITLE = ['header', 'musicCarouselShelfBasicHeaderRenderer', 'title', 'runs', 0]
|
||||||
FRAMEWORK_MUTATIONS = ['frameworkUpdates', 'entityBatchUpdate', 'mutations']
|
FRAMEWORK_MUTATIONS = ['frameworkUpdates', 'entityBatchUpdate', 'mutations']
|
||||||
TITLE = ['title', 'runs', 0]
|
TITLE = ['title', 'runs', 0]
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class Parser:
|
||||||
|
|
||||||
if resultType in ['artist']:
|
if resultType in ['artist']:
|
||||||
search_result['artist'] = get_item_text(data, 0)
|
search_result['artist'] = get_item_text(data, 0)
|
||||||
|
parse_menu_playlists(data, search_result)
|
||||||
|
|
||||||
elif resultType in ['album']:
|
elif resultType in ['album']:
|
||||||
search_result['title'] = get_item_text(data, 0)
|
search_result['title'] = get_item_text(data, 0)
|
||||||
|
|
@ -114,28 +115,6 @@ class Parser:
|
||||||
search_result['releaseDate'] = runs[2]
|
search_result['releaseDate'] = runs[2]
|
||||||
search_result['resultType'] = 'album'
|
search_result['resultType'] = 'album'
|
||||||
|
|
||||||
watch_menu = find_objects_by_key(nav(data, MENU_ITEMS), 'menuNavigationItemRenderer')
|
|
||||||
for item in [_x['menuNavigationItemRenderer'] for _x in watch_menu]:
|
|
||||||
icon = nav(item, ['icon', 'iconType'])
|
|
||||||
if icon == 'MUSIC_SHUFFLE':
|
|
||||||
watch_key = 'shuffleId'
|
|
||||||
elif icon == 'MIX':
|
|
||||||
watch_key = 'radioId'
|
|
||||||
else:
|
|
||||||
# ADD_TO_PLAYLIST
|
|
||||||
# ALBUM
|
|
||||||
# ARTIST
|
|
||||||
# SHARE
|
|
||||||
continue
|
|
||||||
|
|
||||||
watch_id = nav(item, ['navigationEndpoint', 'watchPlaylistEndpoint', 'playlistId'],
|
|
||||||
True)
|
|
||||||
if not watch_id:
|
|
||||||
watch_id = nav(item, ['navigationEndpoint', 'watchEndpoint', 'playlistId'],
|
|
||||||
True)
|
|
||||||
if watch_id:
|
|
||||||
search_result[watch_key] = watch_id
|
|
||||||
|
|
||||||
search_result['thumbnails'] = nav(data, THUMBNAILS)
|
search_result['thumbnails'] = nav(data, THUMBNAILS)
|
||||||
search_results.append(search_result)
|
search_results.append(search_result)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ def parse_artists(results, uploaded=False):
|
||||||
artist = {}
|
artist = {}
|
||||||
artist['browseId'] = nav(data, NAVIGATION_BROWSE_ID)
|
artist['browseId'] = nav(data, NAVIGATION_BROWSE_ID)
|
||||||
artist['artist'] = get_item_text(data, 0)
|
artist['artist'] = get_item_text(data, 0)
|
||||||
|
parse_menu_playlists(data, artist)
|
||||||
if uploaded:
|
if uploaded:
|
||||||
artist['songs'] = get_item_text(data, 1).split(' ')[0]
|
artist['songs'] = get_item_text(data, 1).split(' ')[0]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,24 @@ def parse_song_menu_tokens(item):
|
||||||
return {'add': library_add_token, 'remove': library_remove_token}
|
return {'add': library_add_token, 'remove': library_remove_token}
|
||||||
|
|
||||||
|
|
||||||
|
def parse_menu_playlists(data, result):
|
||||||
|
watch_menu = find_objects_by_key(nav(data, MENU_ITEMS), 'menuNavigationItemRenderer')
|
||||||
|
for item in [_x['menuNavigationItemRenderer'] for _x in watch_menu]:
|
||||||
|
icon = nav(item, ['icon', 'iconType'])
|
||||||
|
if icon == 'MUSIC_SHUFFLE':
|
||||||
|
watch_key = 'shuffleId'
|
||||||
|
elif icon == 'MIX':
|
||||||
|
watch_key = 'radioId'
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
watch_id = nav(item, ['navigationEndpoint', 'watchPlaylistEndpoint', 'playlistId'], True)
|
||||||
|
if not watch_id:
|
||||||
|
watch_id = nav(item, ['navigationEndpoint', 'watchEndpoint', 'playlistId'], True)
|
||||||
|
if watch_id:
|
||||||
|
result[watch_key] = watch_id
|
||||||
|
|
||||||
|
|
||||||
def get_item_text(item, index, run_index=0, none_if_absent=False):
|
def get_item_text(item, index, run_index=0, none_if_absent=False):
|
||||||
column = get_flex_column_item(item, index)
|
column = get_flex_column_item(item, index)
|
||||||
if not column:
|
if not column:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue