Skip to content

Commit

Permalink
v4.6.9 (breakdowns#66)
Browse files Browse the repository at this point in the history
- Merged mega-rest from lzzy
- Fix /watch download msg progress
- Change auto stop to 20 minute
- Fix stop duplicate mirror (breakdowns#65)
- Fix tar name
- Change tracker

Co-authored-by: Shivam Jha <[email protected]>
Co-authored-by: Dev Singh Rajput <[email protected]>
Co-authored-by: FA Tulloh <[email protected]>
  • Loading branch information
4 people authored Apr 26, 2021
1 parent bd381fb commit 6f2080b
Show file tree
Hide file tree
Showing 20 changed files with 232 additions and 304 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ data*
*.pickle
authorized_chats.txt
log.txt
accounts/*
accounts/*
venv/
23 changes: 12 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
FROM lzzy12/mega-sdk-python:latest
FROM ubuntu:20.04

WORKDIR /usr/src/app
RUN chmod 777 /usr/src/app

RUN apt-get -qq update && \
apt-get install -y software-properties-common && \
rm -rf /var/lib/apt/lists/* && \
apt-add-repository non-free && \
apt-get -qq update && \
apt-get -qq install -y p7zip-full p7zip-rar aria2 curl pv jq ffmpeg locales python3-lxml && \
apt-get purge -y software-properties-common
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 \
libcrypto++-dev libssl-dev \
libc-ares-dev libcurl4-openssl-dev \
libsqlite3-dev libsodium-dev && \
curl -L https://github.com/jaskaranSM/megasdkrest/releases/download/v0.1/megasdkrest -o /usr/local/bin/megasdkrest && \
chmod +x /usr/local/bin/megasdkrest

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 pip3 install --no-cache-dir -r requirements.txt
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && \
locale-gen
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
COPY . .
COPY .netrc /root/.netrc
COPY netrc /root/.netrc
RUN chmod +x aria.sh

CMD ["bash","start.sh"]
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ This is a telegram bot writen in python for mirroring files on the internet to o
- Check Heroku dynos stats
- Add stickers to your pack
- Shell and Executor
- racaty.net support

## 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 Mega.nz links to google drive
- 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 @@ -90,8 +91,8 @@ 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_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_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_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`.
Expand Down Expand Up @@ -247,7 +248,7 @@ python3 add_to_team_drive.py -d SharedTeamDriveSrcID
```

## Youtube-dl authentication using .netrc file
For using your premium accounts in youtube-dl, edit the [.netrc](https://github.com/breakdowns/slam-mirrorbot/blob/master/.netrc) file according to following format:
For using your premium accounts in youtube-dl, edit the netrc file according to following format:
```
machine host login username password my_youtube_password
```
Expand All @@ -264,5 +265,6 @@ Thanks to:
- [Dank-del](https://github.com/Dank-del/) for base repo
- [magneto261290](https://github.com/magneto261290/) for some features
- [SVR666](https://github.com/SVR666/) for some features & fixes
- [breakdowns](https://github.com/breakdowns/) me (lol)

and many more people who aren't mentioned here, but may be found in [Contributors](https://github.com/breakdowns/slam-mirrorbot/graphs/contributors).
8 changes: 2 additions & 6 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,18 @@
"description": "Uptobox premium token to mirror uptobox links. Get it from https://uptobox.com/my_account.",
"required": false
},
"MEGA_API_KEY": {
"MEGA_KEY": {
"description": "Mega.nz api key to mirror mega.nz links. Get it from https://mega.nz/sdk.",
"required": false
},
"MEGA_EMAIL_ID": {
"MEGA_USERNAME": {
"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
6 changes: 3 additions & 3 deletions aria.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export MAX_DOWNLOAD_SPEED=0
tracker_list=$(curl -Ns https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_all.txt | awk '$1' | tr '\n' ',')
tracker_list=$(curl -Ns https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt | awk '$1' | tr '\n' ',')
export MAX_CONCURRENT_DOWNLOADS=7

aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --check-certificate=false\
aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --check-certificate=false \
--max-connection-per-server=10 --rpc-max-request-size=1024M \
--bt-tracker="[$tracker_list]" --bt-max-peers=0 --bt-tracker-connect-timeout=300 --bt-stop-timeout=300 --seed-time=0.01 --min-split-size=10M \
--bt-tracker="[$tracker_list]" --bt-max-peers=0 --bt-tracker-connect-timeout=300 --bt-stop-timeout=1200 --seed-time=0.01 --min-split-size=10M \
--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 \
Expand Down
54 changes: 32 additions & 22 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from pyrogram import Client
from telegraph import Telegraph
import socket
from megasdkrestclient import MegaSdkRestClient, errors as mega_err
import subprocess

socket.setdefaulttimeout(600)

Expand Down Expand Up @@ -102,6 +104,32 @@ def getConfig(name: str):
telegraph_token = telegraph.get_access_token()
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:
try:
MEGA_USERNAME = getConfig('MEGA_USERNAME')
MEGA_PASSWORD = getConfig('MEGA_PASSWORD')
# Start megasdkrest binary
subprocess.Popen(["megasdkrest", "--apikey", MEGA_KEY])
time.sleep(3)
mega_client = MegaSdkRestClient('http://localhost:6090')
try:
mega_client.login(MEGA_USERNAME, MEGA_PASSWORD)
except mega_err.MegaSdkRestClientException as e:
logging.error(e.message['message'])
exit(0)
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_PASSWORD = None
try:
HEROKU_API_KEY = getConfig('HEROKU_API_KEY')
except KeyError:
Expand All @@ -124,25 +152,15 @@ def getConfig(name: str):
ENABLE_FILESIZE_LIMIT = False
except KeyError:
ENABLE_FILESIZE_LIMIT = False
try:
IMAGE_URL = getConfig('IMAGE_URL')
except KeyError:
IMAGE_URL = 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:
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:
INDEX_URL = getConfig('INDEX_URL')
if len(INDEX_URL) == 0:
Expand Down Expand Up @@ -197,14 +215,6 @@ 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 Down
2 changes: 2 additions & 0 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

now=datetime.now(pytz.timezone('Asia/Jakarta'))


@run_async
def stats(update, context):
currentTime = get_readable_time((time.time() - botStartTime))
Expand Down Expand Up @@ -54,6 +55,7 @@ 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 =''
Expand Down
19 changes: 6 additions & 13 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def getDownloadByGid(gid):
with download_dict_lock:
for dl in download_dict.values():
status = dl.status()
if status != MirrorStatus.STATUS_UPLOADING and status != MirrorStatus.STATUS_ARCHIVING\
if status != MirrorStatus.STATUS_UPLOADING and status != MirrorStatus.STATUS_ARCHIVING \
and status != MirrorStatus.STATUS_EXTRACTING:
if dl.gid() == gid:
return dl
Expand Down Expand Up @@ -133,31 +133,24 @@ 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
2 changes: 1 addition & 1 deletion bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def tar(org_path):
path = pathlib.PurePath(org_path)
LOGGER.info(f'Tar: orig_path: {org_path}, tar_path: {tar_path}')
tar = tarfile.open(tar_path, "w")
tar.add(org_path, arcname=path.name)
tar.add(org_path, arcname=os.path.basename(org_path))
tar.close()
return tar_path

Expand Down
21 changes: 11 additions & 10 deletions bot/helper/mirror_utils/download_utils/aria2_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ def __onDownloadStarted(self, api, gid):
download = api.get_download(gid)
self.name = download.name
sname = download.name
size = download.total_length
if ENABLE_FILESIZE_LIMIT:
if size / 1024 / 1024 / 1024 > MAX_TORRENT_SIZE:
LOGGER.info(f" Download size Exceeded: {gid}")
dl.getListener().onDownloadError(f'File size {get_readable_file_size(size)} larger than Maximum Allowed size {MAX_TORRENT_SIZE}')
aria2.remove([download])
return
update_all_messages()
if STOP_DUPLICATE_MIRROR:
if dl.getListener().isTar == True:
sname = sname + ".tar"
Expand All @@ -40,7 +32,14 @@ def __onDownloadStarted(self, api, gid):
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)
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:
LOGGER.info(f" Download size Exceeded: {gid}")
dl.getListener().onDownloadError(f'File size {get_readable_file_size(size)} larger than Maximum Allowed size {MAX_TORRENT_SIZE}GB')
aria2.remove([download])
return
update_all_messages()
Expand Down Expand Up @@ -72,7 +71,9 @@ 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!')
dl = getDownloadByGid(gid)
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 6f2080b

Please sign in to comment.