Skip to content

Commit

Permalink
Remove broken direct download link extracters
Browse files Browse the repository at this point in the history
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
  • Loading branch information
lzzy12 committed May 8, 2020
1 parent 1d8c8ce commit d393878
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 112 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "vendor/megadown"]
path = vendor/megadown
url = https://github.com/tonikelope/megadown.git
[submodule "vendor/cmrudl.py"]
path = vendor/cmrudl.py
url = https://github.com/JrMasterModelBuilder/cmrudl.py.git
13 changes: 7 additions & 6 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sys import executable

from telegram.ext import CommandHandler, run_async
from bot import dispatcher, updater, botStartTime, DOWNLOAD_DIR
from bot import dispatcher, updater, botStartTime
from bot.helper.ext_utils import fs_utils
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.message_utils import *
Expand All @@ -16,21 +16,21 @@


@run_async
def stats(update,context):
def stats(update, context):
currentTime = get_readable_time((time.time() - botStartTime))
total, used, free = shutil.disk_usage('.')
total = get_readable_file_size(total)
used = get_readable_file_size(used)
free = get_readable_file_size(free)
stats = f'Bot Uptime: {currentTime}\n' \
f'Total disk space: {total}\n' \
f'Used: {used}\n' \
f'Free: {free}'
f'Used: {used}\n' \
f'Free: {free}'
sendMessage(stats, context.bot, update)


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

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


@run_async
def ping(update, context):
start_time = int(round(time.time() * 1000))
reply = sendMessage("Starting Ping", context.bot, update)
Expand Down Expand Up @@ -100,7 +101,7 @@ def main():
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
restart_handler = CommandHandler(BotCommands.RestartCommand, restart,
filters=CustomFilters.owner_filter)
filters=CustomFilters.owner_filter)
help_handler = CommandHandler(BotCommands.HelpCommand,
bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
stats_handler = CommandHandler(BotCommands.StatsCommand,
Expand Down
103 changes: 0 additions & 103 deletions bot/helper/mirror_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ def direct_link_generator(link: str):
""" direct links generator """
if not link:
raise DirectDownloadLinkException("`No links found!`")
if 'drive.google.com' in link:
return gdrive(link)
elif 'zippyshare.com' in link:
return zippy_share(link)
elif 'mega.' in link:
return mega_dl(link)
elif 'yadi.sk' in link:
return yandex_disk(link)
elif 'cloud.mail.ru' in link:
Expand All @@ -40,49 +36,10 @@ def direct_link_generator(link: str):
return osdn(link)
elif 'github.com' in link:
return github(link)
elif 'androidfilehost.com' in link:
return androidfilehost(link)
else:
raise DirectDownloadLinkException(f'No Direct link function found for {link}')


def gdrive(url: str) -> str:
""" GDrive direct links generator """
drive = 'https://drive.google.com'
try:
link = re.findall(r'\bhttps?://drive\.google\.com\S+', url)[0]
except IndexError:
reply = "`No Google drive links found`\n"
return reply
file_id = ''
if link.find("view") != -1:
file_id = link.split('/')[-2]
elif link.find("open?id=") != -1:
file_id = link.split("open?id=")[1].strip()
elif link.find("uc?id=") != -1:
file_id = link.split("uc?id=")[1].strip()
url = f'{drive}/uc?export=download&id={file_id}'
download = requests.get(url, stream=True, allow_redirects=False)
cookies = download.cookies
try:
# In case of small file size, Google downloads directly
dl_url = download.headers["location"]
if 'accounts.google.com' in dl_url: # non-public file
raise DirectDownloadLinkException('`Link not public`')
except KeyError:
# In case of download warning page
page = BeautifulSoup(download.content, 'lxml')
export = drive + page.find('a', {'id': 'uc-download-link'}).get('href')
response = requests.get(export,
stream=True,
allow_redirects=False,
cookies=cookies)
dl_url = response.headers['location']
if 'accounts.google.com' in dl_url:
raise DirectDownloadLinkException('`Link not public`')
return dl_url


def zippy_share(url: str) -> str:
""" ZippyShare direct links generator
Based on https://github.com/LameLemon/ziggy"""
Expand Down Expand Up @@ -125,23 +82,6 @@ def yandex_disk(url: str) -> str:
raise DirectDownloadLinkException("`Error: File not found / Download limit reached`\n")


def mega_dl(url: str) -> str:
""" MEGA.nz direct links generator
Using https://github.com/tonikelope/megadown"""
try:
link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("`No MEGA.nz links found`\n")
command = f'vendor/megadown/megadown -q -m {link}'
result = popen(command).read()
try:
data = json.loads(result)
except json.JSONDecodeError:
raise DirectDownloadLinkException("`Error: Can't extract the link`\n")
dl_url = data['url']
return dl_url


def cm_ru(url: str) -> str:
""" cloud.mail.ru direct links generator
Using https://github.com/JrMasterModelBuilder/cmrudl.py"""
Expand Down Expand Up @@ -206,49 +146,6 @@ def github(url: str) -> str:
raise DirectDownloadLinkException("`Error: Can't extract the link`\n")


def androidfilehost(url: str) -> str:
""" AFH direct links generator """
try:
link = re.findall(r'\bhttps?://.*androidfilehost.*fid.*\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("`No AFH links found`\n")
fid = re.findall(r'\?fid=(.*)', link)[0]
session = requests.Session()
user_agent = useragent()
headers = {'user-agent': user_agent}
res = session.get(link, headers=headers, allow_redirects=True)
headers = {
'origin': 'https://androidfilehost.com',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'en-US,en;q=0.9',
'user-agent': user_agent,
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'x-mod-sbb-ctype': 'xhr',
'accept': '*/*',
'referer': f'https://androidfilehost.com/?fid={fid}',
'authority': 'androidfilehost.com',
'x-requested-with': 'XMLHttpRequest',
}
data = {
'submit': 'submit',
'action': 'getdownloadmirrors',
'fid': f'{fid}'
}
error = "`Error: Can't find Mirrors for the link`\n"
try:
req = session.post(
'https://androidfilehost.com/libs/otf/mirrors.otf.php',
headers=headers,
data=data,
cookies=res.cookies)
mirrors = req.json()['MIRRORS']
except (json.decoder.JSONDecodeError, TypeError):
raise DirectDownloadLinkException(error)
if not mirrors:
raise DirectDownloadLinkException(error)
return mirrors[0]


def useragent():
"""
useragent random setter
Expand Down

0 comments on commit d393878

Please sign in to comment.