Fix continuations to always retrieve at least the specified limit, even if YTMusic returns less than per_page
This commit is contained in:
parent
2e872798ae
commit
90bc7538e4
2 changed files with 4 additions and 6 deletions
|
|
@ -69,15 +69,15 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreater(len(playlists), 0)
|
self.assertGreater(len(playlists), 0)
|
||||||
|
|
||||||
def test_get_library_songs(self):
|
def test_get_library_songs(self):
|
||||||
songs = youtube_brand.get_library_songs(200)
|
songs = youtube_brand.get_library_songs(100)
|
||||||
self.assertGreater(len(songs), 0)
|
self.assertGreater(len(songs), 0)
|
||||||
|
|
||||||
def test_get_library_albums(self):
|
def test_get_library_albums(self):
|
||||||
albums = youtube_brand.get_library_albums(50)
|
albums = youtube_brand.get_library_albums(100)
|
||||||
self.assertGreater(len(albums), 0)
|
self.assertGreater(len(albums), 0)
|
||||||
|
|
||||||
def test_get_library_artists(self):
|
def test_get_library_artists(self):
|
||||||
artists = youtube_brand.get_library_artists(50)
|
artists = youtube_brand.get_library_artists(100)
|
||||||
self.assertGreater(len(artists), 0)
|
self.assertGreater(len(artists), 0)
|
||||||
|
|
||||||
def test_get_library_subscriptions(self):
|
def test_get_library_subscriptions(self):
|
||||||
|
|
|
||||||
|
|
@ -310,16 +310,14 @@ def get_browse_id(item, index):
|
||||||
|
|
||||||
|
|
||||||
def get_continuations(results, continuation_type, per_page, limit, request_func, parse_func):
|
def get_continuations(results, continuation_type, per_page, limit, request_func, parse_func):
|
||||||
request_count = 1
|
|
||||||
items = []
|
items = []
|
||||||
while 'continuations' in results and request_count * per_page < limit:
|
while 'continuations' in results and len(items) < limit - per_page:
|
||||||
ctoken = nav(results, CONTINUATION)
|
ctoken = nav(results, CONTINUATION)
|
||||||
additionalParams = "&ctoken=" + ctoken + "&continuation=" + ctoken
|
additionalParams = "&ctoken=" + ctoken + "&continuation=" + ctoken
|
||||||
response = request_func(additionalParams)
|
response = request_func(additionalParams)
|
||||||
results = response['continuationContents'][continuation_type]
|
results = response['continuationContents'][continuation_type]
|
||||||
continuation_contents = 'contents' if 'Shelf' in continuation_type else 'items'
|
continuation_contents = 'contents' if 'Shelf' in continuation_type else 'items'
|
||||||
items.extend(parse_func(results[continuation_contents]))
|
items.extend(parse_func(results[continuation_contents]))
|
||||||
request_count += 1
|
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue