Skip to content

Commit

Permalink
[Bring-Up] Priyo-Mirror-Bot
Browse files Browse the repository at this point in the history
* Addded Mega Download Support For Complex And Big Size(100-200+) Folders.Read The Msg About Mega Download Below.
* Added Support For UpToBox Links (Premium Account Needed).
* Added Ability To Do Speed Test Of The Host. (/speedtest Command).
* Added Support For Indian Streaming Sites Like Hotstar, Zee5, Mx Player, Voot, And Many Others........
* Added Custom User Agent ,Peer Agent..Transmission For Now.
  • Loading branch information
S M Mahabub Hossain (Priyo) committed Mar 19, 2021
1 parent affa68c commit d8626aa
Show file tree
Hide file tree
Showing 25 changed files with 2,089 additions and 2,065 deletions.
56 changes: 29 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
FROM lzzy12/mega-sdk-python:latest

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

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 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
RUN chmod +x aria.sh

CMD ["bash","start.sh"]
FROM iamliquidx/megasdk:latest

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

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 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
RUN chmod +x aria.sh

CMD ["bash","start.sh"]


1,348 changes: 674 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

500 changes: 250 additions & 250 deletions README.md

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions add_to_team_drive.py
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
from __future__ import print_function
from google.oauth2.service_account import Credentials
import googleapiclient.discovery, json, progress.bar, glob, sys, argparse, time
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import os, pickle

stt = time.time()

parse = argparse.ArgumentParser(
description='A tool to add service accounts to a shared drive from a folder containing credential files.')
parse.add_argument('--path', '-p', default='accounts',
help='Specify an alternative path to the service accounts folder.')
parse.add_argument('--credentials', '-c', default='./credentials.json',
help='Specify the relative path for the credentials file.')
parse.add_argument('--yes', '-y', default=False, action='store_true', help='Skips the sanity prompt.')
parsereq = parse.add_argument_group('required arguments')
parsereq.add_argument('--drive-id', '-d', help='The ID of the Shared Drive.', required=True)

args = parse.parse_args()
acc_dir = args.path
did = args.drive_id
credentials = glob.glob(args.credentials)

try:
open(credentials[0], 'r')
print('>> Found credentials.')
except IndexError:
print('>> No credentials found.')
sys.exit(0)

if not args.yes:
# input('Make sure the following client id is added to the shared drive as Manager:\n' + json.loads((open(
# credentials[0],'r').read()))['installed']['client_id'])
input('>> Make sure the **Google account** that has generated credentials.json\n is added into your Team Drive '
'(shared drive) as Manager\n>> (Press any key to continue)')

creds = None
if os.path.exists('token_sa.pickle'):
with open('token_sa.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(credentials[0], scopes=[
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member'
])
# creds = flow.run_local_server(port=0)
creds = flow.run_console()
# Save the credentials for the next run
with open('token_sa.pickle', 'wb') as token:
pickle.dump(creds, token)

drive = googleapiclient.discovery.build("drive", "v3", credentials=creds)
batch = drive.new_batch_http_request()

aa = glob.glob('%s/*.json' % acc_dir)
pbar = progress.bar.Bar("Readying accounts", max=len(aa))
for i in aa:
ce = json.loads(open(i, 'r').read())['client_email']
batch.add(drive.permissions().create(fileId=did, supportsAllDrives=True, body={
"role": "fileOrganizer",
"type": "user",
"emailAddress": ce
}))
pbar.next()
pbar.finish()
print('Adding...')
batch.execute()

print('Complete.')
hours, rem = divmod((time.time() - stt), 3600)
minutes, sec = divmod(rem, 60)
from __future__ import print_function
from google.oauth2.service_account import Credentials
import googleapiclient.discovery, json, progress.bar, glob, sys, argparse, time
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
import os, pickle

stt = time.time()

parse = argparse.ArgumentParser(
description='A tool to add service accounts to a shared drive from a folder containing credential files.')
parse.add_argument('--path', '-p', default='accounts',
help='Specify an alternative path to the service accounts folder.')
parse.add_argument('--credentials', '-c', default='./credentials.json',
help='Specify the relative path for the credentials file.')
parse.add_argument('--yes', '-y', default=False, action='store_true', help='Skips the sanity prompt.')
parsereq = parse.add_argument_group('required arguments')
parsereq.add_argument('--drive-id', '-d', help='The ID of the Shared Drive.', required=True)

args = parse.parse_args()
acc_dir = args.path
did = args.drive_id
credentials = glob.glob(args.credentials)

try:
open(credentials[0], 'r')
print('>> Found credentials.')
except IndexError:
print('>> No credentials found.')
sys.exit(0)

if not args.yes:
# input('Make sure the following client id is added to the shared drive as Manager:\n' + json.loads((open(
# credentials[0],'r').read()))['installed']['client_id'])
input('>> Make sure the **Google account** that has generated credentials.json\n is added into your Team Drive '
'(shared drive) as Manager\n>> (Press any key to continue)')

creds = None
if os.path.exists('token_sa.pickle'):
with open('token_sa.pickle', 'rb') as token:
creds = pickle.load(token)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(credentials[0], scopes=[
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.member'
])
# creds = flow.run_local_server(port=0)
creds = flow.run_console()
# Save the credentials for the next run
with open('token_sa.pickle', 'wb') as token:
pickle.dump(creds, token)

drive = googleapiclient.discovery.build("drive", "v3", credentials=creds)
batch = drive.new_batch_http_request()

aa = glob.glob('%s/*.json' % acc_dir)
pbar = progress.bar.Bar("Readying accounts", max=len(aa))
for i in aa:
ce = json.loads(open(i, 'r').read())['client_email']
batch.add(drive.permissions().create(fileId=did, supportsAllDrives=True, body={
"role": "fileOrganizer",
"type": "user",
"emailAddress": ce
}))
pbar.next()
pbar.finish()
print('Adding...')
batch.execute()

print('Complete.')
hours, rem = divmod((time.time() - stt), 3600)
minutes, sec = divmod(rem, 60)
print("Elapsed Time:\n{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), sec))
2 changes: 1 addition & 1 deletion aria.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true
aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true
20 changes: 10 additions & 10 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/iamLiquidX/trackerlistx/main/trackers.txt | awk '$1' | tr '\n' ',')
export MAX_CONCURRENT_DOWNLOADS=4
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 --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 \
--peer-id-prefix=-TR2770- --user-agent=Transmission/2.77 --peer-agent=Transmission/2.77 \
export MAX_DOWNLOAD_SPEED=0
tracker_list=$(curl -Ns https://raw.githubusercontent.com/iamLiquidX/trackerlistx/main/trackers.txt | awk '$1' | tr '\n' ',')
export MAX_CONCURRENT_DOWNLOADS=4
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 --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 \
--peer-id-prefix=-TR2770- --user-agent=Transmission/2.77 --peer-agent=Transmission/2.77 \
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 @@ -24,7 +24,7 @@ def start_cleanup():
def clean_all():
aria2.remove_all(True)
try:
start_cleanup()
shutil.rmtree(DOWNLOAD_DIR)
except FileNotFoundError:
pass

Expand Down
42 changes: 42 additions & 0 deletions bot/helper/mirror_utils/download_utils/direct_link_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from random import choice

import requests
import logging
from bot import UPTOBOX_TOKEN
from bs4 import BeautifulSoup

from bot.helper.ext_utils.exceptions import DirectDownloadLinkException
Expand All @@ -32,6 +34,8 @@ def direct_link_generator(link: str):
return cm_ru(link)
elif 'mediafire.com' in link:
return mediafire(link)
elif 'uptobox.com' in link:
return uptobox(link)
elif 'osdn.net' in link:
return osdn(link)
elif 'github.com' in link:
Expand Down Expand Up @@ -113,6 +117,44 @@ def mediafire(url: str) -> str:
return dl_url


def uptobox(url: str) -> str:
try:
link = re.findall(r'\bhttps?://.*uptobox\.com\S+', url)[0]
except IndexError:
raise DirectDownloadLinkException("`No Uptobox links found`\n")
if UPTOBOX_TOKEN is None:
logging.error('UPTOBOX_TOKEN not provided!')
else:
check = 'https://uptobox.com/api/user/me?token=%s' % (UPTOBOX_TOKEN)
request = requests.get(check)
info = request.json()
premium = info["data"]["premium"]
try:
link = re.findall(r'\bhttp?://.*uptobox\.com/dl\S+', url)[0]
logging.info('Uptobox direct link')
dl_url = url
except:
if premium == 1:
file_id = re.findall(r'\bhttps?://.*uptobox\.com/(\w+)', url)[0]
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s' % (UPTOBOX_TOKEN, file_id)
req = requests.get(file_link)
result = req.json()
dl_url = result['data']['dlLink']
else:
file_id = re.findall(r'\bhttps?://.*uptobox\.com/(\w+)', url)[0]
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s' % (UPTOBOX_TOKEN, file_id)
req = requests.get(file_link)
result = req.json()
waiting_time = result["data"]["waiting"] + 1
waiting_token = result["data"]["waitingToken"]
_countdown(waiting_time)
file_link = 'https://uptobox.com/api/link?token=%s&file_code=%s&waitingToken=%s' % (UPTOBOX_TOKEN, file_id, waiting_token)
req = requests.get(file_link)
result = req.json()
dl_url = result['data']['dlLink']
return dl_url


def osdn(url: str) -> str:
""" OSDN direct links generator """
osdn_link = 'https://osdn.net'
Expand Down
10 changes: 5 additions & 5 deletions bot/helper/telegram_helper/filters.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
from telegram.ext import BaseFilter
from telegram.ext import MessageFilter
from telegram import Message
from bot import AUTHORIZED_CHATS, OWNER_ID, download_dict, download_dict_lock


class CustomFilters:
class _OwnerFilter(BaseFilter):
class _OwnerFilter(MessageFilter):
def filter(self, message):
return bool(message.from_user.id == OWNER_ID)

owner_filter = _OwnerFilter()

class _AuthorizedUserFilter(BaseFilter):
class _AuthorizedUserFilter(MessageFilter):
def filter(self, message):
id = message.from_user.id
return bool(id in AUTHORIZED_CHATS or id == OWNER_ID)

authorized_user = _AuthorizedUserFilter()

class _AuthorizedChat(BaseFilter):
class _AuthorizedChat(MessageFilter):
def filter(self, message):
return bool(message.chat.id in AUTHORIZED_CHATS)

authorized_chat = _AuthorizedChat()

class _MirrorOwner(BaseFilter):
class _MirrorOwner(MessageFilter):
def filter(self, message: Message):
user_id = message.from_user.id
if user_id == OWNER_ID:
Expand Down
7 changes: 2 additions & 5 deletions bot/modules/authorize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from bot.helper.telegram_helper.message_utils import sendMessage
from telegram.ext import run_async
from bot import AUTHORIZED_CHATS, dispatcher
from telegram.ext import CommandHandler
from bot.helper.telegram_helper.filters import CustomFilters
Expand All @@ -8,7 +7,6 @@
from bot.helper.telegram_helper.bot_commands import BotCommands


@run_async
def authorize(update,context):
reply_message = update.message.reply_to_message
msg = ''
Expand All @@ -34,7 +32,6 @@ def authorize(update,context):
sendMessage(msg, context.bot, update)


@run_async
def unauthorize(update,context):
reply_message = update.message.reply_to_message
if reply_message is None:
Expand All @@ -61,9 +58,9 @@ def unauthorize(update,context):


authorize_handler = CommandHandler(command=BotCommands.AuthorizeCommand, callback=authorize,
filters=CustomFilters.owner_filter & Filters.group)
filters=CustomFilters.owner_filter & Filters.group, run_async=True)
unauthorize_handler = CommandHandler(command=BotCommands.UnAuthorizeCommand, callback=unauthorize,
filters=CustomFilters.owner_filter & Filters.group)
filters=CustomFilters.owner_filter & Filters.group, run_async=True)
dispatcher.add_handler(authorize_handler)
dispatcher.add_handler(unauthorize_handler)

Loading

0 comments on commit d8626aa

Please sign in to comment.