forked from platypush/platypush
Merge branch 'master' into 391/improve-youtube-support
This commit is contained in:
commit
701623c99d
2 changed files with 23 additions and 9 deletions
|
@ -1,4 +1,5 @@
|
||||||
import base64
|
import base64
|
||||||
|
import re
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
|
@ -99,6 +100,14 @@ class YoutubePlugin(Plugin):
|
||||||
PipedChannelSchema().dump(self._request(f'channel/{id}')) or {} # type: ignore
|
PipedChannelSchema().dump(self._request(f'channel/{id}')) or {} # type: ignore
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_video_id(id_or_url: str) -> str:
|
||||||
|
m = re.search(r'/watch\?v=([^&]+)', id_or_url)
|
||||||
|
if m:
|
||||||
|
return m.group(1)
|
||||||
|
|
||||||
|
return id_or_url
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def search(self, query: str, **_) -> List[dict]:
|
def search(self, query: str, **_) -> List[dict]:
|
||||||
"""
|
"""
|
||||||
|
@ -215,10 +224,10 @@ class YoutubePlugin(Plugin):
|
||||||
:param playlist_id: Piped playlist ID.
|
:param playlist_id: Piped playlist ID.
|
||||||
"""
|
"""
|
||||||
self._request(
|
self._request(
|
||||||
'playlists/add',
|
'user/playlists/add',
|
||||||
method='post',
|
method='post',
|
||||||
json={
|
json={
|
||||||
'videoIds': [video_id],
|
'videoIds': [self._get_video_id(video_id)],
|
||||||
'playlistId': playlist_id,
|
'playlistId': playlist_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -235,13 +244,15 @@ class YoutubePlugin(Plugin):
|
||||||
|
|
||||||
Note that either the video ID or the index must be provided.
|
Note that either the video ID or the index must be provided.
|
||||||
|
|
||||||
:param video_id: YouTube video ID.
|
:param video_id: YouTube video ID or URL.
|
||||||
:param index: (0-based) index of the video in the playlist.
|
:param index: (0-based) index of the video in the playlist.
|
||||||
: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'
|
assert video_id or index, 'Either the video ID or the index must be provided'
|
||||||
|
|
||||||
if index is None:
|
if index is None:
|
||||||
|
assert video_id
|
||||||
|
video_id = self._get_video_id(video_id)
|
||||||
index = next(
|
index = next(
|
||||||
(
|
(
|
||||||
i
|
i
|
||||||
|
@ -250,7 +261,7 @@ class YoutubePlugin(Plugin):
|
||||||
'relatedStreams', []
|
'relatedStreams', []
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if v.get('id') == video_id
|
if self._get_video_id(v.get('url')) == video_id
|
||||||
),
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -262,7 +273,7 @@ class YoutubePlugin(Plugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._request(
|
self._request(
|
||||||
'playlists/remove',
|
'user/playlists/remove',
|
||||||
method='post',
|
method='post',
|
||||||
json={
|
json={
|
||||||
'index': index,
|
'index': index,
|
||||||
|
@ -278,8 +289,11 @@ class YoutubePlugin(Plugin):
|
||||||
:param name: Playlist name.
|
:param name: Playlist name.
|
||||||
:return: Playlist information.
|
:return: Playlist information.
|
||||||
"""
|
"""
|
||||||
|
name = name.strip()
|
||||||
|
assert name, 'Playlist name cannot be empty'
|
||||||
|
|
||||||
playlist_id = self._request(
|
playlist_id = self._request(
|
||||||
'playlists/create',
|
'user/playlists/create',
|
||||||
method='post',
|
method='post',
|
||||||
json={'name': name},
|
json={'name': name},
|
||||||
).get('playlistId')
|
).get('playlistId')
|
||||||
|
@ -312,7 +326,7 @@ class YoutubePlugin(Plugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
self._request(
|
self._request(
|
||||||
'playlists/rename',
|
'user/playlists/rename',
|
||||||
method='post',
|
method='post',
|
||||||
json={
|
json={
|
||||||
'playlistId': id,
|
'playlistId': id,
|
||||||
|
@ -328,7 +342,7 @@ class YoutubePlugin(Plugin):
|
||||||
:param id: Piped playlist ID.
|
:param id: Piped playlist ID.
|
||||||
"""
|
"""
|
||||||
self._request(
|
self._request(
|
||||||
'playlists/delete',
|
'user/playlists/delete',
|
||||||
method='post',
|
method='post',
|
||||||
json={'playlistId': id},
|
json={'playlistId': id},
|
||||||
)
|
)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -66,7 +66,7 @@ backend = pkg_files('platypush/backend')
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="platypush",
|
name="platypush",
|
||||||
version="1.1.0",
|
version="1.1.1",
|
||||||
author="Fabio Manganiello",
|
author="Fabio Manganiello",
|
||||||
author_email="fabio@manganiello.tech",
|
author_email="fabio@manganiello.tech",
|
||||||
description="Platypush service",
|
description="Platypush service",
|
||||||
|
|
Loading…
Reference in a new issue