diff --git a/Command/Command.py b/Command/Command.py index 480751b..2fd65e0 100644 --- a/Command/Command.py +++ b/Command/Command.py @@ -9,7 +9,6 @@ # must return dict like {'cmd': cmd, 'params': params} # this - object (class instance) pointer (self) # abstract this.start() - required method for all commands -# abstract this.confirm() - Return True/False (User responce) # this.keywords - dictionary of arrays keywords # like { # (int)weight : ['word1', 'word2', 'word3'], @@ -119,9 +118,6 @@ class Command(ABC): def setStart(this, function): # define start (required) this.start = function - def setConfirm(this, function): # define confirm (optional) - this.confirm = function - ###################################################################################### # GETTERS # ###################################################################################### @@ -144,10 +140,6 @@ class Command(ABC): def start(this, params): # main method pass - @abstractmethod - def confirm(this): # optional method - pass - ###################################################################################### # STATIC METHODS # ###################################################################################### diff --git a/Media/__init__.py b/Media/__init__.py new file mode 100644 index 0000000..e5cef84 --- /dev/null +++ b/Media/__init__.py @@ -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) diff --git a/Media/film.py b/Media/film.py new file mode 100644 index 0000000..e32b9a6 --- /dev/null +++ b/Media/film.py @@ -0,0 +1,5 @@ +from Command import Command + +class film(Command): + def start(this, string): # main method + pass diff --git a/QA/QA.py b/QA/QA.py index cec3dcd..7083941 100644 --- a/QA/QA.py +++ b/QA/QA.py @@ -7,8 +7,6 @@ import json import re class QA(Command): - def confirm(this, string): return True - def googleDictionary(this, word): responce = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/ru/{word}') if responce.status_code == 200: diff --git a/SmallTalk/SmallTalk.py b/SmallTalk/SmallTalk.py index a6ca292..147ed35 100644 --- a/SmallTalk/SmallTalk.py +++ b/SmallTalk/SmallTalk.py @@ -10,6 +10,3 @@ from Command import Command # import parent class class SmallTalk(Command): def start(this, string): # main method print(f'Hello, {string=}') - - def confirm(this): # optional method - return True diff --git a/api_server.py b/api_server.py new file mode 100644 index 0000000..e69de29 diff --git a/control_panel.py b/control_panel.py new file mode 100644 index 0000000..e69de29 diff --git a/voice_assistant.py b/voice_assistant.py index 022ebca..5aff301 100644 --- a/voice_assistant.py +++ b/voice_assistant.py @@ -1,6 +1,7 @@ import SpeechRecognition import Text2Speech import SmallTalk +import Media from Command import Command import config import QA @@ -44,8 +45,12 @@ while True: # main loop if Command.isRepeat(text): reply(memory[0]['responce']); continue - try: cmd, params = memory[0]['cmd'].checkContext(text).values(); params = {**memory[0]['params'], **params} - except: cmd, params = Command.reg_find(text).values() + try: + 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) reply(responce) memory.insert(0, {