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.1 KiB
Python
Raw Normal View History

from .Media import *
import requests
from bs4 import BeautifulSoup as BS
import os
from Command import Callback
################################################################################
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-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}\\" "')
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())
voice = text = 'Включаю'
else:
voice = text = 'Не могу найти фильм'
else:
voice = text = 'Какой фильм включить?'
callback = kinogo_cb
return {
2020-11-09 20:32:49 +02:00
'type': 'question',
'text': text,
'voice': voice,
'callback': callback,
}
return {
2020-11-09 20:32:49 +02:00
'type': 'simple',
'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())
voice = text = 'Включаю'
return {
'type': 'simple',
'text': text,
'voice': voice,
}
kinogo_cb = Callback(['$text',])
kinogo_cb.setStart(start)
patterns = ['* включ* фильм $text', '* включ* фильм*']
kinogo = Media('KinogoPlayer', {}, patterns)
kinogo.setStart(main)