forked from platypush/platypush
[youtube] Changed remove_from_playlist
API.
To be compatible with the naming conventions of the other media plugins: - `video_id` -> `item_ids` - `index` -> `indices`
This commit is contained in:
parent
f47dbc842a
commit
459fe9427c
1 changed files with 50 additions and 33 deletions
|
@ -259,42 +259,59 @@ class YoutubePlugin(Plugin):
|
||||||
def remove_from_playlist(
|
def remove_from_playlist(
|
||||||
self,
|
self,
|
||||||
playlist_id: str,
|
playlist_id: str,
|
||||||
video_id: Optional[str] = None,
|
item_ids: Optional[Collection[str]] = None,
|
||||||
index: Optional[int] = None,
|
indices: Optional[Collection[int]] = None,
|
||||||
|
**kwargs,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Remove a video from a playlist.
|
Remove a video from a playlist.
|
||||||
|
|
||||||
Note that either the video ID or the index must be provided.
|
Note that either ``item_ids`` or ``indices`` must be provided.
|
||||||
|
|
||||||
:param video_id: YouTube video ID or URL.
|
:param item_ids: YouTube video IDs or URLs to remove from the playlist.
|
||||||
:param index: (0-based) index of the video in the playlist.
|
:param indices: (0-based) indices of the items in the playlist to remove.
|
||||||
:param playlist_id: Piped playlist ID.
|
:param playlist_id: Piped playlist ID.
|
||||||
"""
|
"""
|
||||||
assert video_id or index, 'Either the video ID or the index must be provided'
|
items = item_ids
|
||||||
|
if kwargs.get('video_id'):
|
||||||
|
self.logger.warning(
|
||||||
|
'The "video_id" parameter is deprecated. Use "item_ids" instead.'
|
||||||
|
)
|
||||||
|
items = [kwargs['video_id']]
|
||||||
|
|
||||||
if index is None:
|
if kwargs.get('index'):
|
||||||
assert video_id
|
self.logger.warning(
|
||||||
video_id = self._get_video_id(video_id)
|
'The "index" parameter is deprecated. Use "indices" instead.'
|
||||||
index = next(
|
)
|
||||||
(
|
indices = [kwargs['index']]
|
||||||
i
|
|
||||||
for i, v in enumerate(
|
assert items or indices, 'Either item_ids or indices must be provided'
|
||||||
self._request(f'playlists/{playlist_id}').get(
|
|
||||||
|
if not indices:
|
||||||
|
item_ids = {
|
||||||
|
video_id
|
||||||
|
for video_id in [
|
||||||
|
self._get_video_id(item_id) for item_id in (items or [])
|
||||||
|
]
|
||||||
|
if video_id
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist_items = self._request(f'playlists/{playlist_id}').get(
|
||||||
'relatedStreams', []
|
'relatedStreams', []
|
||||||
)
|
)
|
||||||
)
|
indices = [
|
||||||
if self._get_video_id(v.get('url')) == video_id
|
i
|
||||||
),
|
for i, v in enumerate(playlist_items)
|
||||||
None,
|
if self._get_video_id(v.get('url')) in item_ids
|
||||||
)
|
]
|
||||||
|
|
||||||
if index is None:
|
if not indices:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
'Video %s not found in the playlist %s', video_id, playlist_id
|
'Items not found in the playlist %s: %s', playlist_id, items or []
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
for index in indices:
|
||||||
self._request(
|
self._request(
|
||||||
'user/playlists/remove',
|
'user/playlists/remove',
|
||||||
method='post',
|
method='post',
|
||||||
|
|
Loading…
Reference in a new issue