Skip to content

Commit d393878

Browse files
committedMay 8, 2020
Remove broken direct download link extracters
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
1 parent 1d8c8ce commit d393878

File tree

3 files changed

+7
-112
lines changed

3 files changed

+7
-112
lines changed
 

‎.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "vendor/megadown"]
2-
path = vendor/megadown
3-
url = https://github.com/tonikelope/megadown.git
41
[submodule "vendor/cmrudl.py"]
52
path = vendor/cmrudl.py
63
url = https://github.com/JrMasterModelBuilder/cmrudl.py.git

‎bot/__main__.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sys import executable
77

88
from telegram.ext import CommandHandler, run_async
9-
from bot import dispatcher, updater, botStartTime, DOWNLOAD_DIR
9+
from bot import dispatcher, updater, botStartTime
1010
from bot.helper.ext_utils import fs_utils
1111
from bot.helper.telegram_helper.bot_commands import BotCommands
1212
from bot.helper.telegram_helper.message_utils import *
@@ -16,21 +16,21 @@
1616

1717

1818
@run_async
19-
def stats(update,context):
19+
def stats(update, context):
2020
currentTime = get_readable_time((time.time() - botStartTime))
2121
total, used, free = shutil.disk_usage('.')
2222
total = get_readable_file_size(total)
2323
used = get_readable_file_size(used)
2424
free = get_readable_file_size(free)
2525
stats = f'Bot Uptime: {currentTime}\n' \
2626
f'Total disk space: {total}\n' \
27-
f'Used: {used}\n' \
28-
f'Free: {free}'
27+
f'Used: {used}\n' \
28+
f'Free: {free}'
2929
sendMessage(stats, context.bot, update)
3030

3131

3232
@run_async
33-
def start(update,context):
33+
def start(update, context):
3434
sendMessage("This is a bot which can mirror all your links to Google drive!\n"
3535
"Type /help to get a list of available commands", context.bot, update)
3636

@@ -45,6 +45,7 @@ def restart(update, context):
4545
execl(executable, executable, "-m", "bot")
4646

4747

