You've already forked STARK
mirror of
https://github.com/MarkParker5/STARK.git
synced 2025-07-12 22:50:22 +02:00
play films with kweb for rpi
This commit is contained in:
@ -9,7 +9,6 @@
|
|||||||
# must return dict like {'cmd': cmd, 'params': params}
|
# must return dict like {'cmd': cmd, 'params': params}
|
||||||
# this - object (class instance) pointer (self)
|
# this - object (class instance) pointer (self)
|
||||||
# abstract this.start() - required method for all commands
|
# abstract this.start() - required method for all commands
|
||||||
# abstract this.confirm() - Return True/False (User responce)
|
|
||||||
# this.keywords - dictionary of arrays keywords
|
# this.keywords - dictionary of arrays keywords
|
||||||
# like {
|
# like {
|
||||||
# (int)weight : ['word1', 'word2', 'word3'],
|
# (int)weight : ['word1', 'word2', 'word3'],
|
||||||
@ -119,9 +118,6 @@ class Command(ABC):
|
|||||||
def setStart(this, function): # define start (required)
|
def setStart(this, function): # define start (required)
|
||||||
this.start = function
|
this.start = function
|
||||||
|
|
||||||
def setConfirm(this, function): # define confirm (optional)
|
|
||||||
this.confirm = function
|
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
# GETTERS #
|
# GETTERS #
|
||||||
######################################################################################
|
######################################################################################
|
||||||
@ -144,10 +140,6 @@ class Command(ABC):
|
|||||||
def start(this, params): # main method
|
def start(this, params): # main method
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def confirm(this): # optional method
|
|
||||||
pass
|
|
||||||
|
|
||||||
######################################################################################
|
######################################################################################
|
||||||
# STATIC METHODS #
|
# STATIC METHODS #
|
||||||
######################################################################################
|
######################################################################################
|
||||||
|
47
Media/__init__.py
Normal file
47
Media/__init__.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
from .film import *
|
||||||
|
import requests
|
||||||
|
from bs4 import BeautifulSoup as BS
|
||||||
|
import webbrowser
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
def method(params):
|
||||||
|
def findFilm(name):
|
||||||
|
query = name + ' site:kinogo.by'
|
||||||
|
responce = requests.get(f'https://www.google.ru/search?&q={query}&lr=lang_ru&lang=ru')
|
||||||
|
page = BS(responce.content, 'html.parser')
|
||||||
|
link = page.select_one('.ZINbbc.xpd.O9g5cc.uUPGi>.kCrYT>a')
|
||||||
|
return link['href'][7:].split('&')[0] if link else None
|
||||||
|
|
||||||
|
def extractUrl(url):
|
||||||
|
responce = requests.get(url)
|
||||||
|
page = BS(responce.content, 'html.parser')
|
||||||
|
url = page.select_one('div[style="padding:22px; float:left; margin-left: 30px;"]>a[download]:last-child')
|
||||||
|
return url['href'] if url else None
|
||||||
|
|
||||||
|
def finalUrl(url):
|
||||||
|
return "http://localhost:9192/play?url="+url
|
||||||
|
|
||||||
|
def start(url):
|
||||||
|
webbrowser.open(url)
|
||||||
|
|
||||||
|
name = params.get('text')
|
||||||
|
print(name)
|
||||||
|
if name:
|
||||||
|
if url:= extractUrl(findFilm(name)):
|
||||||
|
voice = text = 'Включаю'
|
||||||
|
start(finalUrl(url))
|
||||||
|
else:
|
||||||
|
voice = text = 'Не могу найти фильм'
|
||||||
|
else:
|
||||||
|
voice = text = 'Какой фильм включить?'
|
||||||
|
|
||||||
|
return {
|
||||||
|
'type': 'simple',
|
||||||
|
'text': text,
|
||||||
|
'voice': voice,
|
||||||
|
}
|
||||||
|
|
||||||
|
patterns = ['* включ* фильм $text', '* включ* фильм*']
|
||||||
|
subpatterns = ['$text',]
|
||||||
|
kinogo = film('KinogoPlayer', {}, patterns, subpatterns)
|
||||||
|
kinogo.setStart(method)
|
5
Media/film.py
Normal file
5
Media/film.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
from Command import Command
|
||||||
|
|
||||||
|
class film(Command):
|
||||||
|
def start(this, string): # main method
|
||||||
|
pass
|
2
QA/QA.py
2
QA/QA.py
@ -7,8 +7,6 @@ import json
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
class QA(Command):
|
class QA(Command):
|
||||||
def confirm(this, string): return True
|
|
||||||
|
|
||||||
def googleDictionary(this, word):
|
def googleDictionary(this, word):
|
||||||
responce = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/ru/{word}')
|
responce = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/ru/{word}')
|
||||||
if responce.status_code == 200:
|
if responce.status_code == 200:
|
||||||
|
@ -10,6 +10,3 @@ from Command import Command # import parent class
|
|||||||
class SmallTalk(Command):
|
class SmallTalk(Command):
|
||||||
def start(this, string): # main method
|
def start(this, string): # main method
|
||||||
print(f'Hello, {string=}')
|
print(f'Hello, {string=}')
|
||||||
|
|
||||||
def confirm(this): # optional method
|
|
||||||
return True
|
|
||||||
|
0
api_server.py
Normal file
0
api_server.py
Normal file
0
control_panel.py
Normal file
0
control_panel.py
Normal file
@ -1,6 +1,7 @@
|
|||||||
import SpeechRecognition
|
import SpeechRecognition
|
||||||
import Text2Speech
|
import Text2Speech
|
||||||
import SmallTalk
|
import SmallTalk
|
||||||
|
import Media
|
||||||
from Command import Command
|
from Command import Command
|
||||||
import config
|
import config
|
||||||
import QA
|
import QA
|
||||||
@ -44,8 +45,12 @@ while True: # main loop
|
|||||||
if Command.isRepeat(text):
|
if Command.isRepeat(text):
|
||||||
reply(memory[0]['responce']);
|
reply(memory[0]['responce']);
|
||||||
continue
|
continue
|
||||||
try: cmd, params = memory[0]['cmd'].checkContext(text).values(); params = {**memory[0]['params'], **params}
|
try:
|
||||||
except: cmd, params = Command.reg_find(text).values()
|
cmd, params = memory[0]['cmd'].checkContext(text).values()
|
||||||
|
if memory[0].get('params'):
|
||||||
|
params = {**memory[0].get('params'), **params}
|
||||||
|
except:
|
||||||
|
cmd, params = Command.reg_find(text).values()
|
||||||
responce = cmd.start(params)
|
responce = cmd.start(params)
|
||||||
reply(responce)
|
reply(responce)
|
||||||
memory.insert(0, {
|
memory.insert(0, {
|
||||||
|
Reference in New Issue
Block a user