-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
88 lines (68 loc) · 3.82 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import InlineKeyboardButton, InlineKeyboardMarkup
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
TOKEN = 'TOKEN'
PLAYER_URL = 'https://4h0y.gitlab.io/#' # 'https://kirlovon.dev/Kinopoisk-Watch/?id='
bot = Bot(token=TOKEN)
dp = Dispatcher(bot)
HEADERS = {'User-Agent': 'Your User Agent'}
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
await bot.send_message(message.chat.id, f'''
👋 Привет, {message.from_user.mention}
🆓 Это бесплатный Kinopoisk
🔎 Чтобы найти нужный вам фильм нужно написать:
🎥 /kino название фильма или ссылка на него
📋 Пример:
🎥 /kino Волк с Уолл-стрит
💲 Поддержать - /donate
👨💻 Разработчик - /coder''')
@dp.message_handler(commands=['kino'])
async def kino(message: types.Message):
text = ' '.join(message.text.strip().split()[1:])
keyboard = InlineKeyboardMarkup()
if text == '':
return await bot.send_message(message.chat.id, '🎥 Укажите название или ссылку на фильм')
if text.startswith('https://www.kinopoisk.ru/film/'):
film_id = text.replace('https://www.kinopoisk.ru/film/', '').replace('/', '')
keyboard.add(InlineKeyboardButton('👁🗨 Смотреть', url=PLAYER_URL + film_id))
return await bot.send_message(message.chat.id,
f'🍿 Готовь попкорн!\n🎥 Держи фильм:', reply_markup=keyboard)
response = requests.get(f'https://www.kinopoisk.ru/index.php?kp_query={text}', headers={
'User-Agent': UserAgent().random})
soup = BeautifulSoup(response.text, 'lxml')
count = 0
film_most = soup.find('div', class_='element most_wanted')
if film_most is None:
msg = '''
🔗 Попробуй указать на него ссылку с Kinopisk
Пример:
/kino https://www.kinopoisk.ru/film/462682
'''
if 'https://captcha-backgrounds.s3.yandex.net/static/kinopoisk-background.jpg' in response.text:
return await bot.send_message(message.chat.id, '😔 Наткнулся на капчу.\n' + msg)
return await bot.send_message(message.chat.id, '😔 Я не нашёл фильм с таким названием.\n' + msg)
for element in soup.find_all('div', class_='search_results'):
e = element.find('p', class_='header').find('a')
if e is not None:
if 'имена' in e.get_text(strip=True):
break
for film in element.find_all('div', class_='element'):
count += 1
film_rating = film.find('div', class_='right').find('div')
film_rating = '0' if film_rating is None else film_rating.get_text(strip=True)
film = film.find('p', class_='name')
film_name = film.find('a').get_text(strip=True)
film_id = film.find('a').get('data-id')
keyboard.add(InlineKeyboardButton(text=f'{film_name} | {film_rating}⭐', url=PLAYER_URL + film_id))
await bot.send_message(message.chat.id, f'🍿 Готовь попкорн!\n🎥 Я нашёл для тебя фильм{"ы" if count > 1 else ""}:', reply_markup=keyboard)
@dp.message_handler(commands=['coder'])
async def coder(message: types.Message):
await bot.send_message(message.chat.id, '''👨💻 Кодер этого бота - @Kirill_Monster
📋 И его проекты не забудь посмотреть:
TG - @kirill_monster_projects
GitHub - https://github.com/KirillMonster''')
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)