edit_playlist: add addToTop function parameter (closes #444)

toggles a playlist from default behaviour (add to bottom) to "add to top"
This commit is contained in:
sigma67 2023-09-27 21:36:32 +02:00
commit 0acef5ddd9
No known key found for this signature in database
GPG key ID: 1C314227DF0103D0
2 changed files with 18 additions and 8 deletions

View file

@ -83,14 +83,14 @@ class TestYTMusic(unittest.TestCase):
query = "edm playlist"
self.assertRaises(Exception, self.yt_auth.search, query, filter="song")
self.assertRaises(Exception, self.yt_auth.search, query, scope="upload")
queries = ["Maylssi", "qllwlwl", "heun"]
queries = ["Monekes", "qllwlwl", "heun"]
for q in queries:
with self.subTest():
results = self.yt_brand.search(q)
self.assertListEqual(["resultType" in r for r in results], [True] * len(results))
self.assertGreater(len(results), 10)
self.assertGreaterEqual(len(results), 10)
results = self.yt.search(q)
self.assertGreater(len(results), 10)
self.assertGreaterEqual(len(results), 10)
results = self.yt_auth.search("Martin Stig Andersen - Deteriation", ignore_spelling=True)
self.assertGreater(len(results), 0)
@ -413,7 +413,9 @@ class TestYTMusic(unittest.TestCase):
def test_get_playlist_foreign(self):
self.assertRaises(Exception, self.yt.get_playlist, "PLABC")
playlist = self.yt.get_playlist("PLPK7133-0ahmzknIfvNUMNJglX-O1rTd2", limit=300, suggestions_limit=7)
playlist = self.yt.get_playlist("PLk5BdzXBUiUe8Q5I13ZSCD8HbxMqJUUQA",
limit=300,
suggestions_limit=7)
self.assertGreater(len(playlist['duration']), 5)
self.assertGreater(len(playlist["tracks"]), 200)
self.assertNotIn("suggestions", playlist)
@ -468,6 +470,7 @@ class TestYTMusic(unittest.TestCase):
source_playlist="OLAK5uy_lGQfnMNGvYCRdDq9ZLzJV2BJL2aHQsz9Y",
)
self.assertEqual(len(playlistId), 34, "Playlist creation failed")
self.yt_brand.edit_playlist(playlistId, addToTop=True)
response = self.yt_brand.add_playlist_items(
playlistId,
[sample_video, sample_video],

View file

@ -139,7 +139,8 @@ class PlaylistsMixin:
has_views = (len(second_subtitle_runs) > 3) * 2
playlist['views'] = None if not has_views else to_int(second_subtitle_runs[0]['text'])
has_duration = (len(second_subtitle_runs) > 1) * 2
playlist['duration'] = None if not has_duration else second_subtitle_runs[has_views + has_duration]['text']
playlist['duration'] = None if not has_duration else second_subtitle_runs[
has_views + has_duration]['text']
song_count = second_subtitle_runs[has_views + 0]['text'].split(" ")
song_count = to_int(song_count[0]) if len(song_count) > 1 else 0
else:
@ -147,7 +148,8 @@ class PlaylistsMixin:
playlist['trackCount'] = song_count
request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams)
request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams
)
# suggestions and related are missing e.g. on liked songs
section_list = nav(response, SINGLE_COLUMN_TAB + ['sectionListRenderer'])
@ -230,7 +232,8 @@ class PlaylistsMixin:
description: str = None,
privacyStatus: str = None,
moveItem: Tuple[str, str] = None,
addPlaylistId: str = None) -> Union[str, Dict]:
addPlaylistId: str = None,
addToTop: bool = False) -> Union[str, Dict]:
"""
Edit title, description or privacyStatus of a playlist.
You may also move an item within a playlist or append another playlist to this playlist.
@ -241,7 +244,8 @@ class PlaylistsMixin:
:param privacyStatus: Optional. New privacy status for the playlist
:param moveItem: Optional. Move one item before another. Items are specified by setVideoId, see :py:func:`get_playlist`
:param addPlaylistId: Optional. Id of another playlist to add to this playlist
:return: Status String or full response
:param addToTop: Optional. Change the state of this playlist to add items to the top of the playlist by default.
:return: Status String or full responwwwse
"""
self._check_auth()
body = {'playlistId': validate_playlist_id(playlistId)}
@ -271,6 +275,9 @@ class PlaylistsMixin:
if addPlaylistId:
actions.append({'action': 'ACTION_ADD_PLAYLIST', 'addedFullListId': addPlaylistId})
if addToTop:
actions.append({'action': 'ACTION_SET_ADD_TO_TOP', 'addToTop': 'true'})
body['actions'] = actions
endpoint = 'browse/edit_playlist'
response = self._send_request(endpoint, body)