48+
@run_async
4849
def ping(update, context):
4950
start_time = int(round(time.time() * 1000))
5051
reply = sendMessage("Starting Ping", context.bot, update)
@@ -100,7 +101,7 @@ def main():
100101
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
101102
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
102103
restart_handler = CommandHandler(BotCommands.RestartCommand, restart,
103-
filters=CustomFilters.owner_filter)
104+
filters=CustomFilters.owner_filter)
104105
help_handler = CommandHandler(BotCommands.HelpCommand,
105106
bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
106107
stats_handler = CommandHandler(BotCommands.StatsCommand,

‎bot/helper/mirror_utils/download_utils/direct_link_generator.py

-103
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@ def direct_link_generator(link: str):
2424
""" direct links generator """
2525
if not link:
2626
raise DirectDownloadLinkException("`No links found!`")
27-
if 'drive.google.com' in link:
28-
return gdrive(link)
2927
elif 'zippyshare.com' in link:
3028
return zippy_share(link)
31-
elif 'mega.' in link:
32-
return mega_dl(link)
3329
elif 'yadi.sk' in link:
3430
return yandex_disk(link)
3531
elif 'cloud.mail.ru' in link:
@@ -40,49 +36,10 @@ def direct_link_generator(link: str):
4036
return osdn(link)
4137
elif 'github.com' in link:
4238
return github(link)
43-
elif 'androidfilehost.com' in link:
44-
return androidfilehost(link)
4539
else:
4640
raise DirectDownloadLinkException(f'No Direct link function found for {link}')
4741

4842

49-
def gdrive(url: str) -> str:
50-
""" GDrive direct links generator """
51-
drive = 'https://drive.google.com'
52-
try:
53-
link = re.findall(r'\bhttps?://drive\.google\.com\S+', url)[0]
54-
except IndexError:
55-
reply = "`No Google drive links found`\n"
56-
return reply
57-
file_id = ''
58-
if link.find("view") != -1:
59-
file_id = link.split('/')[-2]
60-
elif link.find("open?id=") != -1:
61-
file_id = link.split("open?id=")[1].strip()
62-
elif link.find("uc?id=") != -1:
63-
file_id = link.split("uc?id=")[1].strip()
64-
url = f'{drive}/uc?export=download&id={file_id}'
65-
download = requests.get(url, stream=True, allow_redirects=False)
66-
cookies = download.cookies
67-
try:
68-
# In case of small file size, Google downloads directly
69-
dl_url = download.headers["location"]
70-
if 'accounts.google.com' in dl_url: # non-public file
71-
raise DirectDownloadLinkException('`Link not public`')
72-
except KeyError:
73-
# In case of download warning page
74-
page = BeautifulSoup(download.content, 'lxml')
75-
export = drive + page.find('a', {'id': 'uc-download-link'}).get('href')
76-
response = requests.get(export,
77-
stream=True,
78-
allow_redirects=False,
79-
cookies=cookies)
80-
dl_url = response.headers['location']
81-
if 'accounts.google.com' in dl_url:
82-
raise DirectDownloadLinkException('`Link not public`')
83-
return dl_url
84-
85-
8643
def zippy_share(url: str) -> str:
8744
""" ZippyShare direct links generator
8845
Based on https://github.com/LameLemon/ziggy"""
@@ -125,23 +82,6 @@ def yandex_disk(url: str) -> str:
12582
raise DirectDownloadLinkException("`Error: File not found / Download limit reached`\n")
12683

12784

128-
def mega_dl(url: str) -> str:
129-
""" MEGA.nz direct links generator
130-
Using https://github.com/tonikelope/megadown"""
131-
try:
132-
link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', url)[0]
133-
except IndexError:
134-
raise DirectDownloadLinkException("`No MEGA.nz links found`\n")
135-
command = f'vendor/megadown/megadown -q -m {link}'
136-
result = popen(command).read()
137-
try:
138-
data = json.loads(result)
139-
except json.JSONDecodeError:
140-
raise DirectDownloadLinkException("`Error: Can't extract the link`\n")
141-
dl_url = data['url']
142-
return dl_url
143-
144-
14585
def cm_ru(url: str) -> str:
14686
""" cloud.mail.ru direct links generator
14787
Using https://github.com/JrMasterModelBuilder/cmrudl.py"""
@@ -206,49 +146,6 @@ def github(url: str) -> str:
206146
raise DirectDownloadLinkException("`Error: Can't extract the link`\n")
207147

208148

209-
def androidfilehost(url: str) -> str:
210-
""" AFH direct links generator """
211-
try:
212-
link = re.findall(r'\bhttps?://.*androidfilehost.*fid.*\S+', url)[0]
213-
except IndexError:
214-
raise DirectDownloadLinkException("`No AFH links found`\n")
215-
fid = re.findall(r'\?fid=(.*)', link)[0]
216-
session = requests.Session()
217-
user_agent = useragent()
218-
headers = {'user-agent': user_agent}
219-
res = session.get(link, headers=headers, allow_redirects=True)
220-
headers = {
221-
'origin': 'https://androidfilehost.com',
222-
'accept-encoding': 'gzip, deflate, br',
223-
'accept-language': 'en-US,en;q=0.9',
224-
'user-agent': user_agent,
225-
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
226-
'x-mod-sbb-ctype': 'xhr',
227-
'accept': '*/*',
228-
'referer': f'https://androidfilehost.com/?fid={fid}',
229-
'authority': 'androidfilehost.com',
230-
'x-requested-with': 'XMLHttpRequest',
231-
}
232-
data = {
233-
'submit': 'submit',
234-
'action': 'getdownloadmirrors',
235-
'fid': f'{fid}'
236-
}
237-
error = "`Error: Can't find Mirrors for the link`\n"
238-
try:
239-
req = session.post(
240-
'https://androidfilehost.com/libs/otf/mirrors.otf.php',
241-
headers=headers,
242-
data=data,
243-
cookies=res.cookies)
244-
mirrors = req.json()['MIRRORS']
245-
except (json.decoder.JSONDecodeError, TypeError):
246-
raise DirectDownloadLinkException(error)
247-
if not mirrors:
248-
raise DirectDownloadLinkException(error)
249-
return mirrors[0]
250-
251-
252149
def useragent():
253150
"""
254151
useragent random setter

0 commit comments

Comments
 (0)
Please sign in to comment.