randydev commited on
Commit
6b55505
·
verified ·
1 Parent(s): 10142c8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -7
main.py CHANGED
@@ -4,6 +4,7 @@ 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
 
8
  logging.getLogger("pyrogram").setLevel(logging.WARNING)
9
  logging.basicConfig(level=logging.INFO)
@@ -22,6 +23,14 @@ client = Client(
22
  bot_token=BOT_TOKEN
23
  )
24
 
 
 
 
 
 
 
 
 
25
  @client.on_message(filters.command("start") & filters.private)
26
  async def welcome_start(client: Client, message: Message):
27
  keyboard = InlineKeyboardMarkup(
@@ -42,12 +51,15 @@ async def welcome_start(client: Client, message: Message):
42
  @client.on_callback_query(filters.regex("^audiodownload_"))
43
  async def callback_button(client: Client, cb: CallbackQuery):
44
  try:
45
- data = cb.data.split("_")
46
- user_id = int(data[1].split("|")[0])
47
- link = cb.data.split("|")[1]
48
- response = Tiktok.download(tt, link)
49
- await client.send_audio(user_id, response[1])
50
- await cb.answer("Audio sent successfully!")
 
 
 
51
  except Exception as e:
52
  await cb.answer(f"Error: {str(e)}", show_alert=True)
53
 
@@ -55,12 +67,13 @@ async def callback_button(client: Client, cb: CallbackQuery):
55
  async def tiktok_downloader(client: Client, message: Message):
56
  if message.text:
57
  query = message.text
 
58
  keyboard = InlineKeyboardMarkup(
59
  [
60
  [
61
  InlineKeyboardButton(
62
  text="Audio Download",
63
- callback_data=f"audiodownload_{message.from_user.id}|{query}"
64
  )
65
  ]
66
  ]
 
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)
 
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(
 
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 = 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
 
 
67
  async def tiktok_downloader(client: Client, message: Message):
68
  if message.text:
69
  query = message.text
70
+ callback_data = generate_callback_data(message.from_user.id, query)
71
  keyboard = InlineKeyboardMarkup(
72
  [
73
  [
74
  InlineKeyboardButton(
75
  text="Audio Download",
76
+ callback_data=callback_data
77
  )
78
  ]
79
  ]