Support song order for get_library_upload_songs

This commit is contained in:
ide-an 2020-11-09 02:17:39 +09:00 • committed by sigma67
commit 19e9053706
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
2 changed files with 17 additions and 1 deletions

View file

@ -215,6 +215,12 @@ class TestYTMusic(unittest.TestCase):
def test_get_library_upload_songs(self):
results = youtube_auth.get_library_upload_songs(100)
self.assertGreater(len(results), 25)
results = youtube_auth.get_library_upload_songs(100, 'a_to_z')
self.assertGreater(len(results), 25)
results = youtube_auth.get_library_upload_songs(100, 'z_to_a')
self.assertGreater(len(results), 25)
results = youtube_auth.get_library_upload_songs(100, 'recently_added')
self.assertGreater(len(results), 25)
@unittest.skip("Must not have any uploaded songs to pass")
def test_get_library_upload_songs_empty(self):

View file

@ -8,11 +8,12 @@ from ytmusicapi.parsers.uploads import *
class UploadsMixin:
def get_library_upload_songs(self, limit: int = 25) -> List[Dict]:
def get_library_upload_songs(self, limit: int = 25, order: str = None) -> List[Dict]:
"""
Returns a list of uploaded songs
:param limit: How many songs to return. Default: 25
:param order: Determine song order. Allowed values: 'a_to_z', 'z_to_a', 'recently_added'. Default: Default order.
:return: List of uploaded songs.
Each item is in the following format::
@ -29,7 +30,16 @@ class UploadsMixin:
"""
self._check_auth()
endpoint = 'browse'
orders = ['a_to_z', 'z_to_a', 'recently_added']
if order and order not in orders:
raise Exception(
"Invalid order provided. Please use one of the following orders or leave out the parameter: "
+ ', '.join(orders))
body = {"browseId": "FEmusic_library_privately_owned_tracks"}
if order is not None:
# determine order_params via `.contents.singleColumnBrowseResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[1].itemSectionRenderer.header.itemSectionTabbedHeaderRenderer.endItems[1].dropdownRenderer.entries[].dropdownItemRenderer.onSelectCommand.browseEndpoint.params` of `/youtubei/v1/browse` response
order_params = ['ggMGKgQIARAA', 'ggMGKgQIARAB', 'ggMGKgQIABAB']
body["params"] = order_params[orders.index(order)]
response = self._send_request(endpoint, body)
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
'itemSectionRenderer')