forked from platypush/platypush
Added status action to MediaPlugin interface
This commit is contained in:
parent
9b2e4f9d0c
commit
8248b5353f
2 changed files with 11 additions and 25 deletions
|
@ -8,8 +8,7 @@ import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import urllib.request
|
from platypush.plugins.media.search import YoutubeMediaSearcher
|
||||||
import urllib.parse
|
|
||||||
|
|
||||||
from platypush.config import Config
|
from platypush.config import Config
|
||||||
from platypush.context import get_plugin, get_backend
|
from platypush.context import get_plugin, get_backend
|
||||||
|
@ -274,6 +273,10 @@ class MediaPlugin(Plugin):
|
||||||
def set_volume(self, volume):
|
def set_volume(self, volume):
|
||||||
raise self._NOT_IMPLEMENTED_ERR
|
raise self._NOT_IMPLEMENTED_ERR
|
||||||
|
|
||||||
|
@action
|
||||||
|
def status(self):
|
||||||
|
raise self._NOT_IMPLEMENTED_ERR
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def search(self, query, types=None, queue_results=False, autoplay=False,
|
def search(self, query, types=None, queue_results=False, autoplay=False,
|
||||||
search_timeout=_default_search_timeout):
|
search_timeout=_default_search_timeout):
|
||||||
|
@ -447,29 +450,10 @@ class MediaPlugin(Plugin):
|
||||||
if item.get('id', {}).get('kind') == 'youtube#video'
|
if item.get('id', {}).get('kind') == 'youtube#video'
|
||||||
]
|
]
|
||||||
|
|
||||||
def _youtube_search_html_parse(self, query):
|
@staticmethod
|
||||||
query = urllib.parse.quote(query)
|
def _youtube_search_html_parse(query):
|
||||||
url = "https://www.youtube.com/results?search_query=" + query
|
# noinspection PyProtectedMember
|
||||||
response = urllib.request.urlopen(url)
|
return YoutubeMediaSearcher()._youtube_search_html_parse(query)
|
||||||
html = response.read().decode('utf-8')
|
|
||||||
results = []
|
|
||||||
|
|
||||||
while html:
|
|
||||||
m = re.search('(<a href="(/watch\?v=.+?)".+?yt-uix-tile-link.+?title="(.+?)".+?>)', html)
|
|
||||||
if m:
|
|
||||||
results.append({
|
|
||||||
'url': 'https://www.youtube.com' + m.group(2),
|
|
||||||
'title': m.group(3)
|
|
||||||
})
|
|
||||||
|
|
||||||
html = html.split(m.group(1))[1]
|
|
||||||
else:
|
|
||||||
html = ''
|
|
||||||
|
|
||||||
self.logger.info('{} YouTube video results for the search query "{}"'
|
|
||||||
.format(len(results), query))
|
|
||||||
|
|
||||||
return results
|
|
||||||
|
|
||||||
def stream_youtube_to_fifo(self, url):
|
def stream_youtube_to_fifo(self, url):
|
||||||
if self._youtube_proc:
|
if self._youtube_proc:
|
||||||
|
|
|
@ -3,8 +3,10 @@ import urllib.parse
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
from platypush.context import get_plugin
|
from platypush.context import get_plugin
|
||||||
|
# noinspection PyProtectedMember
|
||||||
from platypush.plugins.media.search import MediaSearcher
|
from platypush.plugins.media.search import MediaSearcher
|
||||||
|
|
||||||
|
|
||||||
class YoutubeMediaSearcher(MediaSearcher):
|
class YoutubeMediaSearcher(MediaSearcher):
|
||||||
def search(self, query, **kwargs):
|
def search(self, query, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue