Return song count for each playlist in get_playlists
This commit is contained in:
parent
826a72c817
commit
86fbe15ee3
2 changed files with 20 additions and 13 deletions
|
|
@ -8,7 +8,9 @@ MENU_SERVICE = ['menuServiceItemRenderer', 'serviceEndpoint']
|
||||||
PLAY_BUTTON = ['overlay', 'musicItemThumbnailOverlayRenderer', 'content', 'musicPlayButtonRenderer']
|
PLAY_BUTTON = ['overlay', 'musicItemThumbnailOverlayRenderer', 'content', 'musicPlayButtonRenderer']
|
||||||
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, 'text']
|
||||||
|
SUBTITLE = ['subtitle', 'runs', 0, 'text']
|
||||||
|
SUBTITLE2 = ['subtitle', 'runs', 2, 'text']
|
||||||
|
|
||||||
def parse_playlist_items(results, owned=False):
|
def parse_playlist_items(results, owned=False):
|
||||||
songs = []
|
songs = []
|
||||||
|
|
|
||||||
|
|
@ -234,7 +234,7 @@ class YTMusic:
|
||||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)
|
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)
|
||||||
|
|
||||||
artist = {}
|
artist = {}
|
||||||
artist['name'] = response['header']['musicImmersiveHeaderRenderer']['title']['runs'][0]['text']
|
artist['name'] = nav(response['header']['musicImmersiveHeaderRenderer'], TITLE)
|
||||||
artist['description'] = results[-1]['musicDescriptionShelfRenderer']['description']['runs'][0]['text']
|
artist['description'] = results[-1]['musicDescriptionShelfRenderer']['description']['runs'][0]['text']
|
||||||
artist['views'] = results[-1]['musicDescriptionShelfRenderer']['subheader']['runs'][0]['text'].split(' ')[0]
|
artist['views'] = results[-1]['musicDescriptionShelfRenderer']['subheader']['runs'][0]['text'].split(' ')[0]
|
||||||
artist['songs'] = {}
|
artist['songs'] = {}
|
||||||
|
|
@ -254,15 +254,15 @@ class YTMusic:
|
||||||
artist[category]['params'] = nav(data[0], CAROUSEL_TITLE)['navigationEndpoint']['browseEndpoint']['params']
|
artist[category]['params'] = nav(data[0], CAROUSEL_TITLE)['navigationEndpoint']['browseEndpoint']['params']
|
||||||
|
|
||||||
for item in data[0]['contents']:
|
for item in data[0]['contents']:
|
||||||
result = {'title': item['musicTwoRowItemRenderer']['title']['runs'][0]['text']}
|
result = {'title': nav(item['musicTwoRowItemRenderer'], TITLE)}
|
||||||
if category == 'albums':
|
if category == 'albums':
|
||||||
result['year'] = item['musicTwoRowItemRenderer']['subtitle']['runs'][2]['text']
|
result['year'] = nav(item['musicTwoRowItemRenderer'], SUBTITLE2)
|
||||||
result['browseId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['browseEndpoint']['browseId']
|
result['browseId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['browseEndpoint']['browseId']
|
||||||
elif category == 'singles':
|
elif category == 'singles':
|
||||||
result['year'] = item['musicTwoRowItemRenderer']['subtitle']['runs'][0]['text']
|
result['year'] = nav(item['musicTwoRowItemRenderer'], SUBTITLE)
|
||||||
result['browseId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['browseEndpoint']['browseId']
|
result['browseId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['browseEndpoint']['browseId']
|
||||||
elif category == 'videos':
|
elif category == 'videos':
|
||||||
result['views'] = item['musicTwoRowItemRenderer']['subtitle']['runs'][2]['text'].split(' ')[0]
|
result['views'] = nav(item['musicTwoRowItemRenderer'], SUBTITLE2).split(' ')[0]
|
||||||
result['videoId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['watchEndpoint']['videoId']
|
result['videoId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['watchEndpoint']['videoId']
|
||||||
result['playlistId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['watchEndpoint']['playlistId']
|
result['playlistId'] = item['musicTwoRowItemRenderer']['title']['runs'][0]['navigationEndpoint']['watchEndpoint']['playlistId']
|
||||||
artist[category]['results'].append(result)
|
artist[category]['results'].append(result)
|
||||||
|
|
@ -291,11 +291,11 @@ class YTMusic:
|
||||||
body = {"browseId": channelId, "params": params}
|
body = {"browseId": channelId, "params": params}
|
||||||
endpoint = 'browse'
|
endpoint = 'browse'
|
||||||
response = self.__send_request(endpoint, body)
|
response = self.__send_request(endpoint, body)
|
||||||
artist = response['header']['musicHeaderRenderer']['title']['runs'][0]['text']
|
artist = nav(response['header']['musicHeaderRenderer'], TITLE)
|
||||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)
|
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)
|
||||||
albums = []
|
albums = []
|
||||||
musicShelf = results[0]['musicShelfRenderer']
|
musicShelf = results[0]['musicShelfRenderer']
|
||||||
release_type = musicShelf['title']['runs'][0]['text'].lower()
|
release_type = nav(musicShelf, TITLE).lower()
|
||||||
for result in musicShelf['contents']:
|
for result in musicShelf['contents']:
|
||||||
data = result['musicResponsiveListItemRenderer']
|
data = result['musicResponsiveListItemRenderer']
|
||||||
browseId = data['navigationEndpoint']['browseEndpoint']['browseId']
|
browseId = data['navigationEndpoint']['browseEndpoint']['browseId']
|
||||||
|
|
@ -356,7 +356,8 @@ class YTMusic:
|
||||||
|
|
||||||
{
|
{
|
||||||
'playlistId': 'PLQwVIlKxHM6rz0fDJVv_0UlXGEWf-bFys',
|
'playlistId': 'PLQwVIlKxHM6rz0fDJVv_0UlXGEWf-bFys',
|
||||||
'title': 'Playlist title'
|
'title': 'Playlist title',
|
||||||
|
'count': 5
|
||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
@ -371,9 +372,13 @@ class YTMusic:
|
||||||
# skip first item ("New Playlist" button)
|
# skip first item ("New Playlist" button)
|
||||||
for result in results[1:]:
|
for result in results[1:]:
|
||||||
data = result['musicTwoRowItemRenderer']
|
data = result['musicTwoRowItemRenderer']
|
||||||
playlistId = data['title']['runs'][0]['navigationEndpoint']['browseEndpoint']['browseId'][2:]
|
playlist = {}
|
||||||
title = data['title']['runs'][0]['text']
|
playlist['playlistId'] = data['title']['runs'][0]['navigationEndpoint']['browseEndpoint']['browseId'][2:]
|
||||||
playlists.append({'playlistId': playlistId, 'title': title})
|
playlist['title'] = nav(data, TITLE)
|
||||||
|
if len(data['subtitle']['runs']) == 3:
|
||||||
|
playlist['count'] = nav(data, SUBTITLE2).split(' ')[0]
|
||||||
|
|
||||||
|
playlists.append(playlist)
|
||||||
|
|
||||||
return playlists
|
return playlists
|
||||||
|
|
||||||
|
|
@ -403,7 +408,7 @@ class YTMusic:
|
||||||
data = content['musicShelfRenderer']['contents']
|
data = content['musicShelfRenderer']['contents']
|
||||||
songlist = parse_playlist_items(data)
|
songlist = parse_playlist_items(data)
|
||||||
for song in songlist:
|
for song in songlist:
|
||||||
song['played'] = content['musicShelfRenderer']['title']['runs'][0]['text']
|
song['played'] = nav(content['musicShelfRenderer'], TITLE)
|
||||||
songs.extend(songlist)
|
songs.extend(songlist)
|
||||||
|
|
||||||
return songs
|
return songs
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue