Feature: create_playlist supports video_ids and source_playlist parameters
This commit is contained in:
parent
14eb04e273
commit
bcffaca1b9
2 changed files with 17 additions and 4 deletions
|
|
@ -3,7 +3,7 @@ import configparser
|
||||||
from ytmusicapi.ytmusic import YTMusic
|
from ytmusicapi.ytmusic import YTMusic
|
||||||
|
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.read('./test.cfg')
|
config.read('./test.cfg', 'utf-8')
|
||||||
|
|
||||||
youtube = YTMusic()
|
youtube = YTMusic()
|
||||||
youtube_auth = YTMusic(config['auth']['headers_file'])
|
youtube_auth = YTMusic(config['auth']['headers_file'])
|
||||||
|
|
@ -126,12 +126,15 @@ class TestYTMusic(unittest.TestCase):
|
||||||
|
|
||||||
# end to end test adding playlist, adding item, deleting item, deleting playlist
|
# end to end test adding playlist, adding item, deleting item, deleting playlist
|
||||||
def test_end2end(self):
|
def test_end2end(self):
|
||||||
playlistId = youtube_auth.create_playlist("test", "test description")
|
playlistId = youtube_auth.create_playlist(
|
||||||
|
"test",
|
||||||
|
"test description",
|
||||||
|
source_playlist="OLAK5uy_lGQfnMNGvYCRdDq9ZLzJV2BJL2aHQsz9Y")
|
||||||
self.assertEqual(len(playlistId), 34, "Playlist creation failed")
|
self.assertEqual(len(playlistId), 34, "Playlist creation failed")
|
||||||
response = youtube_auth.add_playlist_items(playlistId, ['y0Hhvtmv0gk'])
|
response = youtube_auth.add_playlist_items(playlistId, ['y0Hhvtmv0gk'])
|
||||||
self.assertEqual(response, 'STATUS_SUCCEEDED', "Adding playlist item failed")
|
self.assertEqual(response, 'STATUS_SUCCEEDED', "Adding playlist item failed")
|
||||||
playlist = youtube_auth.get_playlist(playlistId)
|
playlist = youtube_auth.get_playlist(playlistId)
|
||||||
self.assertEqual(len(playlist['tracks']), 1, "Getting playlist items failed")
|
self.assertEqual(len(playlist['tracks']), 41, "Getting playlist items failed")
|
||||||
response = youtube_auth.remove_playlist_items(playlistId, playlist['tracks'])
|
response = youtube_auth.remove_playlist_items(playlistId, playlist['tracks'])
|
||||||
self.assertEqual(response, 'STATUS_SUCCEEDED', "Playlist item removal failed")
|
self.assertEqual(response, 'STATUS_SUCCEEDED', "Playlist item removal failed")
|
||||||
response = youtube_auth.delete_playlist(playlistId)
|
response = youtube_auth.delete_playlist(playlistId)
|
||||||
|
|
|
||||||
|
|
@ -752,13 +752,17 @@ class YTMusic:
|
||||||
def create_playlist(self,
|
def create_playlist(self,
|
||||||
title: str,
|
title: str,
|
||||||
description: str,
|
description: str,
|
||||||
privacy_status: str = "PRIVATE") -> str:
|
privacy_status: str = "PRIVATE",
|
||||||
|
video_ids: List = None,
|
||||||
|
source_playlist: str = None) -> str:
|
||||||
"""
|
"""
|
||||||
Creates a new empty playlist and returns its id.
|
Creates a new empty playlist and returns its id.
|
||||||
|
|
||||||
:param title: Playlist title
|
:param title: Playlist title
|
||||||
:param description: Playlist description
|
:param description: Playlist description
|
||||||
:param privacy_status: Playlists can be 'PUBLIC', 'PRIVATE', or 'UNLISTED'. Default: 'PRIVATE'
|
:param privacy_status: Playlists can be 'PUBLIC', 'PRIVATE', or 'UNLISTED'. Default: 'PRIVATE'
|
||||||
|
:param video_ids: IDs of songs to create the playlist with
|
||||||
|
:param source_playlist: Another playlist whose songs should be added to the new playlist
|
||||||
:return: ID of the YouTube playlist
|
:return: ID of the YouTube playlist
|
||||||
"""
|
"""
|
||||||
self.__check_auth()
|
self.__check_auth()
|
||||||
|
|
@ -767,6 +771,12 @@ class YTMusic:
|
||||||
'description': html_to_txt(description), # YT does not allow HTML tags
|
'description': html_to_txt(description), # YT does not allow HTML tags
|
||||||
'privacyStatus': privacy_status
|
'privacyStatus': privacy_status
|
||||||
}
|
}
|
||||||
|
if video_ids is not None:
|
||||||
|
body['videoIds'] = video_ids
|
||||||
|
|
||||||
|
if source_playlist is not None:
|
||||||
|
body['sourcePlaylistId'] = source_playlist
|
||||||
|
|
||||||
endpoint = 'playlist/create'
|
endpoint = 'playlist/create'
|
||||||
response = self.__send_request(endpoint, body)
|
response = self.__send_request(endpoint, body)
|
||||||
return response['playlistId']
|
return response['playlistId']
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue