genstava789 commited on
Commit
dc36bc1
·
1 Parent(s): 2a479c9
Files changed (2) hide show
  1. bot.py +30 -71
  2. requirements.txt +1 -0
bot.py CHANGED
@@ -1,5 +1,6 @@
1
  from pyrogram import Client, filters
2
  from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery, Message, InputMediaPhoto, InputMediaVideo
 
3
  from typing import Optional
4
  import threading
5
  import asyncio
@@ -324,6 +325,34 @@ async def threads(client: Client, message: Message):
324
  finally:
325
  await load.delete()
326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  @bot.on_message(filters.command("tiktok"))
328
  async def tiktok(client: Client, message: Message):
329
  if len(message.text.split()) < 2:
@@ -349,78 +378,8 @@ async def tiktok(client: Client, message: Message):
349
  await client.send_message(dev_id, f'[ ERROR MESSAGE ]\n\n• Username: @{message.from_user.username}\n• Url: {url}\n\n{str(e)}')
350
  await message.reply('An unexpected error occurred. Please try again later.')
351
  finally:
352
- await load.delete
353
- ()
354
 
355
- async def tiktokdl(URL):
356
- return new Promise((resolve, reject) => {
357
- axios.get('https://musicaldown.com/id', {
358
- headers: {
359
- 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
360
- }
361
- }).then(res => {
362
- const $ = cheerio.load(res.data)
363
- const url_name = $("#link_url").attr("name")
364
- const token_name = $("#submit-form > div").find("div:nth-child(1) > input[type=hidden]:nth-child(2)").attr("name")
365
- const token_ = $("#submit-form > div").find("div:nth-child(1) > input[type=hidden]:nth-child(2)").attr("value")
366
- const verify = $("#submit-form > div").find("div:nth-child(1) > input[type=hidden]:nth-child(3)").attr("value")
367
- let data = {
368
- [`${url_name}`]: URL,
369
- [`${token_name}`]: token_,
370
- verify: verify
371
- }
372
- axios.request({
373
- url: 'https://musicaldown.com/id/download',
374
- method: 'post',
375
- data: new URLSearchParams(Object.entries(data)),
376
- headers: {
377
- 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
378
- 'cookie': res.headers["set-cookie"]
379
- }
380
- }).then(respon => {
381
- const ch = cheerio.load(respon.data)
382
- axios.request({
383
- url: 'https://musicaldown.com/id/mp3',
384
- method: 'post',
385
- headers: {
386
- 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
387
- 'cookie': res.headers["set-cookie"]
388
- }
389
- }).then(resaudio => {
390
- const hc = cheerio.load(resaudio.data)
391
- if (ch('.card-image')[0]) {
392
- let result = [];
393
- ch('.card-image').each((i, mil) => {
394
- let urlimg = ch(mil).find('img').attr('src');
395
- result.push({ image: urlimg })
396
- })
397
- resolve(result)
398
- } else if (ch('body > div.welcome.section > div > div > div.col.s12.l4 > audio > source').attr('src')) {
399
- const result = {
400
- type: 'music',
401
- title: ch('body > div.welcome.section > div.container > div > div.col.s12.l8 > h2.white-text').text().replace('Music Title: ', ''),
402
- audio: ch('body > div.welcome.section > div > div > div.col.s12.l4 > audio > source').attr('src'),
403
- audio2: ch('body > div.welcome.section > div.container > div > div.col.s12.l8 > a').attr('href')
404
- };
405
- resolve(result);
406
- } else {
407
- const result = {
408
- type: 'video',
409
- pp: ch('body > div.welcome.section > div > div > div.col.s12.l4.center-align > div > div > img').attr('src'),
410
- username: ch('body > div.welcome.section > div > div > div.col.s12.l4.center-align > div > h2 > b').text(),
411
- description: ch('body > div.welcome.section > div > div > div.col.s12.l4.center-align > div > h2 + h2').text(),
412
- video: ch('body > div.welcome.section > div.container > div > div.col.s12.l8 > a').attr('href'),
413
- audio: hc('body > div.welcome.section > div.container > div > div.col.s12.l8 > a + br + a').attr('href'),
414
- videohd: ch('body > div.welcome.section > div.container > div > div.col.s12.l8 > a + br + a + br + a').attr('href'),
415
- videowm: ch('body > div.welcome.section > div.container > div > div.col.s12.l8 > a + br + a + br + a + br + a').attr('href')
416
- }
417
- resolve(result);
418
- }
419
- })
420
- })
421
- })
422
- })
423
- }
424
  def run_bot():
425
  loop = asyncio.new_event_loop()
426
  asyncio.set_event_loop(loop)
 
1
  from pyrogram import Client, filters
2
  from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery, Message, InputMediaPhoto, InputMediaVideo
3
+ from bs4 import BeautifulSoup
4
  from typing import Optional
5
  import threading
6
  import asyncio
 
325
  finally:
326
  await load.delete()
327
 
328
+ async def tiktokdl(url):
329
+ headers = {
330
+ 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
331
+ }
332
+ session = requests.Session()
333
+ response = session.get('https://musicaldown.com/id', headers=headers)
334
+ response.raise_for_status()
335
+
336
+
337
+ soup = BeautifulSoup(response.text, 'html.parser')
338
+ url_name = soup.find(id="link_url")['name']
339
+ token_name = soup.select_one("#submit-form > div input[type=hidden]:nth-child(2)")['name']
340
+ token_value = soup.select_one("#submit-form > div input[type=hidden]:nth-child(2)")['value']
341
+ verify = soup.select_one("#submit-form > div input[type=hidden]:nth-child(3)")['value']
342
+
343
+ data = {
344
+ url_name: url,
345
+ token_name: token_value,
346
+ 'verify': verify
347
+ }
348
+
349
+ download_response = session.post('https://musicaldown.com/id/download', data=data, headers=headers)
350
+ download_response.raise_for_status()
351
+ download_soup = BeautifulSoup(download_response.text, 'html.parser')
352
+
353
+ video_url = download_soup.select_one('a[href*="video"]')['href']
354
+ return {'type': 'video', 'video': video_url}
355
+
356
  @bot.on_message(filters.command("tiktok"))
357
  async def tiktok(client: Client, message: Message):
358
  if len(message.text.split()) < 2:
 
378
  await client.send_message(dev_id, f'[ ERROR MESSAGE ]\n\n• Username: @{message.from_user.username}\n• Url: {url}\n\n{str(e)}')
379
  await message.reply('An unexpected error occurred. Please try again later.')
380
  finally:
381
+ await load.delete()
 
382
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  def run_bot():
384
  loop = asyncio.new_event_loop()
385
  asyncio.set_event_loop(loop)
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  fastapi
2
  uvicorn
 
3
  asyncio
4
  python-dotenv
5
  requests
 
1
  fastapi
2
  uvicorn
3
+ beautifulsoup4
4
  asyncio
5
  python-dotenv
6
  requests