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