2020-11-04 20:39:48 +02:00
|
|
|
from .Media import *
|
2020-10-31 21:11:24 +02:00
|
|
|
import requests
|
|
|
|
from bs4 import BeautifulSoup as BS
|
|
|
|
import os
|
2020-11-04 20:39:48 +02:00
|
|
|
from Command import Callback
|
2020-10-31 21:11:24 +02:00
|
|
|
################################################################################
|
|
|
|
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')
|
2020-11-01 14:18:13 +02:00
|
|
|
title = page.select_one('h1')
|
|
|
|
return (url['href'], title.text) if url else None
|
2020-10-31 21:11:24 +02:00
|
|
|
|
2020-11-01 14:18:13 +02:00
|
|
|
def startFilm(url, title):
|
2020-11-01 16:42:22 +02:00
|
|
|
os.system(f'lxterminal --command="vlc {url} -f --meta-title=\\"{title}\\" "')
|
2020-10-31 21:11:24 +02:00
|
|
|
|
|
|
|
def main(params):
|
|
|
|
name = params.get('text')
|
|
|
|
if name:
|
2020-11-01 14:18:13 +02:00
|
|
|
url, title = extractUrl(findFilm(name))
|
|
|
|
if url:
|
2020-11-01 16:42:22 +02:00
|
|
|
startFilm(url, title.strip())
|
2020-10-31 21:11:24 +02:00
|
|
|
voice = text = 'Включаю'
|
|
|
|
else:
|
|
|
|
voice = text = 'Не могу найти фильм'
|
|
|
|
else:
|
|
|
|
voice = text = 'Какой фильм включить?'
|
|
|
|
callback = kinogo_cb
|
|
|
|
return {
|
2020-11-09 20:32:49 +02:00
|
|
|
'type': 'question',
|
2020-10-31 21:11:24 +02:00
|
|
|
'text': text,
|
|
|
|
'voice': voice,
|
|
|
|
'callback': callback,
|
|
|
|
}
|
|
|
|
return {
|
2020-11-09 20:32:49 +02:00
|
|
|
'type': 'simple',
|
2020-10-31 21:11:24 +02:00
|
|
|
'text': text,
|
|
|
|
'voice': voice,
|
|
|
|
}
|
|
|
|
|
|
|
|
def start(params):
|
|
|
|
name = params.get('text')
|
|
|
|
voice = text = 'Не могу найти фильм'
|
|
|
|
if name:
|
2020-11-05 19:26:15 +02:00
|
|
|
url, title = extractUrl(findFilm(name))
|
|
|
|
if url:
|
|
|
|
startFilm(url, title.strip())
|
2020-10-31 21:11:24 +02:00
|
|
|
voice = text = 'Включаю'
|
|
|
|
return {
|
|
|
|
'type': 'simple',
|
|
|
|
'text': text,
|
|
|
|
'voice': voice,
|
|
|
|
}
|
|
|
|
|
2020-11-04 20:39:48 +02:00
|
|
|
kinogo_cb = Callback(['$text',])
|
2020-10-31 21:11:24 +02:00
|
|
|
kinogo_cb.setStart(start)
|
|
|
|
|
|
|
|
patterns = ['* включ* фильм $text', '* включ* фильм*']
|
2020-11-04 20:39:48 +02:00
|
|
|
kinogo = Media('KinogoPlayer', {}, patterns)
|
2020-10-31 21:11:24 +02:00
|
|
|
kinogo.setStart(main)
|