Skip to content

Commit

Permalink
v4.6.3 (breakdowns#47)
Browse files Browse the repository at this point in the history
- 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]>
  • Loading branch information
4 people authored Apr 12, 2021
1 parent 2e0dd53 commit 264b4db
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 42 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
# Slam Mirror Bot
This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive.

## Features supported:
<details>
<summary><b>Click here for more details</b></summary>
# Features supported:

- Mirroring direct download links to Google Drive
## Additional Features
- Mirroring Uptobox.com links to Google Drive (Uptobox account must be premium)
- Nyaa.si and Sukebei Torrent search
- Speedtest with picture results
- Check Heroku dynos stats
- Add stickers to your pack
- Shell and Executor

## From Source Repos
- Mirroring direct download links, Torrent, and Telegram files to Google Drive
- Mirroring Mega.nz links to Google Drive (In development stage)
- Mirroring Uptobox.com links to Google Drive (**NOTE**: Uptobox account must be premium)
- Copy files from someone's drive to your drive (Using Autorclone)
- Download/upload progress, speeds and ETAs
- Mirror all youtube-dl supported links
- Docker support
- Uploading To Team Drives.
- Uploading To Team Drives
- Index Link support
- Service account support
- Mirror all youtube-dl supported links
- Mirror telegram files
- Delete files from drive
- Add stickers to your pack
- Check Heroku dynos stats
- Nyaa.si and Sukebei Torrent search
- Shell and Executor
- Shortener support
- Custom Buttons
- Custom Filename (Only for url, telegram files and ytdl. Not for mega links and magnet/torrents)
- Speedtest with picture results
- Extracting password protected files and using custom filename see these examples:
> https://telegra.ph/Magneto-Python-Aria---Custom-Filename-Examples-01-20
- Extract these filetypes and uploads to google drive
Expand All @@ -37,8 +36,6 @@ HFS, LZH, LZMA, LZMA2, MBR, MSI, MSLZ, NSIS,
NTFS, RPM, SquashFS, UDF, VHD, XAR, Z.
```

</details>

## How to deploy?
Deploying is pretty much straight forward and is divided into several steps as follows:

Expand Down Expand Up @@ -90,6 +87,8 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
- **MEGA_EMAIL_ID**: Your email id you used to sign up on mega.nz for using premium accounts (Leave th)
- **MEGA_PASSWORD**: Your password for your mega.nz account
- **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)
- **ENABLE_FILESIZE_LIMIT**: Set it to `True` if you want to use `MAX_TORRENT_SIZE`.
- **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`.
- **BLOCK_MEGA_FOLDER**: (Optional field) If you want to remove mega.nz folder support, set it to `True`.
- **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`.
- **UPTOBOX_TOKEN**: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).
Expand Down Expand Up @@ -140,8 +139,9 @@ sudo docker run mirrorbot

## Deploying on Heroku

Give Star & Fork this repo, then upload **token.pickle** to your forks
Fork this repo, then upload **token.pickle** to your forks

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

## Deploying on Heroku using heroku-cli
Expand Down
10 changes: 10 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@
"description": "If you want to remove mega.nz mirror support, set it to True.",
"required": false
},
"ENABLE_FILESIZE_LIMIT": {
"description": "Set it to True if you want to use MAX_TORRENT_SIZE.",
"value": "false",
"required": true
},
"MAX_TORRENT_SIZE": {
"description": "To limit the torrent mirror size, Fill The amount you want to limit, examples: if you fill 15 it will limit 15gb.",
"value": "15",
"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
Expand Down
10 changes: 10 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,20 @@ def getConfig(name: str):
AUTO_DELETE_MESSAGE_DURATION = int(getConfig('AUTO_DELETE_MESSAGE_DURATION'))
TELEGRAM_API = getConfig('TELEGRAM_API')
TELEGRAM_HASH = getConfig('TELEGRAM_HASH')
MAX_TORRENT_SIZE = int(getConfig("MAX_TORRENT_SIZE"))
except KeyError as e:
LOGGER.error("One or more env variables missing! Exiting now")
exit(1)

try:
ENABLE_FILESIZE_LIMIT = getConfig('ENABLE_FILESIZE_LIMIT')
if ENABLE_FILESIZE_LIMIT.lower() == 'true':
ENABLE_FILESIZE_LIMIT = True
else:
ENABLE_FILESIZE_LIMIT = False
except KeyError:
ENABLE_FILESIZE_LIMIT = False

try:
if os.environ['USE_TELEGRAPH'].upper() == 'TRUE':
USE_TELEGRAPH = True
Expand Down
12 changes: 11 additions & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time
from telegram import ParseMode
from telegram.ext import CommandHandler, run_async
from bot import dispatcher, updater, botStartTime
from bot import dispatcher, updater, botStartTime, AUTHORIZED_CHATS
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 Down Expand Up @@ -49,6 +49,12 @@ def start(update, context):
'''
update.effective_message.reply_photo("https://telegra.ph/file/db03910496f06094f1f7a.jpg", start_string, parse_mode=ParseMode.MARKDOWN)

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


@run_async
def repo(update, context):
Expand Down Expand Up @@ -108,6 +114,8 @@ def bot_help(update, context):
/{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by owner of the bot)
/{BotCommands.AuthListCommand}: See Authorized list (Can only be invoked by owner of the bot)
/{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports
/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only).
Expand Down Expand Up @@ -148,13 +156,15 @@ def main():
log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)
repo_handler = CommandHandler(BotCommands.RepoCommand, repo,
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
authlist_handler = CommandHandler(BotCommands.AuthListCommand, chat_list, filters=CustomFilters.owner_filter, run_async=True)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(ping_handler)
dispatcher.add_handler(restart_handler)
dispatcher.add_handler(help_handler)
dispatcher.add_handler(stats_handler)
dispatcher.add_handler(log_handler)
dispatcher.add_handler(repo_handler)
dispatcher.add_handler(authlist_handler)
updater.start_polling()
LOGGER.info("Bot Started!")
signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
Expand Down
9 changes: 8 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,4 @@
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR, MAX_TORRENT_SIZE, ENABLE_FILESIZE_LIMIT
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.bot_utils import *
from .download_helper import DownloadHelper
Expand All @@ -22,6 +22,13 @@ def __onDownloadStarted(self, api, gid):
download = api.get_download(gid)
self.name = download.name
sname = download.name
if ENABLE_FILESIZE_LIMIT:
if download.total_length / 1024 / 1024 / 1024 > MAX_TORRENT_SIZE:
LOGGER.info(f" Download size Exceeded: {gid}")
dl.getListener().onDownloadError(f'File size larger than Maximum Allowed size {MAX_TORRENT_SIZE}GB')
aria2.remove([download])
return
update_all_messages()
gdrive = GoogleDriveHelper(None)
smsg, button = gdrive.drive_list(sname)
if STOP_DUPLICATE_MIRROR:
Expand Down
44 changes: 22 additions & 22 deletions bot/helper/mirror_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import requests
from bs4 import BeautifulSoup
from js2py import EvalJs

from bot.helper.ext_utils.exceptions import DirectDownloadLinkException

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

def zippy_share(url: str) -> str:
""" ZippyShare direct links generator
Based on https://github.com/LameLemon/ziggy"""
dl_url = ''
link = re.findall("https:/.(.*?).zippyshare", url)[0]
response_content = (requests.get(url)).content
bs_obj = BeautifulSoup(response_content, "lxml")

try:
link = re.findall(r'\bhttps?://.*zippyshare\.com\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("`No ZippyShare links found`\n")
session = requests.Session()
base_url = re.search('http.+.com', link).group()
response = session.get(link)
page_soup = BeautifulSoup(response.content, "lxml")
scripts = page_soup.find_all("script", {"type": "text/javascript"})
for script in scripts:
if "getElementById('dlbutton')" in script.text:
url_raw = re.search(r'= (?P<url>\".+\" \+ (?P<math>\(.+\)) .+);',
script.text).group('url')
math = re.search(r'= (?P<url>\".+\" \+ (?P<math>\(.+\)) .+);',
script.text).group('math')
dl_url = url_raw.replace(math, '"' + str(eval(math)) + '"')
break
dl_url = base_url + eval(dl_url)
name = urllib.parse.unquote(dl_url.split('/')[-1])
return dl_url
js_script = bs_obj.find("div", {"class": "center",}).find_all(
"script"
)[1]
except:
js_script = bs_obj.find("div", {"class": "right",}).find_all(
"script"
)[0]

js_content = re.findall(r'\.href.=."/(.*?)";', str(js_script))
js_content = 'var x = "/' + js_content[0] + '"'

evaljs = EvalJs()
setattr(evaljs, "x", None)
evaljs.execute(js_content)
js_content = getattr(evaljs, "x")

return f"https://{link}.zippyshare.com{js_content}"


def yandex_disk(url: str) -> str:
Expand Down
1 change: 1 addition & 0 deletions bot/helper/telegram_helper/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self):
self.StatusCommand = 'status'
self.AuthorizeCommand = 'authorize'
self.UnAuthorizeCommand = 'unauthorize'
self.AuthListCommand = 'authlist'
self.PingCommand = 'ping'
self.RestartCommand = 'restart'
self.StatsCommand = 'stats'
Expand Down
3 changes: 3 additions & 0 deletions config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ MEGA_PASSWORD = ""
BLOCK_MEGA_FOLDER = ""
BLOCK_MEGA_LINKS = ""
STOP_DUPLICATE_MIRROR = ""
MAX_TORRENT_SIZE = 15
#change ENABLE_FILESIZE_LIMIT = true if you want to use MAX_TORRENT_SIZE
ENABLE_FILESIZE_LIMIT = false
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aria2p>=0.9.0,<0.15.0
python-dotenv>=0.10
tenacity>=6.0.0
python-magic
beautifulsoup4>=4.8.2,<4.8.10
beautifulsoup4
pyrogram
TgCrypto
youtube_dl
Expand All @@ -20,5 +20,6 @@ heroku3
aiohttp
speedtest-cli
messages
js2py
lxml
telegraph

0 comments on commit 264b4db

Please sign in to comment.