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

Commit 264b4db

Browse files
breakdownsSVR666brutewooorseKenHV
authored
v4.6.3 (#47)
- Added /authlist command, to see Authorized list - Add ability to limit when mirroring torrent - Fixed Zippyshare Co-authored-by: Sreeraj V R <[email protected]> Co-authored-by: BruteWoorse <[email protected]> Co-authored-by: KenHV <[email protected]>
1 parent 2e0dd53 commit 264b4db

File tree

9 files changed

+84
-42
lines changed

9 files changed

+84
-42
lines changed

README.md

+17-17
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@
33
# Slam Mirror Bot
44
This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive.
55

6-
## Features supported:
7-
<details>
8-
<summary><b>Click here for more details</b></summary>
6+
# Features supported:
97

10-
- Mirroring direct download links to Google Drive
8+
## Additional Features
9+
- Mirroring Uptobox.com links to Google Drive (Uptobox account must be premium)
10+
- Nyaa.si and Sukebei Torrent search
11+
- Speedtest with picture results
12+
- Check Heroku dynos stats
13+
- Add stickers to your pack
14+
- Shell and Executor
15+
16+
## From Source Repos
17+
- Mirroring direct download links, Torrent, and Telegram files to Google Drive
1118
- Mirroring Mega.nz links to Google Drive (In development stage)
12-
- Mirroring Uptobox.com links to Google Drive (**NOTE**: Uptobox account must be premium)
1319
- Copy files from someone's drive to your drive (Using Autorclone)
1420
- Download/upload progress, speeds and ETAs
21+
- Mirror all youtube-dl supported links
1522
- Docker support
16-
- Uploading To Team Drives.
23+
- Uploading To Team Drives
1724
- Index Link support
1825
- Service account support
19-
- Mirror all youtube-dl supported links
20-
- Mirror telegram files
2126
- Delete files from drive
22-
- Add stickers to your pack
23-
- Check Heroku dynos stats
24-
- Nyaa.si and Sukebei Torrent search
25-
- Shell and Executor
2627
- Shortener support
27-
- Custom Buttons
2828
- Custom Filename (Only for url, telegram files and ytdl. Not for mega links and magnet/torrents)
29-
- Speedtest with picture results
3029
- Extracting password protected files and using custom filename see these examples:
3130
> https://telegra.ph/Magneto-Python-Aria---Custom-Filename-Examples-01-20
3231
- Extract these filetypes and uploads to google drive
@@ -37,8 +36,6 @@ HFS, LZH, LZMA, LZMA2, MBR, MSI, MSLZ, NSIS,
3736
NTFS, RPM, SquashFS, UDF, VHD, XAR, Z.
3837
```
3938

40-
</details>
41-
4239
## How to deploy?
4340
Deploying is pretty much straight forward and is divided into several steps as follows:
4441

@@ -90,6 +87,8 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
9087
- **MEGA_EMAIL_ID**: Your email id you used to sign up on mega.nz for using premium accounts (Leave th)
9188
- **MEGA_PASSWORD**: Your password for your mega.nz account
9289
- **STOP_DUPLICATE_MIRROR**: (Optional field) (Leave empty if unsure) if this field is set to `True` , bot will check file in drive, if it is present in drive, downloading will ne stopped. (Note - File will be checked using filename, not using filehash, so this feature is not perfect yet)
90+
- **ENABLE_FILESIZE_LIMIT**: Set it to `True` if you want to use `MAX_TORRENT_SIZE`.
91+
- **MAX_TORRENT_SIZE**: To limit the torrent mirror size, Fill The amount you want to limit, examples: if you fill `15` it will limit `15gb`.
9392
- **BLOCK_MEGA_FOLDER**: (Optional field) If you want to remove mega.nz folder support, set it to `True`.
9493
- **BLOCK_MEGA_LINKS**: (Optional field) If you want to remove mega.nz mirror support (bcoz it's too much buggy and unstable), set it to `True`.
9594
- **UPTOBOX_TOKEN**: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).
@@ -140,8 +139,9 @@ sudo docker run mirrorbot
140139

141140
## Deploying on Heroku
142141

143-
Give Star & Fork this repo, then upload **token.pickle** to your forks
142+
Fork this repo, then upload **token.pickle** to your forks
144143

144+
**NOTE**: If you didn't upload **token.pickle** upload will not working
145145
<p><a href="https://heroku.com/deploy"> <img src="https://www.herokucdn.com/deploy/button.svg" alt="Deploy to Heroku" /></a></p>
146146

147147
## Deploying on Heroku using heroku-cli

app.json

+10
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@
103103
"description": "If you want to remove mega.nz mirror support, set it to True.",
104104
"required": false
105105
},
106+
"ENABLE_FILESIZE_LIMIT": {
107+
"description": "Set it to True if you want to use MAX_TORRENT_SIZE.",
108+
"value": "false",
109+
"required": true
110+
},
111+
"MAX_TORRENT_SIZE": {
112+
"description": "To limit the torrent mirror size, Fill The amount you want to limit, examples: if you fill 15 it will limit 15gb.",
113+
"value": "15",
114+
"required": false
115+
},
106116
"STOP_DUPLICATE_MIRROR": {
107117
"description": "If this field is set to True, bot will check file in drive, if it is present in drive, downloading will be stopped.",
108118
"required": false

bot/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,20 @@ def getConfig(name: str):
8686
AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION'))
8787
TELEGRAM_API = getConfig('TELEGRAM_API')
8888
TELEGRAM_HASH = getConfig('TELEGRAM_HASH')
89+
MAX_TORRENT_SIZE = int(getConfig("MAX_TORRENT_SIZE"))
8990
except KeyError as e:
9091
LOGGER.error("One or more env variables missing! Exiting now")
9192
exit(1)
9293

94+
try:
95+
ENABLE_FILESIZE_LIMIT = getConfig('ENABLE_FILESIZE_LIMIT')
96+
if ENABLE_FILESIZE_LIMIT.lower() == 'true':
97+
ENABLE_FILESIZE_LIMIT = True
98+
else:
99+
ENABLE_FILESIZE_LIMIT = False
100+
except KeyError:
101+
ENABLE_FILESIZE_LIMIT = False
102+
93103
try:
94104
if os.environ['USE_TELEGRAPH'].upper() == 'TRUE':
95105
USE_TELEGRAPH = True

bot/__main__.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import time
99
from telegram import ParseMode
1010
from telegram.ext import CommandHandler, run_async
11-
from bot import dispatcher, updater, botStartTime
11+
from bot import dispatcher, updater, botStartTime, AUTHORIZED_CHATS
1212
from bot.helper.ext_utils import fs_utils
1313
from bot.helper.telegram_helper.bot_commands import BotCommands
1414
from bot.helper.telegram_helper.message_utils import *
@@ -49,6 +49,12 @@ def start(update, context):
4949
'''
5050
update.effective_message.reply_photo("https://telegra.ph/file/db03910496f06094f1f7a.jpg", start_string, parse_mode=ParseMode.MARKDOWN)
5151

52+
@run_async
53+
def chat_list(update, context):
54+
chatlist =''
55+
chatlist += '\n'.join(str(id) for id in AUTHORIZED_CHATS)
56+
sendMessage(f'<b>Authorized List:</b>\n{chatlist}\n', context.bot, update)
57+
5258

5359
@run_async
5460
def repo(update, context):
@@ -108,6 +114,8 @@ def bot_help(update, context):
108114
109115
/{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by owner of the bot)
110116
117+
/{BotCommands.AuthListCommand}: See Authorized list (Can only be invoked by owner of the bot)
118+
111119
/{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports
112120
113121
/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only).
@@ -148,13 +156,15 @@ def main():
148156
log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)
149157
repo_handler = CommandHandler(BotCommands.RepoCommand, repo,
150158
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
159+
authlist_handler = CommandHandler(BotCommands.AuthListCommand, chat_list, filters=CustomFilters.owner_filter, run_async=True)
151160
dispatcher.add_handler(start_handler)
152161
dispatcher.add_handler(ping_handler)
153162
dispatcher.add_handler(restart_handler)
154163
dispatcher.add_handler(help_handler)
155164
dispatcher.add_handler(stats_handler)
156165
dispatcher.add_handler(log_handler)
157166
dispatcher.add_handler(repo_handler)
167+
dispatcher.add_handler(authlist_handler)
158168
updater.start_polling()
159169
LOGGER.info("Bot Started!")
160170
signal.signal(signal.SIGINT, fs_utils.exit_clean_up)

bot/helper/mirror_utils/download_utils/aria2_download.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR
1+
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR, MAX_TORRENT_SIZE, ENABLE_FILESIZE_LIMIT
22
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
33
from bot.helper.ext_utils.bot_utils import *
44
from .download_helper import DownloadHelper
@@ -22,6 +22,13 @@ def __onDownloadStarted(self, api, gid):
2222
download = api.get_download(gid)
2323
self.name = download.name
2424
sname = download.name
25+
if ENABLE_FILESIZE_LIMIT:
26+
if download.total_length / 1024 / 1024 / 1024 > MAX_TORRENT_SIZE:
27+
LOGGER.info(f" Download size Exceeded: {gid}")
28+
dl.getListener().onDownloadError(f'File size larger than Maximum Allowed size {MAX_TORRENT_SIZE}GB')
29+
aria2.remove([download])
30+
return
31+
update_all_messages()
2532
gdrive = GoogleDriveHelper(None)
2633
smsg, button = gdrive.drive_list(sname)
2734
if STOP_DUPLICATE_MIRROR:

bot/helper/mirror_utils/download_utils/direct_link_generator.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import requests
2121
from bs4 import BeautifulSoup
22+
from js2py import EvalJs
2223

2324
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException
2425

@@ -45,29 +46,28 @@ def direct_link_generator(link: str):
4546
raise DirectDownloadLinkException(f'No Direct link function found for {link}')
4647

4748
def zippy_share(url: str) -> str:
48-
""" ZippyShare direct links generator
49-
Based on https://github.com/LameLemon/ziggy"""
50-
dl_url = ''
49+
link = re.findall("https:/.(.*?).zippyshare", url)[0]
50+
response_content = (requests.get(url)).content
51+
bs_obj = BeautifulSoup(response_content, "lxml")
52+
5153
try:
52-
link = re.findall(r'\bhttps?://.*zippyshare\.com\S+', url)[0]
53-
except IndexError:
54-
raise DirectDownloadLinkException("`No ZippyShare links found`\n")
55-
session = requests.Session()
56-
base_url = re.search('http.+.com', link).group()
57-
response = session.get(link)
58-
page_soup = BeautifulSoup(response.content, "lxml")
59-
scripts = page_soup.find_all("script", {"type": "text/javascript"})
60-
for script in scripts:
61-
if "getElementById('dlbutton')" in script.text:
62-
url_raw = re.search(r'= (?P<url>\".+\" \+ (?P<math>\(.+\)) .+);',
63-
script.text).group('url')
64-
math = re.search(r'= (?P<url>\".+\" \+ (?P<math>\(.+\)) .+);',
65-
script.text).group('math')
66-
dl_url = url_raw.replace(math, '"' + str(eval(math)) + '"')
67-
break
68-
dl_url = base_url + eval(dl_url)
69-
name = urllib.parse.unquote(dl_url.split('/')[-1])
70-
return dl_url
54+
js_script = bs_obj.find("div", {"class": "center",}).find_all(
55+
"script"
56+
)[1]
57+
except:
58+
js_script = bs_obj.find("div", {"class": "right",}).find_all(
59+
"script"
60+
)[0]
61+
62+
js_content = re.findall(r'\.href.=."/(.*?)";', str(js_script))
63+
js_content = 'var x = "/' + js_content[0] + '"'
64+
65+
evaljs = EvalJs()
66+
setattr(evaljs, "x", None)
67+
evaljs.execute(js_content)
68+
js_content = getattr(evaljs, "x")
69+
70+
return f"https://{link}.zippyshare.com{js_content}"
7171

7272

7373
def yandex_disk(url: str) -> str:

bot/helper/telegram_helper/bot_commands.py

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def __init__(self):
1010
self.StatusCommand = 'status'
1111
self.AuthorizeCommand = 'authorize'
1212
self.UnAuthorizeCommand = 'unauthorize'
13+
self.AuthListCommand = 'authlist'
1314
self.PingCommand = 'ping'
1415
self.RestartCommand = 'restart'
1516
self.StatsCommand = 'stats'

config_sample.env

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ MEGA_PASSWORD = ""
2323
BLOCK_MEGA_FOLDER = ""
2424
BLOCK_MEGA_LINKS = ""
2525
STOP_DUPLICATE_MIRROR = ""
26+
MAX_TORRENT_SIZE = 15
27+
#change ENABLE_FILESIZE_LIMIT = true if you want to use MAX_TORRENT_SIZE
28+
ENABLE_FILESIZE_LIMIT = false
2629
SHORTENER = ""
2730
SHORTENER_API = ""
2831
# Add more buttons (two buttons are already added of file link and index link, you can add extra buttons too, these are optional)

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ aria2p>=0.9.0,<0.15.0
1010
python-dotenv>=0.10
1111
tenacity>=6.0.0
1212
python-magic
13-
beautifulsoup4>=4.8.2,<4.8.10
13+
beautifulsoup4
1414
pyrogram
1515
TgCrypto
1616
youtube_dl
@@ -20,5 +20,6 @@ heroku3
2020
aiohttp
2121
speedtest-cli
2222
messages
23+
js2py
2324
lxml
2425
telegraph

0 commit comments

Comments
 (0)