forked from mohitbooraget/New_Txt_Random
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
217 lines (217 loc) · 561 KB
/
main.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
from pyrogram.errors.exceptions.bad_request_400 import StickerEmojiInvalid #Bot Created by @NtrRazYt
import requests #Bot Created by @NtrRazYt
import json #Bot Created by @NtrRazYt
import subprocess #Bot Created by @NtrRazYt
from pyrogram import Client, filters #Bot Created by @NtrRazYt
from pyrogram.types.messages_and_media import message #Bot Created by @NtrRazYt
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup #Bot Created by @NtrRazYt
from pyrogram.errors import FloodWait #Bot Created by @NtrRazYt
from pyromod import listen #Bot Created by @NtrRazYt
from pyrogram.types import Message #Bot Created by @NtrRazYt
from pyrogram import Client, filters #Bot Created by @NtrRazYt
from p_bar import progress_bar #Bot Created by @NtrRazYt
from subprocess import getstatusoutput #Bot Created by @NtrRazYt
from aiohttp import ClientSession #Bot Created by @NtrRazYt
import helper #Bot Created by @NtrRazYt
from logger import logging #Bot Created by @NtrRazYt
import time #Bot Created by @NtrRazYt
import asyncio #Bot Created by @NtrRazYt
from pyrogram.types import User, Message #Bot Created by @NtrRazYt
import sys #Bot Created by @NtrRazYt
import re #Bot Created by @NtrRazYt
import os #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
bot = Client("bot", #Bot Created by @NtrRazYt
bot_token=os.environ.get("BOT_TOKEN"), #Bot Created by @NtrRazYt
api_id=int(os.environ.get("API_ID")), #Bot Created by @NtrRazYt
api_hash=os.environ.get("API_HASH")) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
@bot.on_message(filters.command(["start"])) #Bot Created by @NtrRazYt
async def account_login(bot: Client, m: Message): #Bot Created by @NtrRazYt
editable = await m.reply_text("Hello I am Txt file downloader\nI Can Download links listed in a txt file in the format **Name:link**\n\nBot Made by ADITYA⚡") #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
@bot.on_message(filters.command("Stop")) #Bot Created by @NtrRazYt
async def restart_handler(_, m): #Bot Created by @NtrRazYt
await m.reply_text("🚦**STOPPED**🚦", True) #Bot Created by @NtrRazYt
os.execl(sys.executable, sys.executable, *sys.argv) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
@bot.on_message(filters.command(["downvid"])) #Bot Created by @NtrRazYt
async def account_login(bot: Client, m: Message): #Bot Created by @NtrRazYt
editable = await m.reply_text('**Send TXT file for download**') #Bot Created by @NtrRazYt
input: Message = await bot.listen(editable.chat.id) #Bot Created by @NtrRazYt
x = await input.download() #Bot Created by @NtrRazYt
await input.delete(True) #Bot Created by @NtrRazYt
file_name, ext = os.path.splitext(os.path.basename(x)) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
path = f"./downloads/{m.chat.id}" #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
try: #Bot Created by @NtrRazYt
with open(x, "r") as f: #Bot Created by @NtrRazYt
content = f.read() #Bot Created by @NtrRazYt
content = content.split("\n") #Bot Created by @NtrRazYt
links = [] #Bot Created by @NtrRazYt
for i in content: #Bot Created by @NtrRazYt
links.append(i.split("://", 1)) #Bot Created by @NtrRazYt
os.remove(x) #Bot Created by @NtrRazYt
# print(len(links) #Bot Created by @NtrRazYt
except: #Bot Created by @NtrRazYt
await m.reply_text("Invalid file input.") #Bot Created by @NtrRazYt
os.remove(x) #Bot Created by @NtrRazYt
return #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
await editable.edit(f"Total links found are **{len(links)}**\n\nSend From where you want to download initial is **1**") #Bot Created by @NtrRazYt
input0: Message = await bot.listen(editable.chat.id) #Bot Created by @NtrRazYt
raw_text = input0.text #Bot Created by @NtrRazYt
await input0.delete(True) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
await editable.edit("**Enter Batch Name or send /d for grabing from text filename.**") #Bot Created by @NtrRazYt
input1: Message = await bot.listen(editable.chat.id) #Bot Created by @NtrRazYt
raw_text0 = input1.text #Bot Created by @NtrRazYt
await input1.delete(True) #Bot Created by @NtrRazYt
if raw_text0 == '/d': #Bot Created by @NtrRazYt
b_name = file_name #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
b_name = raw_text0 #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
await editable.edit("**Enter resolution**") #Bot Created by @NtrRazYt
input2: Message = await bot.listen(editable.chat.id) #Bot Created by @NtrRazYt
raw_text2 = input2.text #Bot Created by @NtrRazYt
await input2.delete(True) #Bot Created by @NtrRazYt
try: #Bot Created by @NtrRazYt
if raw_text2 == "144": #Bot Created by @NtrRazYt
res = "256x144" #Bot Created by @NtrRazYt
elif raw_text2 == "240": #Bot Created by @NtrRazYt
res = "426x240" #Bot Created by @NtrRazYt
elif raw_text2 == "360": #Bot Created by @NtrRazYt
res = "640x360" #Bot Created by @NtrRazYt
elif raw_text2 == "480": #Bot Created by @NtrRazYt
res = "854x480" #Bot Created by @NtrRazYt
elif raw_text2 == "720": #Bot Created by @NtrRazYt
res = "1280x720" #Bot Created by @NtrRazYt
elif raw_text2 == "1080": #Bot Created by @NtrRazYt
res = "1920x1080" #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
res = "UN" #Bot Created by @NtrRazYt
except Exception: #Bot Created by @NtrRazYt
res = "UN" #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
await editable.edit("**Enter Your Name or send `de` for use default**") #Bot Created by @NtrRazYt
input3: Message = await bot.listen(editable.chat.id) #Bot Created by @NtrRazYt
raw_text3 = input3.text #Bot Created by @NtrRazYt
await input3.delete(True) #Bot Created by @NtrRazYt
if raw_text3 == 'de': #Bot Created by @NtrRazYt
MR = credit #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
MR = raw_text3 #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
await editable.edit("Now send the **Thumb url**\nEg : `https://graph.org/file/45f562dc05b2874c7277e.jpg`\n\nor Send `no`") #Bot Created by @NtrRazYt
input6 = message = await bot.listen(editable.chat.id) #Bot Created by @NtrRazYt
raw_text6 = input6.text #Bot Created by @NtrRazYt
await input6.delete(True) #Bot Created by @NtrRazYt
await editable.delete() #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
thumb = input6.text #Bot Created by @NtrRazYt
if thumb.startswith("http://") or thumb.startswith("https://"): #Bot Created by @NtrRazYt
getstatusoutput(f"wget '{thumb}' -O 'thumb.jpg'") #Bot Created by @NtrRazYt
thumb = "thumb.jpg" #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
thumb == "no" #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
if len(links) == 1: #Bot Created by @NtrRazYt
count = 1 #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
count = int(raw_text) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
try: #Bot Created by @NtrRazYt
for i in range(count - 1, len(links)): #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
V = links[i][1].replace("file/d/","uc?export=download&id=").replace("www.youtube-nocookie.com/embed", "youtu.be").replace("?modestbranding=1", "").replace("/view?usp=sharing","") # .replace("mpd","m3u8") #Bot Created by @NtrRazYt
url = "https://" + V #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
if "visionias" in url: #Bot Created by @NtrRazYt
async with ClientSession() as session: #Bot Created by @NtrRazYt
async with session.get(url, headers={'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', 'Accept-Language': 'en-US,en;q=0.9', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Referer': 'http://www.visionias.in/', 'Sec-Fetch-Dest': 'iframe', 'Sec-Fetch-Mode': 'navigate', 'Sec-Fetch-Site': 'cross-site', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Linux; Android 12; RMX2121) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Mobile Safari/537.36', 'sec-ch-ua': '"Chromium";v="107", "Not=A?Brand";v="24"', 'sec-ch-ua-mobile': '?1', 'sec-ch-ua-platform': '"Android"',}) as resp: #Bot Created by @NtrRazYt
text = await resp.text() #Bot Created by @NtrRazYt
url = re.search(r"(https://.*?playlist.m3u8.*?)\"", text).group(1) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
elif 'videos.classplusapp' in url: #Bot Created by @NtrRazYt
url = requests.get(f'https://api.classplusapp.com/cams/uploader/video/jw-signed-url?url={url}', headers={'x-access-token': 'eyJhbGciOiJIUzM4NCIsInR5cCI6IkpXVCJ9.eyJpZCI6MzgzNjkyMTIsIm9yZ0lkIjoyNjA1LCJ0eXBlIjoxLCJtb2JpbGUiOiI5MTcwODI3NzQyODkiLCJuYW1lIjoiQWNlIiwiZW1haWwiOm51bGwsImlzRmlyc3RMb2dpbiI6dHJ1ZSwiZGVmYXVsdExhbmd1YWdlIjpudWxsLCJjb3VudHJ5Q29kZSI6IklOIiwiaXNJbnRlcm5hdGlvbmFsIjowLCJpYXQiOjE2NDMyODE4NzcsImV4cCI6MTY0Mzg4NjY3N30.hM33P2ai6ivdzxPPfm01LAd4JWv-vnrSxGXqvCirCSpUfhhofpeqyeHPxtstXwe0'}).json()['url'] #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
elif '/master.mpd' in url: #Bot Created by @NtrRazYt
id = url.split("/")[-2] #Bot Created by @NtrRazYt
url = "https://d26g5bnklkwsh4.cloudfront.net/" + id + "/master.m3u8" #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
name1 = links[i][0].replace("\t", "").replace(":", "").replace("/", "").replace("+", "").replace("#", "").replace("|", "").replace("@", "").replace("*", "").replace(".", "").replace("https", "").replace("http", "").strip() #Bot Created by @NtrRazYt
name = f'{str(count).zfill(3)}) «﹝Aditya﹞» {name1[:60]}' #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
if "youtu" in url: #Bot Created by @NtrRazYt
ytf = f"b[height<={raw_text2}][ext=mp4]/bv[height<={raw_text2}][ext=mp4]+ba[ext=m4a]/b[ext=mp4]" #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
ytf = f"b[height<={raw_text2}]/bv[height<={raw_text2}]+ba/b/bv+ba" #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
if "jw-prod" in url: #Bot Created by @NtrRazYt
cmd = f'yt-dlp -o "{name}.mp4" "{url}"' #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
cmd = f'yt-dlp -f "{ytf}" "{url}" -o "{name}.mp4"' #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
try: #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
cc = f'**{str(count).zfill(3)}). {name1} {res}.mkv**\n **Bᴀᴛᴄʜ : {b_name}**\n\n**Dᴏᴡɴʟᴏᴀᴅᴇᴅ Bʏ {MR}**\n\n' #Bot Created by @NtrRazYt
cc1 = f'**{str(count).zfill(3)}. {name1}.pdf**\n **Bᴀᴛᴄʜ : {b_name}**\n\n**Dᴏᴡɴʟᴏᴀᴅᴇᴅ Bʏ {MR}**\n' #Bot Created by @NtrRazYt
if "drive" in url: #Bot Created by @NtrRazYt
try: #Bot Created by @NtrRazYt
ka = await helper.download(url, name) #Bot Created by @NtrRazYt
copy = await bot.send_document(chat_id=m.chat.id,document=ka, caption=cc1) #Bot Created by @NtrRazYt
count+=1 #Bot Created by @NtrRazYt
os.remove(ka) #Bot Created by @NtrRazYt
time.sleep(1) #Bot Created by @NtrRazYt
except FloodWait as e: #Bot Created by @NtrRazYt
await m.reply_text(str(e)) #Bot Created by @NtrRazYt
time.sleep(e.x) #Bot Created by @NtrRazYt
continue #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
elif ".pdf" in url: #Bot Created by @NtrRazYt
try: #Bot Created by @NtrRazYt
cmd = f'yt-dlp -o "{name}.pdf" "{url}"' #Bot Created by @NtrRazYt
download_cmd = f"{cmd} -R 25 --fragment-retries 25" #Bot Created by @NtrRazYt
os.system(download_cmd) #Bot Created by @NtrRazYt
copy = await bot.send_document(chat_id=m.chat.id, document=f'{name}.pdf', caption=cc1) #Bot Created by @NtrRazYt
count += 1 #Bot Created by @NtrRazYt
os.remove(f'{name}.pdf') #Bot Created by @NtrRazYt
except FloodWait as e: #Bot Created by @NtrRazYt
await m.reply_text(str(e)) #Bot Created by @NtrRazYt
time.sleep(e.x) #Bot Created by @NtrRazYt
continue #Bot Created by @NtrRazYt
else: #Bot Created by @NtrRazYt
Show = f"**⬇️𝘿𝙊𝙒𝙉𝙇𝙊𝘼𝘿𝙄𝙉𝙂⬇️**\n\n**📝Name »** `{name}\n❄Quality » {raw_text2}`\n\n**🔗URL » {url}" #Bot Created by @NtrRazYt
prog = await m.reply_text(Show) #Bot Created by @NtrRazYt
res_file = await helper.download_video(url, cmd, name) #Bot Created by @NtrRazYt
filename = res_file #Bot Created by @NtrRazYt
await prog.delete(True) #Bot Created by @NtrRazYt
await helper.send_vid(bot, m, cc, filename, thumb, name, prog) #Bot Created by @NtrRazYt
count += 1 #Bot Created by @NtrRazYt
time.sleep(1) #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
except Exception as e: #Bot Created by @NtrRazYt
await m.reply_text( #Bot Created by @NtrRazYt
f"**downloading failed ❌**\n{str(e)}\n**Name** - {name}\n**Link** - `{url}`" #Bot Created by @NtrRazYt
) #Bot Created by @NtrRazYt
continue #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
except Exception as e: #Bot Created by @NtrRazYt
await m.reply_text(e) #Bot Created by @NtrRazYt
await m.reply_text("**Done✅**") #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt
bot.run() #Bot Created by @NtrRazYt
#Bot Created by @NtrRazYt