diff --git a/platypush/plugins/media/ctrl.py b/platypush/plugins/media/ctrl.py index ea017f90..fbf8350f 100644 --- a/platypush/plugins/media/ctrl.py +++ b/platypush/plugins/media/ctrl.py @@ -1,10 +1,6 @@ import re import subprocess -import urllib.request -import urllib.parse - -from bs4 import BeautifulSoup from omxplayer import OMXPlayer from platypush.context import get_plugin @@ -76,7 +72,10 @@ class MediaCtrlPlugin(Plugin): def stop(self): - if self.plugin: return self.plugin.stop() + if self.plugin: + ret = self.plugin.stop() + self.plugin = None + return ret def voldown(self): @@ -96,6 +95,12 @@ class MediaCtrlPlugin(Plugin): def next(self): + if self.plugin: return self.plugin.next() + + + def previous(self): + if self.plugin: return self.plugin.previous() + if self.plugin: self.plugin.stop() @@ -105,20 +110,5 @@ class MediaCtrlPlugin(Plugin): return Response(output={'status': 'no media'}, errors = []) - def youtube_search_and_play(self, query): - query = urllib.parse.quote(query) - url = "https://www.youtube.com/results?search_query=" + query - response = urllib.request.urlopen(url) - html = response.read() - soup = BeautifulSoup(html, 'lxml') - self.videos_queue = [] - - for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}): - if vid['href'].startswith('/watch?v='): - self.videos_queue.append('https://www.youtube.com' + vid['href']) - - url = self.videos_queue.pop(0) - return self.play(url) - # vim:sw=4:ts=4:et: diff --git a/platypush/plugins/video/omxplayer.py b/platypush/plugins/video/omxplayer.py index 14417d4c..f9b77bf5 100644 --- a/platypush/plugins/video/omxplayer.py +++ b/platypush/plugins/video/omxplayer.py @@ -3,6 +3,10 @@ import logging import re import subprocess +import urllib.request +import urllib.parse + +from bs4 import BeautifulSoup from dbus.exceptions import DBusException from omxplayer import OMXPlayer @@ -59,6 +63,16 @@ class VideoOmxplayerPlugin(Plugin): self.player.seek(+30) return self.status() + def next(self): + if self.player: + self.player.stop() + + if self.videos_queue: + return self.play(self.videos_queue.pop(0)) + + return Response(output={'status': 'no media'}, errors = []) + + def status(self): if self.player: return Response(output=json.dumps({ @@ -72,6 +86,21 @@ class VideoOmxplayerPlugin(Plugin): 'status': 'Not initialized' })) + def youtube_search_and_play(self, query): + query = urllib.parse.quote(query) + url = "https://www.youtube.com/results?search_query=" + query + response = urllib.request.urlopen(url) + html = response.read() + soup = BeautifulSoup(html, 'lxml') + self.videos_queue = [] + + for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}): + if vid['href'].startswith('/watch?v='): + self.videos_queue.append('https://www.youtube.com' + vid['href']) + + url = self.videos_queue.pop(0) + return self.play(url) + @classmethod def _get_youtube_content(cls, url): m = re.match('youtube:video:(.*)', url)