1
0
mirror of https://github.com/MarkParker5/STARK.git synced 2024-11-29 08:22:03 +02:00
STARK/Media/kinogo.py

68 lines
2.0 KiB
Python
Raw Normal View History

from .Film import *
import requests
from bs4 import BeautifulSoup as BS
import os
import Command
################################################################################
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 startFilm(url):
print(url)
os.system(f'lxterminal --command="vlc {url} -f"')
def main(params):
name = params.get('text')
if name:
if url:= extractUrl(findFilm(name)):
startFilm(url)
voice = text = 'Включаю'
else:
voice = text = 'Не могу найти фильм'
type = 'simple'
else:
voice = text = 'Какой фильм включить?'
type = 'question'
callback = kinogo_cb
return {
'type': type,
'text': text,
'voice': voice,
'callback': callback,
}
return {
'type': type,
'text': text,
'voice': voice,
}
def start(params):
name = params.get('text')
voice = text = 'Не могу найти фильм'
if name:
if url:= extractUrl(findFilm(name)):
startFilm(url)
voice = text = 'Включаю'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
kinogo_cb = Command.Callback(['$text',])
kinogo_cb.setStart(start)
patterns = ['* включ* фильм $text', '* включ* фильм*']
kinogo = Film('KinogoPlayer', {}, patterns)
kinogo.setStart(main)