Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -1,18 +1,10 @@
|
|
1 |
import logging
|
2 |
-
import
|
3 |
-
import random
|
4 |
-
from pyrogram import Client, filters, idle
|
5 |
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
6 |
from pyrogram.types import *
|
7 |
from RyuzakiLib import Tiktok
|
8 |
-
from config import TIKTOK_WEB as tt, API_ID, API_HASH, BOT_TOKEN
|
9 |
import hashlib
|
10 |
-
import asyncio
|
11 |
-
|
12 |
-
try:
|
13 |
-
from aiohttp import ClientSession as aiohttp_client
|
14 |
-
except ImportError:
|
15 |
-
aiohttp_client = None
|
16 |
|
17 |
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
18 |
logging.basicConfig(level=logging.INFO)
|
@@ -39,60 +31,6 @@ def generate_callback_data(user_id, query):
|
|
39 |
link_storage[callback_data] = query
|
40 |
return callback_data
|
41 |
|
42 |
-
async def async_searcher(
|
43 |
-
url: str,
|
44 |
-
post: bool = False,
|
45 |
-
head: bool = False,
|
46 |
-
headers: dict = None,
|
47 |
-
evaluate=None,
|
48 |
-
object: bool = False,
|
49 |
-
re_json: bool = False,
|
50 |
-
re_content: bool = False,
|
51 |
-
*args,
|
52 |
-
**kwargs,
|
53 |
-
):
|
54 |
-
if aiohttp_client:
|
55 |
-
async with aiohttp_client(headers=headers) as client:
|
56 |
-
method = client.head if head else (client.post if post else client.get)
|
57 |
-
data = await method(url, *args, **kwargs)
|
58 |
-
if evaluate:
|
59 |
-
return await evaluate(data)
|
60 |
-
if re_json:
|
61 |
-
return await data.json()
|
62 |
-
if re_content:
|
63 |
-
return await data.read()
|
64 |
-
if head or object:
|
65 |
-
return data
|
66 |
-
return await data.text()
|
67 |
-
else:
|
68 |
-
raise DependencyMissingError("install 'aiohttp' to use this.")
|
69 |
-
|
70 |
-
async def hfv(api_url, timeout=10):
|
71 |
-
try:
|
72 |
-
headers = {
|
73 |
-
"Authorization": f"Bearer {HUGGING_TOKEN}",
|
74 |
-
"Content-Type": "application/json",
|
75 |
-
}
|
76 |
-
response = await async_searcher(api_url, headers=headers, re_json=True)
|
77 |
-
stat = response.get("message", "ded")
|
78 |
-
return await client.send_message(chat_id=1191668125, text=f"**TɪᴋTᴏᴋ Sᴇʀᴠᴇʀ Sᴛᴀᴛᴜs:** `{stat}`")
|
79 |
-
except requests.exceptions.RequestException as e:
|
80 |
-
logging.info("Error occurred:", e)
|
81 |
-
return await client.send_message(chat_id=1191668125, text=f"**TɪᴋTᴏᴋ Sᴇʀᴠᴇʀ Sᴛᴀᴛᴜs:** `ded`")
|
82 |
-
|
83 |
-
async def periodic_hfv(api_url, interval_range):
|
84 |
-
while True:
|
85 |
-
result = await hfv(api_url)
|
86 |
-
if result:
|
87 |
-
logging.info("Call Complete")
|
88 |
-
interval = random.randint(*interval_range)
|
89 |
-
await asyncio.sleep(interval)
|
90 |
-
|
91 |
-
async def start_periodic_task():
|
92 |
-
interval_range = (2 * 3600, 4 * 3600) # Call the function every 2 to 4 hours
|
93 |
-
api_url = "https://randydev-ttk-bot.hf.space/status"
|
94 |
-
asyncio.create_task(periodic_hfv(api_url, interval_range))
|
95 |
-
|
96 |
@client.on_message(filters.command("start") & filters.private)
|
97 |
async def welcome_start(client: Client, message: Message):
|
98 |
keyboard = InlineKeyboardMarkup(
|
@@ -110,13 +48,6 @@ async def welcome_start(client: Client, message: Message):
|
|
110 |
reply_markup=keyboard
|
111 |
)
|
112 |
|
113 |
-
@client.on_message(filters.command("keepalive") & filters.private)
|
114 |
-
async def keep_alive(client: Client, message: Message):
|
115 |
-
await start_periodic_task()
|
116 |
-
await message.reply_text(
|
117 |
-
"Now Keeping Alive"
|
118 |
-
)
|
119 |
-
|
120 |
@client.on_callback_query(filters.regex("^audiodownload_"))
|
121 |
async def callback_button(client: Client, cb: CallbackQuery):
|
122 |
try:
|
@@ -124,7 +55,7 @@ async def callback_button(client: Client, cb: CallbackQuery):
|
|
124 |
user_id = cb.from_user.id
|
125 |
query = link_storage.get(data)
|
126 |
if query:
|
127 |
-
response = Tiktok.download(tt, query)
|
128 |
await client.send_audio(user_id, response[1])
|
129 |
await cb.answer("Audio sent successfully!")
|
130 |
else:
|
@@ -150,11 +81,11 @@ async def tiktok_downloader(client: Client, message: Message):
|
|
150 |
try:
|
151 |
dll = await message.reply_text("Processing....")
|
152 |
await message.delete()
|
153 |
-
response = Tiktok.download(tt, query)
|
154 |
await message.reply_video(response[0], reply_markup=keyboard)
|
155 |
await dll.delete()
|
156 |
except Exception as e:
|
157 |
await dll.delete()
|
158 |
await message.reply_text(f"Error: {str(e)}")
|
159 |
|
160 |
-
client.run()
|
|
|
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)
|
|
|
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(
|
|
|
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:
|
|
|
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:
|
|
|
81 |
try:
|
82 |
dll = await message.reply_text("Processing....")
|
83 |
await message.delete()
|
84 |
+
response = await Tiktok.download(tt, query)
|
85 |
await message.reply_video(response[0], reply_markup=keyboard)
|
86 |
await dll.delete()
|
87 |
except Exception as e:
|
88 |
await dll.delete()
|
89 |
await message.reply_text(f"Error: {str(e)}")
|
90 |
|
91 |
+
client.run()
|