youtube_search_and_play moved back to video.omxplayer

This commit is contained in:
Fabio Manganiello 2018-04-19 00:30:39 +02:00
parent a58fa23173
commit 12295f2f77
2 changed files with 39 additions and 20 deletions

View file

@ -1,10 +1,6 @@
import re import re
import subprocess import subprocess
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
from omxplayer import OMXPlayer from omxplayer import OMXPlayer
from platypush.context import get_plugin from platypush.context import get_plugin
@ -76,7 +72,10 @@ class MediaCtrlPlugin(Plugin):
def stop(self): 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): def voldown(self):
@ -96,6 +95,12 @@ class MediaCtrlPlugin(Plugin):
def next(self): def next(self):
if self.plugin: return self.plugin.next()
def previous(self):
if self.plugin: return self.plugin.previous()
if self.plugin: if self.plugin:
self.plugin.stop() self.plugin.stop()
@ -105,20 +110,5 @@ class MediaCtrlPlugin(Plugin):
return Response(output={'status': 'no media'}, errors = []) 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: # vim:sw=4:ts=4:et:

View file

@ -3,6 +3,10 @@ import logging
import re import re
import subprocess import subprocess
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
from dbus.exceptions import DBusException from dbus.exceptions import DBusException
from omxplayer import OMXPlayer from omxplayer import OMXPlayer
@ -59,6 +63,16 @@ class VideoOmxplayerPlugin(Plugin):
self.player.seek(+30) self.player.seek(+30)
return self.status() 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): def status(self):
if self.player: if self.player:
return Response(output=json.dumps({ return Response(output=json.dumps({
@ -72,6 +86,21 @@ class VideoOmxplayerPlugin(Plugin):
'status': 'Not initialized' '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 @classmethod
def _get_youtube_content(cls, url): def _get_youtube_content(cls, url):
m = re.match('youtube:video:(.*)', url) m = re.match('youtube:video:(.*)', url)