Skip to content

Commit

Permalink
v4.7.1 (breakdowns#82)
Browse files Browse the repository at this point in the history
- Revert to megasdk
- Added Estimated Dyno Expired in usage command

Co-authored-by: Ncode2014 <[email protected]>
  • Loading branch information
breakdowns and Ncode2014 authored May 8, 2021
1 parent d3b8ac6 commit 9612d99
Show file tree
Hide file tree
Showing 18 changed files with 298 additions and 227 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ data*
authorized_chats.txt
log.txt
accounts/*
venv/
File renamed without changes.
5 changes: 1 addition & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ FROM ubuntu:20.04
WORKDIR /usr/src/app
RUN chmod 777 /usr/src/app
RUN apt-get -qq update && \
apt-get upgrade -y && apt-get autoremove -y && \
DEBIAN_FRONTEND="noninteractive" apt-get -qq install -y tzdata aria2 wget git python3 python3-pip \
DEBIAN_FRONTEND="noninteractive" apt-get -qq install -y tzdata aria2 git python3 python3-pip \
locales python3-lxml \
curl pv jq ffmpeg \
p7zip-full p7zip-rar \
Expand All @@ -18,8 +17,6 @@ COPY requirements.txt .
COPY extract /usr/local/bin
COPY pextract /usr/local/bin
RUN chmod +x /usr/local/bin/extract && chmod +x /usr/local/bin/pextract
RUN wget -q https://github.com/P3TERX/aria2.conf/raw/master/dht.dat -O /usr/src/app/dht.dat && \
wget -q https://github.com/P3TERX/aria2.conf/raw/master/dht6.dat -O /usr/src/app/dht6.dat
RUN pip3 install --no-cache-dir -r requirements.txt
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is a telegram bot writen in python for mirroring files on the internet to o

## From Source Repos
- Mirroring direct download links, Torrent, and Telegram files to Google Drive
- Mirroring Mega.nz links to google drive
- Mirroring Mega.nz links to Google Drive (If your Mega account not premium, it will limit 4-5gb/day)
- Copy files from someone's drive to your drive (Using Autorclone)
- Download/upload progress, speeds and ETAs
- Mirror all youtube-dl supported links
Expand Down Expand Up @@ -92,12 +92,13 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
- **INDEX_URL**: (Optional field) Refer to https://github.com/maple3142/GDIndex/ The URL should not have any trailing '/'
- **API_KEY**: This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org DO NOT put this in quotes.
- **API_HASH**: This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org
- **MEGA_KEY**: Mega.nz api key to mirror mega.nz links. Get it from [Mega SDK Page](https://mega.nz/sdk)
- **MEGA_USERNAME**: Your email id you used to sign up on mega.nz for using premium accounts (Leave th)
- **MEGA_API_KEY**: Mega.nz api key to mirror mega.nz links. Get it from [Mega SDK Page](https://mega.nz/sdk)
- **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`.
- **IMAGE_URL**: (Optional field) Show Image/Logo in /start message. Fill value of image your link image, use telegra.ph or any direct link image.
- **UPTOBOX_TOKEN**: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).
Expand All @@ -122,7 +123,7 @@ shortzon.com
- Go to the Credentials tab and click Create Credentials -> OAuth Client ID
- Choose Desktop and Create.
- Use the download button to download your credentials.
- Move that file to the root of mirrorbot, and rename it to credentials.json
- Move that file to the root of mirrorbot, and rename it to **credentials.json**
- Visit [Google API page](https://console.developers.google.com/apis/library)
- Search for Drive and enable it if it is disabled
- Finally, run the script to generate **token.pickle** file for Google Drive:
Expand All @@ -148,7 +149,8 @@ sudo docker run mirrorbot

## Deploying on Heroku

Fork this repo then upload **token.pickle** to your forks
- Fork this repo then upload **token.pickle** to your forks
- Hit the deploy to heroku button and follow the further instructions in the screen

**NOTE**: If you didn't upload **token.pickle**, uploading will not work.
<p><a href="https://heroku.com/deploy"> <img src="https://img.shields.io/badge/Deploy%20To%20Heroku-blueviolet?style=for-the-badge&logo=heroku" width="200""/></a></p>
Expand Down
20 changes: 12 additions & 8 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "slam-mirrorbot ",
"name": "slam-mirrorbot",
"description": "A Telegram bot for all your mirror needs",
"logo": "https://telegra.ph/file/6507910fd06d18dfaba82.jpg",
"keywords": [
Expand All @@ -8,14 +8,14 @@
"python"
],
"repository": "https://github.com/breakdowns/slam-mirrorbot",
"website": "https://t.me/SlamMirrorSupport",
"success_url": "https://github.com/breakdowns/slam-mirrorbot/blob/master/README.md",
"website": "https://github.com/breakdowns/slam-mirrorbot",
"success_url": "https://t.me/SlamMirrorSupport",
"stack": "container",
"env": {
"ENV": {
"description": "Setting this to ANYTHING will enable Webhooks when in env mode",
"value": "ANYTHING"
},
"description": "Setting this to ANYTHING will enable Webhooks when in env mode",
"value": "ANYTHING"
},
"BOT_TOKEN": {
"description": "The telegram bot token that you get from @BotFather.",
"required": true
Expand Down Expand Up @@ -78,18 +78,22 @@
"description": "Uptobox premium token to mirror uptobox links. Get it from https://uptobox.com/my_account.",
"required": false
},
"MEGA_KEY": {
"MEGA_API_KEY": {
"description": "Mega.nz api key to mirror mega.nz links. Get it from https://mega.nz/sdk.",
"required": false
},
"MEGA_USERNAME": {
"MEGA_EMAIL_ID": {
"description": "Your email id you used to sign up on mega.nz.",
"required": false
},
"MEGA_PASSWORD": {
"description": "Your password for your mega.nz account.",
"required": false
},
"BLOCK_MEGA_FOLDER": {
"description": "If you want to remove mega.nz folder support, set it to True.",
"required": false
},
"BLOCK_MEGA_LINKS": {
"description": "If you want to remove mega.nz mirror support, set it to True.",
"required": false
Expand Down
12 changes: 3 additions & 9 deletions aria.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --check-certif
--follow-torrent=mem --split=10 \
--daemon=true --allow-overwrite=true --max-overall-download-limit=$MAX_DOWNLOAD_SPEED \
--max-overall-upload-limit=1K --max-concurrent-downloads=$MAX_CONCURRENT_DOWNLOADS \
--peer-id-prefix=-TR2940- --user-agent=Transmission/2.94 --peer-agent=Transmission/2.94 --continue=true \
--disk-cache=64M --file-allocation=prealloc \
--peer-id-prefix=-qB4220- --user-agent=qBittorrent/4.2.2 \
--disk-cache=64M --file-allocation=prealloc --continue=true \
--max-file-not-found=5 --max-tries=20 --auto-file-renaming=true \
--bt-enable-lpd=true --seed-time=0.01 --seed-ratio=1.0 \
--file-allocation=prealloc --max-file-not-found=5 --max-tries=5 --retry-wait=5 \
--auto-file-renaming=true --reuse-uri=true --http-accept-gzip=true --listen-port=49152-65535 \
--content-disposition-default-utf8=true --bt-tracker-connect-timeout=600 \
--dht-listen-port=51513 --enable-dht=true --enable-dht6=true \
--dht-file-path=/usr/src/app/dht.dat --dht-file-path6=/usr/src/app/dht6.dat \
--dht-entry-point=dht.transmissionbt.com:6881 \
--dht-entry-point6=dht.transmissionbt.com:6881
--content-disposition-default-utf8=true --http-accept-gzip=true --reuse-uri=true
53 changes: 21 additions & 32 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import socket
import faulthandler
faulthandler.enable()
from megasdkrestclient import MegaSdkRestClient, errors as mega_err
import subprocess

socket.setdefaulttimeout(600)

Expand Down Expand Up @@ -109,35 +107,18 @@ def getConfig(name: str):
LOGGER.info("Telegraph Token Generated: '" + telegraph_token + "'")

try:
MEGA_KEY = getConfig('MEGA_KEY')

except KeyError:
MEGA_KEY = None
LOGGER.info('MEGA API KEY NOT AVAILABLE')
if MEGA_KEY is not None:
# Start megasdkrest binary
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY])
time.sleep(3) # Wait for the mega server to start listening
mega_client = MegaSdkRestClient('http://localhost:6090')
try:
MEGA_USERNAME = getConfig('MEGA_USERNAME')
MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
if len(MEGA_USERNAME) > 0 and len(MEGA_PASSWORD) > 0:
try:
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
except mega_err.MegaSdkRestClientException as e:
logging.error(e.message['message'])
exit(0)
else:
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
MEGA_USERNAME = None
MEGA_PASSWORD = None
except KeyError:
LOGGER.info("Mega API KEY provided but credentials not provided. Starting mega in anonymous mode!")
MEGA_USERNAME = None
MEGA_PASSWORD = None
else:
MEGA_USERNAME = None
MEGA_API_KEY = getConfig('MEGA_API_KEY')
except KeyError:
logging.warning('MEGA API KEY not provided!')
MEGA_API_KEY = None
try:
MEGA_EMAIL_ID = getConfig('MEGA_EMAIL_ID')
MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
if len(MEGA_EMAIL_ID) == 0 or len(MEGA_PASSWORD) == 0:
raise KeyError
except KeyError:
logging.warning('MEGA Credentials not provided!')
MEGA_EMAIL_ID = None
MEGA_PASSWORD = None
try:
HEROKU_API_KEY = getConfig('HEROKU_API_KEY')
Expand Down Expand Up @@ -220,6 +201,14 @@ def getConfig(name: str):
USE_SERVICE_ACCOUNTS = False
except KeyError:
USE_SERVICE_ACCOUNTS = False
try:
BLOCK_MEGA_FOLDER = getConfig('BLOCK_MEGA_FOLDER')
if BLOCK_MEGA_FOLDER.lower() == 'true':
BLOCK_MEGA_FOLDER = True
else:
BLOCK_MEGA_FOLDER = False
except KeyError:
BLOCK_MEGA_FOLDER = False
try:
BLOCK_MEGA_LINKS = getConfig('BLOCK_MEGA_LINKS')
if BLOCK_MEGA_LINKS.lower() == 'true':
Expand All @@ -241,6 +230,6 @@ def getConfig(name: str):
except KeyError:
IMAGE_URL = 'https://telegra.ph/file/db03910496f06094f1f7a.jpg'

updater = tg.Updater(token=BOT_TOKEN,use_context=True)
updater = tg.Updater(token=BOT_TOKEN, use_context=True)
bot = updater.bot
dispatcher = updater.dispatcher
19 changes: 13 additions & 6 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def get_readable_message():
msg += f"\n<b>Downloaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
else:
msg += f"\n<b>Uploaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
msg += f"\n<b>Speed:</b> {download.speed()}, \n<b>ETA:</b> {download.eta()} "
msg += f"\n<b>Speed:</b> {download.speed()} | <b>ETA:</b> {download.eta()} "
# if hasattr(download, 'is_torrent'):
try:
msg += f"\n<b>Seeders:</b> {download.aria_download().num_seeders}" \
Expand Down Expand Up @@ -133,24 +133,31 @@ def get_readable_time(seconds: int) -> str:
return result


def is_mega_link(url: str):
return "mega.nz" in url


def is_url(url: str):
url = re.findall(URL_REGEX, url)
if url:
return True
return False


def is_mega_link(url: str):
return "mega.nz" in url

def get_mega_link_type(url: str):
if "folder" in url:
return "folder"
elif "file" in url:
return "file"
elif "/#F!" in url:
return "folder"
return "file"

def is_magnet(url: str):
magnet = re.findall(MAGNET_REGEX, url)
if magnet:
return True
return False


def new_thread(fn):
"""To use as decorator to make a function call threaded.
Needs import
Expand Down
7 changes: 3 additions & 4 deletions bot/helper/mirror_utils/download_utils/aria2_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def __onDownloadStarted(self, api, gid):
smsg, button = gdrive.drive_list(sname)
if smsg:
dl.getListener().onDownloadError(f'File is already available in drive.\n\n')
sendMarkup("Here are the search results: 👇", dl.getListener().bot, dl.getListener().update, button)
sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
aria2.remove([download])

size = download.total_length
if ENABLE_FILESIZE_LIMIT:
if size / 1024 / 1024 / 1024 > MAX_TORRENT_SIZE:
Expand Down Expand Up @@ -71,8 +71,7 @@ def __onDownloadPause(self, api, gid):
def __onDownloadStopped(self, api, gid):
LOGGER.info(f"onDownloadStop: {gid}")
dl = getDownloadByGid(gid)
if dl:
dl.getListener().onDownloadError('Dead Torrent!')
if dl: dl.getListener().onDownloadError('Dead torrent!')

@new_thread
def __onDownloadError(self, api, gid):
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/mirror_utils/download_utils/download_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def __init__(self):

class DownloadHelper:
def __init__(self):
self._name = '' # Name of the download; empty string if no download has been started
self._size = 0.0 # Size of the download
self.name = '' # Name of the download; empty string if no download has been started
self.size = 0.0 # Size of the download
self.downloaded_bytes = 0.0 # Bytes downloaded
self.speed = 0.0 # Download speed in bytes per second
self.progress = 0.0
Expand Down
Loading

0 comments on commit 9612d99

Please sign in to comment.