Implemented file search method in OMXPlayer plugin
This commit is contained in:
parent
e5e1270380
commit
77da94769e
1 changed files with 49 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
@ -19,8 +20,25 @@ from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \
|
||||||
from .. import Plugin
|
from .. import Plugin
|
||||||
|
|
||||||
class VideoOmxplayerPlugin(Plugin):
|
class VideoOmxplayerPlugin(Plugin):
|
||||||
def __init__(self, args=[], *argv, **kwargs):
|
video_extensions = {
|
||||||
|
'.avi', '.flv', '.wmv', '.mov', '.mp4', '.m4v', '.mpg', '.mpeg',
|
||||||
|
'.rm', '.swf', '.vob'
|
||||||
|
}
|
||||||
|
|
||||||
|
def __init__(self, args=[], media_dirs=[], *argv, **kwargs):
|
||||||
|
super().__init__(argv, kwargs)
|
||||||
|
|
||||||
self.args = args
|
self.args = args
|
||||||
|
self.media_dirs = list(
|
||||||
|
filter(
|
||||||
|
lambda _: os.path.isdir(_),
|
||||||
|
map(
|
||||||
|
lambda _: os.path.abspath(os.path.expanduser(_)),
|
||||||
|
media_dirs
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
self.player = None
|
self.player = None
|
||||||
self.videos_queue = []
|
self.videos_queue = []
|
||||||
|
|
||||||
|
@ -198,6 +216,36 @@ class VideoOmxplayerPlugin(Plugin):
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def file_search(self, query):
|
||||||
|
results = []
|
||||||
|
query_tokens = [_.lower() for _ in re.split('\s+', query.trim())]
|
||||||
|
|
||||||
|
for media_dir in self.media_dirs:
|
||||||
|
logging.info('Scanning {} for "{}"'.format(media_dir, query))
|
||||||
|
for path, dirs, files in os.walk(media_dir):
|
||||||
|
for f in files:
|
||||||
|
is_video = False
|
||||||
|
for ext in self.video_extensions:
|
||||||
|
if f.lower().endswith(ext):
|
||||||
|
is_video = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if not is_video:
|
||||||
|
continue
|
||||||
|
|
||||||
|
matches_query = True
|
||||||
|
for token in query_tokens:
|
||||||
|
if token not in f.lower():
|
||||||
|
matches_query = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if not matches_query:
|
||||||
|
continue
|
||||||
|
|
||||||
|
results.append(path + os.sep + f)
|
||||||
|
|
||||||
|
return Response(output=results)
|
||||||
|
|
||||||
def youtube_search(self, query):
|
def youtube_search(self, query):
|
||||||
query = urllib.parse.quote(query)
|
query = urllib.parse.quote(query)
|
||||||
url = "https://www.youtube.com/results?search_query=" + query
|
url = "https://www.youtube.com/results?search_query=" + query
|
||||||
|
|
Loading…
Reference in a new issue