forked from KeyZenD/modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
YTsearch.py
59 lines (45 loc) · 1.85 KB
/
YTsearch.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
# -*- coding: utf-8 -*-
# Friendly Telegram (telegram userbot)
# Copyright (C) 2018-2020 The Authors
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# если не подписан на t.me/keyzend
# твоя мама шлюха
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from .. import loader, utils # pylint: disable=relative-beyond-top-level
from telethon.tl.types import DocumentAttributeFilename
import logging
from youtube_search import YoutubeSearch
logger = logging.getLogger(__name__)
def register(cb):
cb(YTsearchod())
@loader.tds
class YTsearchMod(loader.Module):
"""Поиск видео на ютубе"""
strings = {
"name": "YTsearch"
}
async def client_ready(self, client, db):
self.client = client
@loader.sudo
async def ytcmd(self, message):
"""текст или реплай"""
text = utils.get_args_raw(message)
if not text:
reply = await message.get_reply_message()
if not reply:
await message.delete()
return
text = reply.raw_text
results = YoutubeSearch(text, max_results=10).to_dict()
out = f'Найдено по запросу: {text}'
for r in results:
out += f'\n\n<a href="https://www.youtube.com/{r["link"]}">{r["title"]}</a>'
await message.edit(out)