Addded favorite artists to taste
This commit is contained in:
parent
fbb26dde94
commit
d66f20aa13
4 changed files with 74 additions and 15 deletions
|
|
@ -164,9 +164,16 @@ class TestYTMusic(unittest.TestCase):
|
||||||
signatureTimestamp = self.yt.get_signatureTimestamp()
|
signatureTimestamp = self.yt.get_signatureTimestamp()
|
||||||
self.assertIsNotNone(signatureTimestamp)
|
self.assertIsNotNone(signatureTimestamp)
|
||||||
|
|
||||||
###############
|
def test_set_tasteprofile(self):
|
||||||
|
self.assertRaises(self.yt.set_tasteprofile("Galactic"))
|
||||||
|
|
||||||
|
def test_get_tasteprofile(self):
|
||||||
|
result = self.yt.get_tasteprofiles()
|
||||||
|
self.assertGreaterEqual(len(result), 0)
|
||||||
|
|
||||||
|
################
|
||||||
# EXPLORE
|
# EXPLORE
|
||||||
###############
|
################
|
||||||
|
|
||||||
def test_get_mood_playlists(self):
|
def test_get_mood_playlists(self):
|
||||||
categories = self.yt.get_mood_categories()
|
categories = self.yt.get_mood_categories()
|
||||||
|
|
@ -206,9 +213,9 @@ class TestYTMusic(unittest.TestCase):
|
||||||
playlist = self.yt_brand.get_watch_playlist_shuffle(playlistId=config['playlists']['own'])
|
playlist = self.yt_brand.get_watch_playlist_shuffle(playlistId=config['playlists']['own'])
|
||||||
self.assertEqual(len(playlist['tracks']), 4)
|
self.assertEqual(len(playlist['tracks']), 4)
|
||||||
|
|
||||||
###############
|
################
|
||||||
# LIBRARY
|
# LIBRARY
|
||||||
###############
|
################
|
||||||
|
|
||||||
def test_get_library_playlists(self):
|
def test_get_library_playlists(self):
|
||||||
playlists = self.yt_auth.get_library_playlists(50)
|
playlists = self.yt_auth.get_library_playlists(50)
|
||||||
|
|
|
||||||
|
|
@ -211,9 +211,7 @@ class BrowsingMixin:
|
||||||
artist = {'description': None, 'views': None}
|
artist = {'description': None, 'views': None}
|
||||||
header = response['header']['musicImmersiveHeaderRenderer']
|
header = response['header']['musicImmersiveHeaderRenderer']
|
||||||
artist['name'] = nav(header, TITLE_TEXT)
|
artist['name'] = nav(header, TITLE_TEXT)
|
||||||
descriptionShelf = find_object_by_key(results,
|
descriptionShelf = find_object_by_key(results, DESCRIPTION_SHELF[0], is_key=True)
|
||||||
DESCRIPTION_SHELF[0],
|
|
||||||
is_key=True)
|
|
||||||
if descriptionShelf:
|
if descriptionShelf:
|
||||||
artist['description'] = nav(descriptionShelf, DESCRIPTION)
|
artist['description'] = nav(descriptionShelf, DESCRIPTION)
|
||||||
artist['views'] = None if 'subheader' not in descriptionShelf else descriptionShelf[
|
artist['views'] = None if 'subheader' not in descriptionShelf else descriptionShelf[
|
||||||
|
|
@ -674,10 +672,11 @@ class BrowsingMixin:
|
||||||
raise Exception("Invalid browseId provided. This song might not have lyrics.")
|
raise Exception("Invalid browseId provided. This song might not have lyrics.")
|
||||||
|
|
||||||
response = self._send_request('browse', {'browseId': browseId})
|
response = self._send_request('browse', {'browseId': browseId})
|
||||||
lyrics['lyrics'] = nav(response, ['contents'] + SECTION_LIST_ITEM
|
lyrics['lyrics'] = nav(response,
|
||||||
+ DESCRIPTION_SHELF + DESCRIPTION, True)
|
['contents'] + SECTION_LIST_ITEM + DESCRIPTION_SHELF + DESCRIPTION,
|
||||||
lyrics['source'] = nav(response, ['contents'] + SECTION_LIST_ITEM
|
True)
|
||||||
+ DESCRIPTION_SHELF + ['footer'] + RUN_TEXT, True)
|
lyrics['source'] = nav(response, ['contents'] + SECTION_LIST_ITEM + DESCRIPTION_SHELF
|
||||||
|
+ ['footer'] + RUN_TEXT, True)
|
||||||
|
|
||||||
return lyrics
|
return lyrics
|
||||||
|
|
||||||
|
|
@ -711,3 +710,41 @@ class BrowsingMixin:
|
||||||
raise Exception("Unable to identify the signatureTimestamp.")
|
raise Exception("Unable to identify the signatureTimestamp.")
|
||||||
|
|
||||||
return int(match.group(1))
|
return int(match.group(1))
|
||||||
|
|
||||||
|
def get_tasteprofiles(self) -> Dict:
|
||||||
|
"""
|
||||||
|
Fetches all artists from taste profile (music.youtube.com/tasteprofile)
|
||||||
|
|
||||||
|
:return: Dictionary with artist and their selection & impression value
|
||||||
|
|
||||||
|
Example::
|
||||||
|
{
|
||||||
|
"Drake": {
|
||||||
|
"selectionValue": "tastebuilder_selection=/m/05mt_q",
|
||||||
|
"impressionValue": "tastebuilder_impression=/m/05mt_q"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
response = self._send_request('browse', {'browseId': "FEmusic_tastebuilder"})
|
||||||
|
return parse_tasteprofiles(response)
|
||||||
|
|
||||||
|
def set_tasteprofile(self, *artists: str) -> None:
|
||||||
|
"""
|
||||||
|
Favorites artists to see more recommendations from the artist
|
||||||
|
"""
|
||||||
|
|
||||||
|
taste_profiles = self.get_tasteprofiles()
|
||||||
|
formData = {
|
||||||
|
"impressionValues":
|
||||||
|
[taste_profiles[profile]["impressionValue"] for profile in taste_profiles],
|
||||||
|
"selectedValues": []
|
||||||
|
}
|
||||||
|
|
||||||
|
for artist in artists:
|
||||||
|
if artist not in taste_profiles:
|
||||||
|
raise Exception("The artist, {}, was not present in taste!".format(artist))
|
||||||
|
formData["selectedValues"].append(taste_profiles[artist]["selectionValue"])
|
||||||
|
|
||||||
|
body = {'browseId': "FEmusic_home", "formData": formData}
|
||||||
|
|
||||||
|
self._send_request('browse', body)
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ CATEGORY_TITLE = ['musicNavigationButtonRenderer', 'buttonText'] + RUN_TEXT
|
||||||
CATEGORY_PARAMS = ['musicNavigationButtonRenderer', 'clickCommand', 'browseEndpoint', 'params']
|
CATEGORY_PARAMS = ['musicNavigationButtonRenderer', 'clickCommand', 'browseEndpoint', 'params']
|
||||||
MRLIR = 'musicResponsiveListItemRenderer'
|
MRLIR = 'musicResponsiveListItemRenderer'
|
||||||
MTRIR = 'musicTwoRowItemRenderer'
|
MTRIR = 'musicTwoRowItemRenderer'
|
||||||
|
TASTE_PROFILE_ITEMS = ["contents", "tastebuilderRenderer", "contents"]
|
||||||
|
TASTE_PROFILE_ARTIST = ["title", "runs"]
|
||||||
|
|
||||||
|
|
||||||
def nav(root, items, none_if_absent=False):
|
def nav(root, items, none_if_absent=False):
|
||||||
|
|
|
||||||
|
|
@ -227,9 +227,7 @@ def parse_song(result):
|
||||||
|
|
||||||
|
|
||||||
def parse_song_flat(data):
|
def parse_song_flat(data):
|
||||||
columns = [
|
columns = [get_flex_column_item(data, i) for i in range(0, len(data['flexColumns']))]
|
||||||
get_flex_column_item(data, i) for i in range(0, len(data['flexColumns']))
|
|
||||||
]
|
|
||||||
song = {
|
song = {
|
||||||
'title': nav(columns[0], TEXT_RUN_TEXT),
|
'title': nav(columns[0], TEXT_RUN_TEXT),
|
||||||
'videoId': nav(columns[0], TEXT_RUN + NAVIGATION_VIDEO_ID, True),
|
'videoId': nav(columns[0], TEXT_RUN + NAVIGATION_VIDEO_ID, True),
|
||||||
|
|
@ -237,7 +235,8 @@ def parse_song_flat(data):
|
||||||
'thumbnails': nav(data, THUMBNAILS),
|
'thumbnails': nav(data, THUMBNAILS),
|
||||||
'isExplicit': nav(data, BADGE_LABEL, True) is not None
|
'isExplicit': nav(data, BADGE_LABEL, True) is not None
|
||||||
}
|
}
|
||||||
if len(columns) > 2 and columns[2] is not None and 'navigationEndpoint' in nav(columns[2], TEXT_RUN):
|
if len(columns) > 2 and columns[2] is not None and 'navigationEndpoint' in nav(
|
||||||
|
columns[2], TEXT_RUN):
|
||||||
song['album'] = {
|
song['album'] = {
|
||||||
'name': nav(columns[2], TEXT_RUN_TEXT),
|
'name': nav(columns[2], TEXT_RUN_TEXT),
|
||||||
'id': nav(columns[2], TEXT_RUN + NAVIGATION_BROWSE_ID)
|
'id': nav(columns[2], TEXT_RUN + NAVIGATION_BROWSE_ID)
|
||||||
|
|
@ -288,3 +287,17 @@ def parse_related_artist(data):
|
||||||
'subscribers': subscribers,
|
'subscribers': subscribers,
|
||||||
'thumbnails': nav(data, THUMBNAIL_RENDERER),
|
'thumbnails': nav(data, THUMBNAIL_RENDERER),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def parse_tasteprofiles(data):
|
||||||
|
profiles = nav(data, TASTE_PROFILE_ITEMS)
|
||||||
|
|
||||||
|
taste_profiles = {}
|
||||||
|
for itemList in profiles:
|
||||||
|
for item in itemList["tastebuilderItemListRenderer"]["contents"]:
|
||||||
|
artist = nav(item["tastebuilderItemRenderer"], TASTE_PROFILE_ARTIST)[0]["text"]
|
||||||
|
taste_profiles[artist] = {
|
||||||
|
"selectionValue": item["tastebuilderItemRenderer"]["selectionFormValue"],
|
||||||
|
"impressionValue": item["tastebuilderItemRenderer"]["impressionFormValue"]
|
||||||
|
}
|
||||||
|
return taste_profiles
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue