Skip to content

Commit

Permalink
v3.7 (breakdowns#14)
Browse files Browse the repository at this point in the history
- Added Uptobox support
- Check file in drive before mirror and stop duplicate mirror
  • Loading branch information
breakdowns authored Mar 6, 2021
1 parent def8e7b commit 2ba98ac
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Fork this repo, than upload credentials.json and token.pickle to your forks

## Features supported:
- Mirroring direct download links to Google Drive
- Mirroring Mega.nz links to google drive (In development stage)
- Mirroring Mega.nz links to Google Drive (In development stage)
- Mirroring Uptobox.com links to Google Drive (Uptobox account must be premium)
- Copy files from someone's drive to your drive (Using Autorclone)
- Download/upload progress
- Download/upload speeds and ETAs
Expand Down
8 changes: 8 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
"description": "This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org.",
"required": true
},
"UPTOBOX_TOKEN": {
"description": "Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).",
"required": false
},
"MEGA_API_KEY": {
"description": "Mega.nz api key to mirror mega.nz links. Get it from https://mega.nz/sdk.",
"required": false
Expand All @@ -82,6 +86,10 @@
"description": "If you want to remove mega.nz mirror support, set it to True.",
"required": false
},
"STOP_DUPLICATE_MIRROR": {
"description": "If this field is set to True, bot will check file in drive, if it is present in drive, downloading will be stopped.",
"required": false
},
"SHORTENER": {
"description": "If you want to use shortener in Gdrive and index link.",
"required": false
Expand Down
18 changes: 18 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ def getConfig(name: str):
LOGGER.error("One or more env variables missing! Exiting now")
exit(1)

try:
UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN')
except KeyError:
logging.warning('UPTOBOX_TOKEN not provided!')
UPTOBOX_TOKEN = None
try:
UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN')
except KeyError:
logging.warning('UPTOBOX_TOKEN not provided!')
UPTOBOX_TOKEN = None
try:
MEGA_API_KEY = getConfig('MEGA_API_KEY')
except KeyError:
Expand Down Expand Up @@ -160,6 +170,14 @@ def getConfig(name: str):
except KeyError:
BUTTON_FIVE_NAME = None
BUTTON_FIVE_URL = None
try:
STOP_DUPLICATE_MIRROR = getConfig('STOP_DUPLICATE_MIRROR')
if STOP_DUPLICATE_MIRROR.lower() == 'true':
STOP_DUPLICATE_MIRROR = True
else:
STOP_DUPLICATE_MIRROR = False
except KeyError:
STOP_DUPLICATE_MIRROR = False
try:
IS_TEAM_DRIVE = getConfig('IS_TEAM_DRIVE')
if IS_TEAM_DRIVE.lower() == 'true':
Expand Down
21 changes: 20 additions & 1 deletion bot/helper/mirror_utils/download_utils/aria2_download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from bot import aria2, download_dict_lock
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.bot_utils import *
from .download_helper import DownloadHelper
from bot.helper.mirror_utils.status_utils.aria_download_status import AriaDownloadStatus
Expand All @@ -15,7 +16,25 @@ def __init__(self):

@new_thread
def __onDownloadStarted(self, api, gid):
sleep(1)
LOGGER.info(f"onDownloadStart: {gid}")
dl = getDownloadByGid(gid)
download = api.get_download(gid)
self.name = download.name
sname = download.name
if STOP_DUPLICATE_MIRROR:
if dl.getListener().isTar == True:
sname = sname + ".tar"
if dl.getListener().extract == True:
smsg = None
else:
gdrive = GoogleDriveHelper(None)
smsg, button = gdrive.drive_list(sname)
if smsg:
dl.getListener().onDownloadError(f'😡 File is already available in drive. You should have search before mirror any file. You might get ban if you do this again. This download has been stopped.\n\n')
sendMarkup(" Here are the search results:👇", dl.getListener().bot, dl.getListener().update, button)
aria2.remove([download])
return
update_all_messages()

def __onDownloadComplete(self, api: API, gid):
Expand Down
27 changes: 27 additions & 0 deletions bot/helper/mirror_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
than the modifications. See https://github.com/AvinashReddy3108/PaperplaneExtended/commits/master/userbot/modules/direct_links.py
for original authorship. """

from bot import UPTOBOX_TOKEN
import logging
import json
import re
import urllib.parse
Expand All @@ -32,6 +34,8 @@ def direct_link_generator(link: str):
return cm_ru(link)
elif 'mediafire.com' in link:
return mediafire(link)
elif 'uptobox.com' in link:
return uptobox(link)
elif 'osdn.net' in link:
return osdn(link)
elif 'github.com' in link:
Expand Down Expand Up @@ -100,6 +104,29 @@ def cm_ru(url: str) -> str:
dl_url = data['download']
return dl_url

def uptobox(url: str) -> str:
""" Uptobox direct links generator
based on https://github.com/jovanzers/WinTenCermin """
try:
link = re.findall(r'\bhttps?://.*uptobox\.com\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("`No Uptobox links found`\n")
if UPTOBOX_TOKEN is None:
logging.error('UPTOBOX_TOKEN not provided!')
dl_url = url
else:
try:
link = re.findall(r'\bhttp?://.*uptobox\.com/dl\S+', url)[0]
logging.info('Uptobox direct link')
dl_url = url
except:
file_id = re.findall(r'\bhttps?://.*uptobox\.com/(\w+)', url)[0]
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s' % (UPTOBOX_TOKEN, file_id)
req = requests.get(file_link)
result = req.json()
dl_url = result['data']['dlLink']
return dl_url


def mediafire(url: str) -> str:
""" MediaFire direct links generator """
Expand Down
4 changes: 3 additions & 1 deletion config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ TELEGRAM_HASH = ""
USE_SERVICE_ACCOUNTS = ""
# Optional config
AUTHORIZED_CHATS = ""
INDEX_URL = ""
INDEX_URL = ""
UPTOBOX_TOKEN = ""
MEGA_API_KEY = ""
MEGA_EMAIL_ID = ""
MEGA_PASSWORD = ""
BLOCK_MEGA_LINKS = ""
STOP_DUPLICATE_MIRROR = ""
SHORTENER = ""
SHORTENER_API = ""
# Add more buttons (two buttons are already added of file link and index link, you can add extra buttons too, these are optional)
Expand Down

0 comments on commit 2ba98ac

Please sign in to comment.