Add subscription properties to get_artist (fixes #35)
subscribers, subscribed and channelId
This commit is contained in:
parent
93d744897f
commit
667a6edc81
2 changed files with 16 additions and 7 deletions
|
|
@ -41,7 +41,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
|
|
||||||
def test_get_artist(self):
|
def test_get_artist(self):
|
||||||
results = youtube.get_artist("UCmMUZbaYdNH0bEd1PAlAqsA")
|
results = youtube.get_artist("UCmMUZbaYdNH0bEd1PAlAqsA")
|
||||||
self.assertEqual(len(results), 8)
|
self.assertEqual(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")
|
||||||
|
|
@ -107,8 +107,8 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertIn('actions', response)
|
self.assertIn('actions', response)
|
||||||
|
|
||||||
def test_subscribe_artists(self):
|
def test_subscribe_artists(self):
|
||||||
youtube_auth.subscribe_artists(['UCmMUZbaYdNH0bEd1PAlAqsA', 'UCEPMVbUzImPl4p8k4LkGevA'])
|
youtube_auth.subscribe_artists(['UCUDVBtnOQi4c7E8jebpjc9Q', 'UCiMhD4jzUqG-IgPzUmmytRQ'])
|
||||||
youtube_auth.unsubscribe_artists(['UCmMUZbaYdNH0bEd1PAlAqsA', 'UCEPMVbUzImPl4p8k4LkGevA'])
|
youtube_auth.unsubscribe_artists(['UCUDVBtnOQi4c7E8jebpjc9Q', 'UCiMhD4jzUqG-IgPzUmmytRQ'])
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# PLAYLISTS
|
# PLAYLISTS
|
||||||
|
|
|
||||||
|
|
@ -203,9 +203,12 @@ class YTMusic:
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Oasis",
|
|
||||||
"description": "Oasis were ...",
|
"description": "Oasis were ...",
|
||||||
"views": "1838795605",
|
"views": "1838795605",
|
||||||
|
"name": "Oasis",
|
||||||
|
"channelId": "UCUDVBtnOQi4c7E8jebpjc9Q",
|
||||||
|
"subscribers": "2.3M",
|
||||||
|
"subscribed": false,
|
||||||
"thumbnails": [...],
|
"thumbnails": [...],
|
||||||
"songs": {
|
"songs": {
|
||||||
"browseId": "VLPLMpM3Z0118S42R1npOhcjoakLIv1aqnS1",
|
"browseId": "VLPLMpM3Z0118S42R1npOhcjoakLIv1aqnS1",
|
||||||
|
|
@ -263,14 +266,20 @@ class YTMusic:
|
||||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)
|
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST)
|
||||||
|
|
||||||
artist = {'description': None, 'views': None}
|
artist = {'description': None, 'views': None}
|
||||||
artist['name'] = nav(response['header']['musicImmersiveHeaderRenderer'], TITLE_TEXT)
|
header = response['header']['musicImmersiveHeaderRenderer']
|
||||||
|
artist['name'] = nav(header, TITLE_TEXT)
|
||||||
descriptionShelf = find_object_by_key(results,
|
descriptionShelf = find_object_by_key(results,
|
||||||
'musicDescriptionShelfRenderer',
|
'musicDescriptionShelfRenderer',
|
||||||
is_key=True)
|
is_key=True)
|
||||||
if descriptionShelf:
|
if descriptionShelf:
|
||||||
artist['description'] = descriptionShelf['description']['runs'][0]['text']
|
artist['description'] = descriptionShelf['description']['runs'][0]['text']
|
||||||
artist['views'] = to_int(descriptionShelf['subheader']['runs'][0]['text'])
|
artist['views'] = to_int(descriptionShelf['subheader']['runs'][0]['text'])
|
||||||
artist['thumbnails'] = nav(response['header']['musicImmersiveHeaderRenderer'], THUMBNAILS)
|
subscription_button = header['subscriptionButton']['subscribeButtonRenderer']
|
||||||
|
artist['channelId'] = subscription_button['channelId']
|
||||||
|
artist['subscribers'] = nav(subscription_button,
|
||||||
|
['subscriberCountText', 'runs', 0, 'text'])
|
||||||
|
artist['subscribed'] = subscription_button['subscribed']
|
||||||
|
artist['thumbnails'] = nav(header, THUMBNAILS)
|
||||||
artist['songs'] = {'browseId': None}
|
artist['songs'] = {'browseId': None}
|
||||||
if 'musicShelfRenderer' in results[0]: # API sometimes does not return songs
|
if 'musicShelfRenderer' in results[0]: # API sometimes does not return songs
|
||||||
musicShelf = nav(results, MUSIC_SHELF)
|
musicShelf = nav(results, MUSIC_SHELF)
|
||||||
|
|
@ -422,7 +431,7 @@ class YTMusic:
|
||||||
album['tracks'] = []
|
album['tracks'] = []
|
||||||
|
|
||||||
likes = {}
|
likes = {}
|
||||||
for item in data[4:]:
|
for item in data:
|
||||||
if 'musicTrackUserDetail' in item['payload']:
|
if 'musicTrackUserDetail' in item['payload']:
|
||||||
like_state = item['payload']['musicTrackUserDetail']['likeState'].split('_')[-1]
|
like_state = item['payload']['musicTrackUserDetail']['likeState'].split('_')[-1]
|
||||||
parent_track = item['payload']['musicTrackUserDetail']['parentTrack']
|
parent_track = item['payload']['musicTrackUserDetail']['parentTrack']
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue