get_library_*: fix for next YouTube update (#301)
This commit is contained in:
parent
d36a01077d
commit
1cac82be21
4 changed files with 29 additions and 47 deletions
|
|
@ -231,20 +231,12 @@ class TestYTMusic(unittest.TestCase):
|
||||||
playlists = self.yt_auth.get_library_playlists(50)
|
playlists = self.yt_auth.get_library_playlists(50)
|
||||||
self.assertGreater(len(playlists), 25)
|
self.assertGreater(len(playlists), 25)
|
||||||
|
|
||||||
def test_get_all_library_playlists(self):
|
|
||||||
current_length = len(self.yt_auth.get_library_playlists(25))
|
|
||||||
expected_length = current_length
|
|
||||||
while expected_length <= current_length:
|
|
||||||
expected_length = current_length + 1
|
|
||||||
current_length = len(self.yt_auth.get_library_playlists(expected_length))
|
|
||||||
expected_length -= 1
|
|
||||||
|
|
||||||
playlists = self.yt_auth.get_library_playlists(None)
|
playlists = self.yt_auth.get_library_playlists(None)
|
||||||
self.assertEqual(len(playlists), expected_length)
|
self.assertGreaterEqual(len(playlists), config.getint('limits', 'library_playlists'))
|
||||||
|
|
||||||
def test_get_library_songs(self):
|
def test_get_library_songs(self):
|
||||||
self.assertRaises(Exception, self.yt_auth.get_library_songs, None, True)
|
self.assertRaises(Exception, self.yt_auth.get_library_songs, None, True)
|
||||||
songs = self.yt_brand.get_library_songs(100)
|
songs = self.yt_auth.get_library_songs(100)
|
||||||
self.assertGreaterEqual(len(songs), 100)
|
self.assertGreaterEqual(len(songs), 100)
|
||||||
songs = self.yt_auth.get_library_songs(200, validate_responses=True)
|
songs = self.yt_auth.get_library_songs(200, validate_responses=True)
|
||||||
self.assertGreaterEqual(len(songs), config.getint('limits', 'library_songs'))
|
self.assertGreaterEqual(len(songs), config.getint('limits', 'library_songs'))
|
||||||
|
|
@ -262,7 +254,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreater(len(albums), 50)
|
self.assertGreater(len(albums), 50)
|
||||||
|
|
||||||
def test_get_library_artists(self):
|
def test_get_library_artists(self):
|
||||||
artists = self.yt_brand.get_library_artists(50)
|
artists = self.yt_auth.get_library_artists(50)
|
||||||
self.assertGreater(len(artists), 40)
|
self.assertGreater(len(artists), 40)
|
||||||
artists = self.yt_brand.get_library_artists(order='a_to_z', limit=50)
|
artists = self.yt_brand.get_library_artists(order='a_to_z', limit=50)
|
||||||
self.assertGreater(len(artists), 40)
|
self.assertGreater(len(artists), 40)
|
||||||
|
|
@ -392,7 +384,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
@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):
|
||||||
results = self.yt_auth.get_library_upload_songs(100)
|
results = self.yt_auth.get_library_upload_songs(100)
|
||||||
self.assertEquals(len(results), 0)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_get_library_upload_albums(self):
|
def test_get_library_upload_albums(self):
|
||||||
results = self.yt_auth.get_library_upload_albums(50, order='a_to_z')
|
results = self.yt_auth.get_library_upload_albums(50, order='a_to_z')
|
||||||
|
|
@ -404,7 +396,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
@unittest.skip("Must not have any uploaded albums to pass")
|
@unittest.skip("Must not have any uploaded albums to pass")
|
||||||
def test_get_library_upload_albums_empty(self):
|
def test_get_library_upload_albums_empty(self):
|
||||||
results = self.yt_auth.get_library_upload_albums(100)
|
results = self.yt_auth.get_library_upload_albums(100)
|
||||||
self.assertEquals(len(results), 0)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_get_library_upload_artists(self):
|
def test_get_library_upload_artists(self):
|
||||||
artists = self.yt_auth.get_library_upload_artists(None)
|
artists = self.yt_auth.get_library_upload_artists(None)
|
||||||
|
|
@ -416,7 +408,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
@unittest.skip("Must not have any uploaded artsts to pass")
|
@unittest.skip("Must not have any uploaded artsts to pass")
|
||||||
def test_get_library_upload_artists_empty(self):
|
def test_get_library_upload_artists_empty(self):
|
||||||
results = self.yt_auth.get_library_upload_artists(100)
|
results = self.yt_auth.get_library_upload_artists(100)
|
||||||
self.assertEquals(len(results), 0)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_upload_song(self):
|
def test_upload_song(self):
|
||||||
self.assertRaises(Exception, self.yt_auth.upload_song, 'song.wav')
|
self.assertRaises(Exception, self.yt_auth.upload_song, 'song.wav')
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,7 @@ class LibraryMixin:
|
||||||
endpoint = 'browse'
|
endpoint = 'browse'
|
||||||
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 = get_library_contents(response, GRID)
|
||||||
'itemSectionRenderer')
|
|
||||||
results = nav(results, ITEM_SECTION + GRID)
|
|
||||||
playlists = parse_content_list(results['items'][1:], parse_playlist)
|
playlists = parse_content_list(results['items'][1:], parse_playlist)
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from ._utils import validate_order_parameter, prepare_order_params
|
||||||
from ytmusicapi.helpers import *
|
from ytmusicapi.helpers import *
|
||||||
from ytmusicapi.navigation import *
|
from ytmusicapi.navigation import *
|
||||||
from ytmusicapi.continuations import get_continuations
|
from ytmusicapi.continuations import get_continuations
|
||||||
from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists
|
from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists, get_library_contents
|
||||||
from ytmusicapi.parsers.albums import parse_album_header
|
from ytmusicapi.parsers.albums import parse_album_header
|
||||||
from ytmusicapi.parsers.uploads import parse_uploaded_items
|
from ytmusicapi.parsers.uploads import parse_uploaded_items
|
||||||
|
|
||||||
|
|
@ -43,17 +43,10 @@ class UploadsMixin:
|
||||||
if order is not None:
|
if order is not None:
|
||||||
body["params"] = prepare_order_params(order)
|
body["params"] = prepare_order_params(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 = get_library_contents(response, MUSIC_SHELF)
|
||||||
'itemSectionRenderer')
|
if results is None:
|
||||||
results = nav(results, ITEM_SECTION)
|
|
||||||
if 'musicShelfRenderer' not in results:
|
|
||||||
return []
|
return []
|
||||||
else:
|
songs = parse_uploaded_items(results['contents'][1:])
|
||||||
results = results['musicShelfRenderer']
|
|
||||||
|
|
||||||
songs = []
|
|
||||||
|
|
||||||
songs.extend(parse_uploaded_items(results['contents'][1:]))
|
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
request_func = lambda additionalParams: self._send_request(
|
request_func = lambda additionalParams: self._send_request(
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,9 @@ def parse_artists(results, uploaded=False):
|
||||||
|
|
||||||
|
|
||||||
def parse_library_albums(response, request_func, limit):
|
def parse_library_albums(response, request_func, limit):
|
||||||
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
|
results = get_library_contents(response, GRID)
|
||||||
'itemSectionRenderer')
|
if results is None:
|
||||||
results = nav(results, ITEM_SECTION)
|
|
||||||
if 'gridRenderer' not in results:
|
|
||||||
return []
|
return []
|
||||||
results = nav(results, GRID)
|
|
||||||
albums = parse_albums(results['items'])
|
albums = parse_albums(results['items'])
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
|
|
@ -83,12 +80,9 @@ def parse_albums(results):
|
||||||
|
|
||||||
|
|
||||||
def parse_library_artists(response, request_func, limit):
|
def parse_library_artists(response, request_func, limit):
|
||||||
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
|
results = get_library_contents(response, MUSIC_SHELF)
|
||||||
'itemSectionRenderer')
|
if results is None:
|
||||||
results = nav(results, ITEM_SECTION)
|
|
||||||
if 'musicShelfRenderer' not in results:
|
|
||||||
return []
|
return []
|
||||||
results = results['musicShelfRenderer']
|
|
||||||
artists = parse_artists(results['contents'])
|
artists = parse_artists(results['contents'])
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
|
|
@ -102,12 +96,17 @@ def parse_library_artists(response, request_func, limit):
|
||||||
|
|
||||||
|
|
||||||
def parse_library_songs(response):
|
def parse_library_songs(response):
|
||||||
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
|
results = get_library_contents(response, MUSIC_SHELF)
|
||||||
'itemSectionRenderer')
|
return {'results': results, 'parsed': (parse_playlist_items(results['contents'][1:]))}
|
||||||
results = nav(results, ITEM_SECTION)
|
|
||||||
songs = {'results': [], 'parsed': []}
|
|
||||||
if 'musicShelfRenderer' in results:
|
|
||||||
songs['results'] = results['musicShelfRenderer']
|
|
||||||
songs['parsed'] = parse_playlist_items(songs['results']['contents'][1:])
|
|
||||||
|
|
||||||
return songs
|
|
||||||
|
def get_library_contents(response, renderer):
|
||||||
|
# first 3 lines are original path prior to #301
|
||||||
|
contents = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST, True)
|
||||||
|
if contents is None: # empty library
|
||||||
|
return None
|
||||||
|
results = find_object_by_key(contents, 'itemSectionRenderer')
|
||||||
|
if results is None:
|
||||||
|
return nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + renderer, True)
|
||||||
|
else:
|
||||||
|
return nav(results, ITEM_SECTION + renderer)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue