From 8248b5353f6cd9ad201da9796a02f483a17b05b2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 17 Feb 2020 18:12:40 +0100 Subject: [PATCH] Added status action to MediaPlugin interface --- platypush/plugins/media/__init__.py | 34 ++++++----------------- platypush/plugins/media/search/youtube.py | 2 ++ 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/platypush/plugins/media/__init__.py b/platypush/plugins/media/__init__.py index 8de8862bc9..eaa5f1fa10 100644 --- a/platypush/plugins/media/__init__.py +++ b/platypush/plugins/media/__init__.py @@ -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('()', 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: diff --git a/platypush/plugins/media/search/youtube.py b/platypush/plugins/media/search/youtube.py index 18c5f9d295..7fa8a6fbfb 100644 --- a/platypush/plugins/media/search/youtube.py +++ b/platypush/plugins/media/search/youtube.py @@ -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): """