Added status action to MediaPlugin interface

This commit is contained in:
Fabio Manganiello 2020-02-17 18:12:40 +01:00
parent 9b2e4f9d0c
commit 8248b5353f
2 changed files with 11 additions and 25 deletions

View file

@ -8,8 +8,7 @@ import subprocess
import tempfile
import threading
import urllib.request
import urllib.parse
from platypush.plugins.media.search import YoutubeMediaSearcher
from platypush.config import Config
from platypush.context import get_plugin, get_backend
@ -274,6 +273,10 @@ class MediaPlugin(Plugin):
def set_volume(self, volume):
raise self._NOT_IMPLEMENTED_ERR
@action
def status(self):
raise self._NOT_IMPLEMENTED_ERR
@action
def search(self, query, types=None, queue_results=False, autoplay=False,
search_timeout=_default_search_timeout):
@ -447,29 +450,10 @@ class MediaPlugin(Plugin):
if item.get('id', {}).get('kind') == 'youtube#video'
]
def _youtube_search_html_parse(self, query):
query = urllib.parse.quote(query)
url = "https://www.youtube.com/results?search_query=" + query
response = urllib.request.urlopen(url)
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
@staticmethod
def _youtube_search_html_parse(query):
# noinspection PyProtectedMember
return YoutubeMediaSearcher()._youtube_search_html_parse(query)
def stream_youtube_to_fifo(self, url):
if self._youtube_proc:

View file

@ -3,8 +3,10 @@ import urllib.parse
import urllib.request
from platypush.context import get_plugin
# noinspection PyProtectedMember
from platypush.plugins.media.search import MediaSearcher
class YoutubeMediaSearcher(MediaSearcher):
def search(self, query, **kwargs):
"""