get_library_songs, get_library_upload_songs: fix empty result for libraries containing exactly 1 song
This commit is contained in:
parent
43d3c3bc04
commit
8f7970b264
2 changed files with 13 additions and 3 deletions
|
|
@ -7,12 +7,14 @@ 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, get_library_contents
|
from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists, get_library_contents, \
|
||||||
|
pop_songs_random_mix
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
class UploadsMixin:
|
class UploadsMixin:
|
||||||
|
|
||||||
def get_library_upload_songs(self, limit: int = 25, order: str = None) -> 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
|
||||||
|
|
@ -44,9 +46,10 @@ class UploadsMixin:
|
||||||
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 = get_library_contents(response, MUSIC_SHELF)
|
results = get_library_contents(response, MUSIC_SHELF)
|
||||||
|
pop_songs_random_mix(results['contents'])
|
||||||
if results is None:
|
if results is None:
|
||||||
return []
|
return []
|
||||||
songs = parse_uploaded_items(results['contents'][1:])
|
songs = parse_uploaded_items(results['contents'])
|
||||||
|
|
||||||
if 'continuations' in results:
|
if 'continuations' in results:
|
||||||
request_func = lambda additionalParams: self._send_request(
|
request_func = lambda additionalParams: self._send_request(
|
||||||
|
|
|
||||||
|
|
@ -75,11 +75,18 @@ def parse_library_artists(response, request_func, limit):
|
||||||
return artists
|
return artists
|
||||||
|
|
||||||
|
|
||||||
|
def pop_songs_random_mix(results) -> None:
|
||||||
|
"""remove the random mix that conditionally appears at the start of library songs"""
|
||||||
|
if len(results) >= 2:
|
||||||
|
results.pop(0)
|
||||||
|
|
||||||
|
|
||||||
def parse_library_songs(response):
|
def parse_library_songs(response):
|
||||||
results = get_library_contents(response, MUSIC_SHELF)
|
results = get_library_contents(response, MUSIC_SHELF)
|
||||||
|
pop_songs_random_mix(results['contents'])
|
||||||
return {
|
return {
|
||||||
'results': results,
|
'results': results,
|
||||||
'parsed': parse_playlist_items(results['contents'][1:]) if results else results
|
'parsed': parse_playlist_items(results['contents']) if results else results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue