randydev commited on
Commit
b3eb313
·
verified ·
1 Parent(s): 3af4735

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +93 -0
main.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from pyrogram import Client, filters
3
+ from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
4
+ from pyrogram.types import *
5
+ from RyuzakiLib import Tiktok
6
+ from config import TIKTOK_WEB as tt, API_ID, API_HASH, BOT_TOKEN
7
+ import hashlib
8
+
9
+ logging.getLogger("pyrogram").setLevel(logging.WARNING)
10
+ logging.basicConfig(level=logging.INFO)
11
+
12
+ WELCOME_TEXT = """
13
+ Halo {}
14
+ Saya adalah bot untuk mengunduh video tiktok di telegram.
15
+
16
+ Saya dapat mengunduh video dengan tanda air atau tanpa tanda air dan mengunduh audio dari url. Kirimkan saja saya url tiktok.
17
+ """
18
+
19
+ client = Client(
20
+ "TTK-BOT",
21
+ api_id=API_ID,
22
+ api_hash=API_HASH,
23
+ bot_token=BOT_TOKEN
24
+ )
25
+
26
+ link_storage = {}
27
+
28
+ def generate_callback_data(user_id, query):
29
+ identifier = hashlib.md5(query.encode()).hexdigest()
30
+ callback_data = f"audiodownload_{user_id}_{identifier}"
31
+ link_storage[callback_data] = query
32
+ return callback_data
33
+
34
+ @client.on_message(filters.command("start") & filters.private)
35
+ async def welcome_start(client: Client, message: Message):
36
+ keyboard = InlineKeyboardMarkup(
37
+ [
38
+ [
39
+ InlineKeyboardButton(
40
+ text="📢 Saluran Bot",
41
+ url="https://t.me/RendyProjects"
42
+ )
43
+ ]
44
+ ]
45
+ )
46
+ await message.reply_text(
47
+ WELCOME_TEXT.format(message.from_user.first_name),
48
+ reply_markup=keyboard
49
+ )
50
+
51
+ @client.on_callback_query(filters.regex("^audiodownload_"))
52
+ async def callback_button(client: Client, cb: CallbackQuery):
53
+ try:
54
+ data = cb.data
55
+ user_id = cb.from_user.id
56
+ query = link_storage.get(data)
57
+ if query:
58
+ response = await Tiktok.download(tt, query)
59
+ await client.send_audio(user_id, response[1])
60
+ await cb.answer("Audio sent successfully!")
61
+ else:
62
+ await cb.answer("Invalid or expired link.", show_alert=True)
63
+ except Exception as e:
64
+ await cb.answer(f"Error: {str(e)}", show_alert=True)
65
+
66
+ @client.on_message(filters.text & filters.private)
67
+ async def tiktok_downloader(client: Client, message: Message):
68
+ if message.text:
69
+ query = message.text
70
+ if not query.startswith("https://vt.tiktok.com/") and not query.startswith("https://www.tiktok.com/"):
71
+ return await message.reply_text("Invalid link")
72
+ callback_data = generate_callback_data(message.from_user.id, query)
73
+ keyboard = InlineKeyboardMarkup(
74
+ [
75
+ [
76
+ InlineKeyboardButton(
77
+ text="Audio Download",
78
+ callback_data=callback_data
79
+ )
80
+ ]
81
+ ]
82
+ )
83
+ try:
84
+ dll = await message.reply_text("Processing....")
85
+ await message.delete()
86
+ response = await Tiktok.download(tt, query)
87
+ await message.reply_video(response[0], reply_markup=keyboard)
88
+ await dll.delete()
89
+ except Exception as e:
90
+ await dll.delete()
91
+ await message.reply_text(f"Error: {str(e)}")
92
+
93
+ client.run()