Support song order for get_library_upload_songs
This commit is contained in:
parent
c378b58296
commit
19e9053706
2 changed files with 17 additions and 1 deletions
|
|
@ -215,6 +215,12 @@ class TestYTMusic(unittest.TestCase):
|
||||||
def test_get_library_upload_songs(self):
|
def test_get_library_upload_songs(self):
|
||||||
results = youtube_auth.get_library_upload_songs(100)
|
results = youtube_auth.get_library_upload_songs(100)
|
||||||
self.assertGreater(len(results), 25)
|
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")
|
@unittest.skip("Must not have any uploaded songs to pass")
|
||||||
def test_get_library_upload_songs_empty(self):
|
def test_get_library_upload_songs_empty(self):
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ from ytmusicapi.parsers.uploads import *
|
||||||
|
|
||||||
|
|
||||||
class UploadsMixin:
|
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
|
Returns a list of uploaded songs
|
||||||
|
|
||||||
:param limit: How many songs to return. Default: 25
|
: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.
|
:return: List of uploaded songs.
|
||||||
|
|
||||||
Each item is in the following format::
|
Each item is in the following format::
|
||||||
|
|
@ -29,7 +30,16 @@ class UploadsMixin:
|
||||||
"""
|
"""
|
||||||
self._check_auth()
|
self._check_auth()
|
||||||
endpoint = 'browse'
|
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"}
|
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)
|
response = self._send_request(endpoint, body)
|
||||||
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
|
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
|
||||||
'itemSectionRenderer')
|
'itemSectionRenderer')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue