get_library_songs: add support for limit=None (closes #275)

add tests for get_library_subscriptions and get_library_artists with limit=None
This commit is contained in:
sigma67 2022-09-26 13:12:45 +02:00
commit 98c4661fce
No known key found for this signature in database
GPG key ID: 1C314227DF0103D0
2 changed files with 11 additions and 14 deletions

View file

@ -242,16 +242,13 @@ class TestYTMusic(unittest.TestCase):
self.assertEqual(len(playlists), expected_length)
def test_get_library_songs(self):
self.assertRaises(Exception, self.yt_auth.get_library_songs, None, True)
songs = self.yt_brand.get_library_songs(100)
self.assertGreaterEqual(len(songs), 100)
songs = self.yt_auth.get_library_songs(200, validate_responses=True)
self.assertGreaterEqual(len(songs), 200)
songs = self.yt_auth.get_library_songs(order='a_to_z')
self.assertGreaterEqual(len(songs), 25)
songs = self.yt_auth.get_library_songs(order='z_to_a')
self.assertGreaterEqual(len(songs), 25)
songs = self.yt_auth.get_library_songs(order='recently_added')
self.assertGreaterEqual(len(songs), 25)
def test_get_library_albums(self):
albums = self.yt_auth.get_library_albums(100)
@ -268,20 +265,16 @@ class TestYTMusic(unittest.TestCase):
self.assertGreater(len(artists), 40)
artists = self.yt_brand.get_library_artists(order='a_to_z', limit=50)
self.assertGreater(len(artists), 40)
artists = self.yt_brand.get_library_artists(order='z_to_a')
self.assertGreater(len(artists), 20)
artists = self.yt_brand.get_library_artists(order='recently_added')
self.assertGreater(len(artists), 20)
artists = self.yt_brand.get_library_artists(limit=None)
self.assertGreater(len(artists), 300)
def test_get_library_subscriptions(self):
artists = self.yt_brand.get_library_subscriptions(50)
self.assertGreater(len(artists), 40)
artists = self.yt_brand.get_library_subscriptions(order='a_to_z')
self.assertGreater(len(artists), 20)
artists = self.yt_brand.get_library_subscriptions(order='z_to_a')
self.assertGreater(len(artists), 20)
artists = self.yt_brand.get_library_subscriptions(order='recently_added')
self.assertGreater(len(artists), 20)
artists = self.yt_brand.get_library_subscriptions(limit=None)
self.assertGreater(len(artists), 50)
def test_get_liked_songs(self):
songs = self.yt_brand.get_liked_songs(200)
@ -404,7 +397,7 @@ class TestYTMusic(unittest.TestCase):
self.assertGreater(len(results), 40)
albums = self.yt_auth.get_library_upload_albums(None)
self.assertEqual(len(albums), 200)
self.assertGreaterEqual(len(albums), 200)
@unittest.skip("Must not have any uploaded albums to pass")
def test_get_library_upload_albums_empty(self):

View file

@ -67,6 +67,9 @@ class LibraryMixin:
request_func = lambda additionalParams: self._send_request(endpoint, body)
parse_func = lambda raw_response: parse_library_songs(raw_response)
if validate_responses and limit is None:
raise Exception("Validation is not supported without a limit parameter.")
if validate_responses:
validate_func = lambda parsed: validate_response(parsed, per_page, limit, 0)
response = resend_request_until_parsed_response_is_valid(request_func, None,
@ -89,8 +92,9 @@ class LibraryMixin:
request_continuations_func,
parse_continuations_func))
else:
remaining_limit = None if limit is None else (limit - len(songs))
songs.extend(
get_continuations(results, 'musicShelfContinuation', limit - len(songs),
get_continuations(results, 'musicShelfContinuation', remaining_limit,
request_continuations_func, parse_continuations_func))
return songs