set_tasteprofile: make internal get_tasteprofile request optional (#289)
This commit is contained in:
parent
c3ed850026
commit
4512dac409
2 changed files with 18 additions and 15 deletions
|
|
@ -165,13 +165,13 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertIsNotNone(signatureTimestamp)
|
self.assertIsNotNone(signatureTimestamp)
|
||||||
|
|
||||||
def test_set_tasteprofile(self):
|
def test_set_tasteprofile(self):
|
||||||
artists = [artist for artist in self.yt.get_tasteprofile()]
|
|
||||||
|
|
||||||
self.assertRaises(Exception, self.yt.set_tasteprofile, "not an artist")
|
self.assertRaises(Exception, self.yt.set_tasteprofile, "not an artist")
|
||||||
self.assertIsNone(self.yt.set_tasteprofile(artists[:5]))
|
taste_profile = self.yt.get_tasteprofile()
|
||||||
|
self.assertIsNone(self.yt.set_tasteprofile(list(taste_profile)[:5], taste_profile))
|
||||||
|
|
||||||
self.assertIsNone(self.yt_brand.set_tasteprofile(artists[:1]))
|
self.assertRaises(Exception, self.yt_brand.set_tasteprofile, ["test", "test2"])
|
||||||
self.assertIsNone(self.yt_brand.set_tasteprofile(artists[:5]))
|
taste_profile = self.yt_brand.get_tasteprofile()
|
||||||
|
self.assertIsNone(self.yt_brand.set_tasteprofile(list(taste_profile)[:1], taste_profile))
|
||||||
|
|
||||||
def test_get_tasteprofile(self):
|
def test_get_tasteprofile(self):
|
||||||
result = self.yt.get_tasteprofile()
|
result = self.yt.get_tasteprofile()
|
||||||
|
|
|
||||||
|
|
@ -714,7 +714,7 @@ class BrowsingMixin:
|
||||||
def get_tasteprofile(self) -> Dict:
|
def get_tasteprofile(self) -> Dict:
|
||||||
"""
|
"""
|
||||||
Fetches suggested artists from taste profile (music.youtube.com/tasteprofile).
|
Fetches suggested artists from taste profile (music.youtube.com/tasteprofile).
|
||||||
Tasteprofile allows users to pick artists to update their reccomendations.
|
Tasteprofile allows users to pick artists to update their recommendations.
|
||||||
Only returns a list of suggested artists, not the actual list of selected entries
|
Only returns a list of suggested artists, not the actual list of selected entries
|
||||||
|
|
||||||
:return: Dictionary with artist and their selection & impression value
|
:return: Dictionary with artist and their selection & impression value
|
||||||
|
|
@ -743,26 +743,29 @@ class BrowsingMixin:
|
||||||
}
|
}
|
||||||
return taste_profiles
|
return taste_profiles
|
||||||
|
|
||||||
def set_tasteprofile(self, artists: List[str]) -> None:
|
def set_tasteprofile(self, artists: List[str], taste_profile: Dict = None) -> None:
|
||||||
"""
|
"""
|
||||||
Favorites artists to see more recommendations from the artist.
|
Favorites artists to see more recommendations from the artist.
|
||||||
Use get_tasteprofile() to see which artists are available to be recommended
|
Use get_tasteprofile() to see which artists are available to be recommended
|
||||||
|
|
||||||
:param artists: A List with names of artists
|
:param artists: A List with names of artists, must be contained in the tasteprofile
|
||||||
|
:param taste_profile: tasteprofile result from :py:func:`get_tasteprofile`.
|
||||||
|
Pass this if you call :py:func:`get_tasteprofile` anyway to save an extra request.
|
||||||
|
:return None if successful
|
||||||
"""
|
"""
|
||||||
|
|
||||||
taste_profiles = self.get_tasteprofile()
|
if taste_profile is None:
|
||||||
|
taste_profile = self.get_tasteprofile()
|
||||||
formData = {
|
formData = {
|
||||||
"impressionValues":
|
"impressionValues":
|
||||||
[taste_profiles[profile]["impressionValue"] for profile in taste_profiles],
|
[taste_profile[profile]["impressionValue"] for profile in taste_profile],
|
||||||
"selectedValues": []
|
"selectedValues": []
|
||||||
}
|
}
|
||||||
|
|
||||||
for artist in artists:
|
for artist in artists:
|
||||||
if artist not in taste_profiles:
|
if artist not in taste_profile:
|
||||||
raise Exception("The artist, {}, was not present in taste!".format(artist))
|
raise Exception("The artist, {}, was not present in taste!".format(artist))
|
||||||
formData["selectedValues"].append(taste_profiles[artist]["selectionValue"])
|
formData["selectedValues"].append(taste_profile[artist]["selectionValue"])
|
||||||
|
|
||||||
body = {'browseId': "FEmusic_home", "formData": formData}
|
body = {'browseId': "FEmusic_home", "formData": formData}
|
||||||
self._send_request('browse', body)
|
self._send_request('browse', body)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue