forked from ParitoshPky/pdisk_uploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
152 lines (127 loc) ยท 4.76 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from os import environ
import os
from urllib.parse import urlparse
import aiohttp
from pyrogram import Client, filters
import requests
from bs4 import BeautifulSoup
import re
API_ID = environ.get('API_ID')
API_HASH = environ.get('API_HASH')
BOT_TOKEN = environ.get('BOT_TOKEN')
PDISK_API_KEY = environ.get('PDISK_API_KEY')
CHANNEL = environ.get('CHANNEL')
bot = Client('pdisk bot',
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
workers=50,
sleep_threshold=0)
@bot.on_message(filters.command('start') & filters.private)
async def start(bot, message):
await message.reply(
f"**๐๐๐๐๐ข๐{message.chat.first_name}!**\n\n"
"๐'๐ฆ ๐ ๐๐๐ข๐ฌ๐ค ๐๐ฉ๐ฅ๐จ๐๐๐๐ซ ๐๐จ๐ญ. ๐๐ฎ๐ฌ๐ญ ๐ฌ๐๐ง๐ ๐ฆ๐ ๐ฅ๐ข๐ง๐ค, ๐๐ข๐ฅ๐ ๐จ๐ซ ๐
๐ฎ๐ฅ๐ฅ ๐ฉ๐จ๐ฌ๐ญ...\๐ง\๐ง ๐๐ก๐ข๐ฌ ๐๐จ๐ญ ๐ข๐ฌ ๐ฆ๐๐๐ ๐๐ฒ @ParitoshPky๐")
@bot.on_message(filters.text & filters.private)
async def pdisk_uploader(bot, message):
new_string = str(message.text)
try:
pdisk_link = await multi_pdisk_up(new_string)
await message.reply(f'{pdisk_link}', quote=True)
except Exception as e:
await message.reply(f'Error: {e}', quote=True)
@bot.on_message(filters.photo & filters.private)
async def pdisk_uploader(bot, message):
new_string = str(message.caption)
try:
pdisk_link = await multi_pdisk_up(new_string)
if(len(pdisk_link) > 1020):
await message.reply(f'{pdisk_link}', quote=True)
else:
await bot.send_photo(message.chat.id, message.photo.file_id, caption=f'{pdisk_link}')
except Exception as e:
await message.reply(f'Error: {e}', quote=True)
async def get_ptitle(url):
html_text = requests.get(url).text
soup = BeautifulSoup(html_text, 'html.parser')
for title in soup.find_all('title'):
pass
title = list(title.get_text())
title = title[8:]
str = '@' + CHANNEL + ' '
for i in title:
str = str + i
lst = list(html_text.split(","))
c = 0
for i in lst:
if ("""videoid""" in i):
found = lst[c]
break
c += 1
# pdisk.net link
pdisk_video_id = list(found.split(":"))
video_id = pdisk_video_id[2]
video_id = list(video_id.split(","))
v_id = video_id[0]
v_len = len(v_id)
v_id = v_id[1:v_len - 2]
v_url = 'https://www.pdisks.com/share-video?videoid=' + v_id
res = [str, v_url]
return res
async def pdisk_up(link):
if ('pdisk' in link or 'kuklink' in link or 'kofilink' in link or 'cofilink' in link or 'bit' in link):
res = await get_ptitle(link)
title_pdisk = res[0]
link = res[1]
else:
title_new = urlparse(link)
title_new = os.path.basename(title_new.path)
title_pdisk = '@' + CHANNEL + title_new
res = requests.get(
'http://linkapi.net/open/create_item?link_type=link&content_src=' + link + '&source=2000&api_key=' + PDISK_API_KEY + '&dir_id=0&title=' + title_pdisk + '&description=Join_' + CHANNEL + '_for_more_like_this')
data = res.json()
data = dict(data)
print(data)
v_id = data['data']['item_id']
v_url = 'https://www.pdisks.com/share-video?videoid=' + v_id
return (v_url)
async def multi_pdisk_up(ml_string):
new_ml_string = list(map(str, ml_string.split(" ")))
new_ml_string = await remove_username(new_ml_string)
new_join_str = "".join(new_ml_string)
urls = re.findall(r'(https?://[^\s]+)', new_join_str)
nml_len = len(new_ml_string)
u_len = len(urls)
url_index = []
count = 0
for i in range(nml_len):
for j in range(u_len):
if (urls[j] in new_ml_string[i]):
url_index.append(count)
count += 1
new_urls = await new_pdisk_url(urls)
url_index = list(dict.fromkeys(url_index))
i = 0
for j in url_index:
new_ml_string[j] = new_ml_string[j].replace(urls[i], new_urls[i])
i += 1
new_string = " ".join(new_ml_string)
return await addFooter(new_string)
async def new_pdisk_url(urls):
new_urls = []
for i in urls:
new_urls.append(await pdisk_up(i))
return new_urls
async def remove_username(new_List):
for i in new_List:
if('@' in i or 't.me' in i or 'https://bit.ly/3m4gabB' in i or 'https://bit.ly/pdisk_tuts' in i or 'telegra.ph' in i):
new_List.remove(i)
return new_List
async def addFooter(str):
footer = """
โโโโโโโโโโโโโโโ
โ๏ธ How to Download / Watch Online or Change Audio : https://bit.ly/3m4gabB
โโโโโโโโโโโโโโโ
โญ๏ธJOIN CHANNEL โก๏ธ t.me/""" + CHANNEL
return str + footer
bot.run()