Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.

Commit 2ba98ac

Browse files
authored
v3.7 (#14)
- Added Uptobox support - Check file in drive before mirror and stop duplicate mirror
1 parent def8e7b commit 2ba98ac

File tree

6 files changed

+78
-3
lines changed

6 files changed

+78
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Fork this repo, than upload credentials.json and token.pickle to your forks
3232

3333
## Features supported:
3434
- Mirroring direct download links to Google Drive
35-
- Mirroring Mega.nz links to google drive (In development stage)
35+
- Mirroring Mega.nz links to Google Drive (In development stage)
36+
- Mirroring Uptobox.com links to Google Drive (Uptobox account must be premium)
3637
- Copy files from someone's drive to your drive (Using Autorclone)
3738
- Download/upload progress
3839
- Download/upload speeds and ETAs

app.json

+8
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
"description": "This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org.",
6767
"required": true
6868
},
69+
"UPTOBOX_TOKEN": {
70+
"description": "Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).",
71+
"required": false
72+
},
6973
"MEGA_API_KEY": {
7074
"description": "Mega.nz api key to mirror mega.nz links. Get it from https://mega.nz/sdk.",
7175
"required": false
@@ -82,6 +86,10 @@
8286
"description": "If you want to remove mega.nz mirror support, set it to True.",
8387
"required": false
8488
},
89+
"STOP_DUPLICATE_MIRROR": {
90+
"description": "If this field is set to True, bot will check file in drive, if it is present in drive, downloading will be stopped.",
91+
"required": false
92+
},
8593
"SHORTENER": {
8694
"description": "If you want to use shortener in Gdrive and index link.",
8795
"required": false

bot/__init__.py

+18
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ def getConfig(name: str):
9090
LOGGER.error("One or more env variables missing! Exiting now")
9191
exit(1)
9292

93+
try:
94+
UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN')
95+
except KeyError:
96+
logging.warning('UPTOBOX_TOKEN not provided!')
97+
UPTOBOX_TOKEN = None
98+
try:
99+
UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN')
100+
except KeyError:
101+
logging.warning('UPTOBOX_TOKEN not provided!')
102+
UPTOBOX_TOKEN = None
93103
try:
94104
MEGA_API_KEY = getConfig('MEGA_API_KEY')
95105
except KeyError:
@@ -160,6 +170,14 @@ def getConfig(name: str):
160170
except KeyError:
161171
BUTTON_FIVE_NAME = None
162172
BUTTON_FIVE_URL = None
173+
try:
174+
STOP_DUPLICATE_MIRROR = getConfig('STOP_DUPLICATE_MIRROR')
175+
if STOP_DUPLICATE_MIRROR.lower() == 'true':
176+
STOP_DUPLICATE_MIRROR = True
177+
else:
178+
STOP_DUPLICATE_MIRROR = False
179+
except KeyError:
180+
STOP_DUPLICATE_MIRROR = False
163181
try:
164182
IS_TEAM_DRIVE = getConfig('IS_TEAM_DRIVE')
165183
if IS_TEAM_DRIVE.lower() == 'true':

bot/helper/mirror_utils/download_utils/aria2_download.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from bot import aria2, download_dict_lock
1+
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR
2+
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
23
from bot.helper.ext_utils.bot_utils import *
34
from .download_helper import DownloadHelper
45
from bot.helper.mirror_utils.status_utils.aria_download_status import AriaDownloadStatus
@@ -15,7 +16,25 @@ def __init__(self):
1516

1617
@new_thread
1718
def __onDownloadStarted(self, api, gid):
19+
sleep(1)
1820
LOGGER.info(f"onDownloadStart: {gid}")
21+
dl = getDownloadByGid(gid)
22+
download = api.get_download(gid)
23+
self.name = download.name
24+
sname = download.name
25+
if STOP_DUPLICATE_MIRROR:
26+
if dl.getListener().isTar == True:
27+
sname = sname + ".tar"
28+
if dl.getListener().extract == True:
29+
smsg = None
30+
else:
31+
gdrive = GoogleDriveHelper(None)
32+
smsg, button = gdrive.drive_list(sname)
33+
if smsg:
34+
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')
35+
sendMarkup(" Here are the search results:👇", dl.getListener().bot, dl.getListener().update, button)
36+
aria2.remove([download])
37+
return
1938
update_all_messages()
2039

2140
def __onDownloadComplete(self, api: API, gid):

bot/helper/mirror_utils/download_utils/direct_link_generator.py

+27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
than the modifications. See https://github.com/AvinashReddy3108/PaperplaneExtended/commits/master/userbot/modules/direct_links.py
99
for original authorship. """
1010

11+
from bot import UPTOBOX_TOKEN
12+
import logging
1113
import json
1214
import re
1315
import urllib.parse
@@ -32,6 +34,8 @@ def direct_link_generator(link: str):
3234
return cm_ru(link)
3335
elif 'mediafire.com' in link:
3436
return mediafire(link)
37+
elif 'uptobox.com' in link:
38+
return uptobox(link)
3539
elif 'osdn.net' in link:
3640
return osdn(link)
3741
elif 'github.com' in link:
@@ -100,6 +104,29 @@ def cm_ru(url: str) -> str:
100104
dl_url = data['download']
101105
return dl_url
102106

107+
def uptobox(url: str) -> str:
108+
""" Uptobox direct links generator
109+
based on https://github.com/jovanzers/WinTenCermin """
110+
try:
111+
link = re.findall(r'\bhttps?://.*uptobox\.com\S+', url)[0]
112+
except IndexError:
113+
raise DirectDownloadLinkException("`No Uptobox links found`\n")
114+
if UPTOBOX_TOKEN is None:
115+
logging.error('UPTOBOX_TOKEN not provided!')
116+
dl_url = url
117+
else:
118+
try:
119+
link = re.findall(r'\bhttp?://.*uptobox\.com/dl\S+', url)[0]
120+
logging.info('Uptobox direct link')
121+
dl_url = url
122+
except:
123+
file_id = re.findall(r'\bhttps?://.*uptobox\.com/(\w+)', url)[0]
124+
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s' % (UPTOBOX_TOKEN, file_id)
125+
req = requests.get(file_link)
126+
result = req.json()
127+
dl_url = result['data']['dlLink']
128+
return dl_url
129+
103130

104131
def mediafire(url: str) -> str:
105132
""" MediaFire direct links generator """

config_sample.env

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ TELEGRAM_HASH = ""
1414
USE_SERVICE_ACCOUNTS = ""
1515
# Optional config
1616
AUTHORIZED_CHATS = ""
17-
INDEX_URL = ""
17+
INDEX_URL = ""
18+
UPTOBOX_TOKEN = ""
1819
MEGA_API_KEY = ""
1920
MEGA_EMAIL_ID = ""
2021
MEGA_PASSWORD = ""
2122
BLOCK_MEGA_LINKS = ""
23+
STOP_DUPLICATE_MIRROR = ""
2224
SHORTENER = ""
2325
SHORTENER_API = ""
2426
# Add more buttons (two buttons are already added of file link and index link, you can add extra buttons too, these are optional)

0 commit comments

Comments
 (0)