get_playlist, get_library_songs, get_history, get_liked_songs: fix feedbackTokens, add inLibrary flag (closes #454)
This commit is contained in:
parent
05a5fb8153
commit
437844fa79
5 changed files with 23 additions and 5 deletions
|
|
@ -393,10 +393,14 @@ class TestYTMusic(unittest.TestCase):
|
|||
def test_edit_song_library_status(self):
|
||||
album = self.yt_brand.get_album(sample_album)
|
||||
response = self.yt_brand.edit_song_library_status(
|
||||
album["tracks"][2]["feedbackTokens"]["add"])
|
||||
album["tracks"][0]["feedbackTokens"]["add"])
|
||||
album = self.yt_brand.get_album(sample_album)
|
||||
self.assertTrue(album["tracks"][0]["inLibrary"])
|
||||
self.assertTrue(response["feedbackResponses"][0]["isProcessed"])
|
||||
response = self.yt_brand.edit_song_library_status(
|
||||
album["tracks"][2]["feedbackTokens"]["remove"])
|
||||
album["tracks"][0]["feedbackTokens"]["remove"])
|
||||
album = self.yt_brand.get_album(sample_album)
|
||||
self.assertFalse(album["tracks"][0]["inLibrary"])
|
||||
self.assertTrue(response["feedbackResponses"][0]["isProcessed"])
|
||||
|
||||
def test_rate_playlist(self):
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
|||
videoId = setVideoId = None
|
||||
like = None
|
||||
feedback_tokens = None
|
||||
library_status = None
|
||||
|
||||
# if the item has a menu, find its setVideoId
|
||||
if 'menu' in data:
|
||||
|
|
@ -27,6 +28,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
|||
|
||||
if TOGGLE_MENU in item:
|
||||
feedback_tokens = parse_song_menu_tokens(item)
|
||||
library_status = parse_song_library_status(item)
|
||||
|
||||
# if item is not playable, the videoId was retrieved above
|
||||
if nav(data, PLAY_BUTTON, none_if_absent=True) is not None:
|
||||
|
|
@ -73,6 +75,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
|||
'artists': artists,
|
||||
'album': album,
|
||||
'likeStatus': like,
|
||||
'inLibrary': library_status,
|
||||
'thumbnails': thumbnails,
|
||||
'isAvailable': isAvailable,
|
||||
'isExplicit': isExplicit,
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ def parse_search_result(data, search_result_types, result_type, category):
|
|||
if 'menu' in data:
|
||||
toggle_menu = find_object_by_key(nav(data, MENU_ITEMS), TOGGLE_MENU)
|
||||
if toggle_menu:
|
||||
search_result['inLibrary'] = parse_song_library_status(toggle_menu)
|
||||
search_result['feedbackTokens'] = parse_song_menu_tokens(toggle_menu)
|
||||
|
||||
elif result_type == 'upload':
|
||||
|
|
|
|||
|
|
@ -62,13 +62,21 @@ def parse_song_album(data, index):
|
|||
}
|
||||
|
||||
|
||||
def parse_song_library_status(item) -> bool:
|
||||
"""Returns True if song is in the library"""
|
||||
library_status = nav(item, [TOGGLE_MENU, 'defaultIcon', 'iconType'], True)
|
||||
|
||||
return library_status == "LIBRARY_SAVED"
|
||||
|
||||
|
||||
def parse_song_menu_tokens(item):
|
||||
toggle_menu = item[TOGGLE_MENU]
|
||||
service_type = toggle_menu['defaultIcon']['iconType']
|
||||
|
||||
library_add_token = nav(toggle_menu, ['defaultServiceEndpoint'] + FEEDBACK_TOKEN, True)
|
||||
library_remove_token = nav(toggle_menu, ['toggledServiceEndpoint'] + FEEDBACK_TOKEN, True)
|
||||
|
||||
if service_type == "LIBRARY_REMOVE": # swap if already in library
|
||||
in_library = parse_song_library_status(item)
|
||||
if in_library:
|
||||
library_add_token, library_remove_token = library_remove_token, library_add_token
|
||||
|
||||
return {'add': library_add_token, 'remove': library_remove_token}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ def parse_watch_playlist(results):
|
|||
|
||||
|
||||
def parse_watch_track(data):
|
||||
feedback_tokens = like_status = None
|
||||
feedback_tokens = like_status = library_status = None
|
||||
for item in nav(data, MENU_ITEMS):
|
||||
if TOGGLE_MENU in item:
|
||||
library_status = parse_song_library_status(item)
|
||||
service = item[TOGGLE_MENU]['defaultServiceEndpoint']
|
||||
if 'feedbackEndpoint' in service:
|
||||
feedback_tokens = parse_song_menu_tokens(item)
|
||||
|
|
@ -44,6 +45,7 @@ def parse_watch_track(data):
|
|||
'thumbnail': nav(data, THUMBNAIL),
|
||||
'feedbackTokens': feedback_tokens,
|
||||
'likeStatus': like_status,
|
||||
'inLibrary': library_status,
|
||||
'videoType': nav(data, ['navigationEndpoint'] + NAVIGATION_VIDEO_TYPE, True)
|
||||
}
|
||||
track.update(song_info)
|
||||
|
|
|
|||
Loading…
Reference in a new issue