v3.5 (#12)
- Added quality option in /watch command - Added url Shorteners support (Optional) - Random name while generating Telegraph Token
This commit is contained in:
parent
3520d59062
commit
df192e4145
|
|
@ -47,7 +47,7 @@ Fork this repo, than upload credentials.json and token.pickle to your forks
|
||||||
- Add stickers to your pack
|
- Add stickers to your pack
|
||||||
- Nyaa.si and Sukebei Torrent search
|
- Nyaa.si and Sukebei Torrent search
|
||||||
- Shell and Executor
|
- Shell and Executor
|
||||||
- Inline buttons support
|
- Shortener support
|
||||||
- Speedtest with picture results
|
- Speedtest with picture results
|
||||||
- Extract these filetypes and uploads to google drive
|
- Extract these filetypes and uploads to google drive
|
||||||
> ZIP, RAR, TAR, 7z, ISO, WIM, CAB, GZIP, BZIP2,
|
> ZIP, RAR, TAR, 7z, ISO, WIM, CAB, GZIP, BZIP2,
|
||||||
|
|
|
||||||
10
app.json
10
app.json
|
|
@ -3,6 +3,7 @@
|
||||||
"description": "Telegram mirror bot with python",
|
"description": "Telegram mirror bot with python",
|
||||||
"logo": "https://telegra.ph/file/6507910fd06d18dfaba82.jpg",
|
"logo": "https://telegra.ph/file/6507910fd06d18dfaba82.jpg",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
"bot",
|
||||||
"telegram",
|
"telegram",
|
||||||
"python"
|
"python"
|
||||||
],
|
],
|
||||||
|
|
@ -47,7 +48,6 @@
|
||||||
},
|
},
|
||||||
"USE_SERVICE_ACCOUNTS": {
|
"USE_SERVICE_ACCOUNTS": {
|
||||||
"description": "Whether to use service accounts or not. For this to work see 'Using service accounts' section below.",
|
"description": "Whether to use service accounts or not. For this to work see 'Using service accounts' section below.",
|
||||||
"value": "False",
|
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
"AUTHORIZED_CHATS": {
|
"AUTHORIZED_CHATS": {
|
||||||
|
|
@ -81,6 +81,14 @@
|
||||||
"BLOCK_MEGA_LINKS": {
|
"BLOCK_MEGA_LINKS": {
|
||||||
"description": "If you want to remove mega.nz mirror support, set it to True.",
|
"description": "If you want to remove mega.nz mirror support, set it to True.",
|
||||||
"required": false
|
"required": false
|
||||||
|
},
|
||||||
|
"SHORTENER": {
|
||||||
|
"description": "if you want to use shortener in Gdrive and index link.",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
"SHORTENER_API": {
|
||||||
|
"description": "Fill your shortener api key if you are using shortener.",
|
||||||
|
"required": false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ import logging
|
||||||
import os
|
import os
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
import random
|
||||||
|
import string
|
||||||
import aria2p
|
import aria2p
|
||||||
import telegram.ext as tg
|
import telegram.ext as tg
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
@ -107,11 +109,27 @@ LOGGER.info("Generating USER_SESSION_STRING")
|
||||||
with Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) as app:
|
with Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) as app:
|
||||||
USER_SESSION_STRING = app.export_session_string()
|
USER_SESSION_STRING = app.export_session_string()
|
||||||
#Generate Telegraph Token
|
#Generate Telegraph Token
|
||||||
LOGGER.info("Generating Telegraph Token")
|
sname = ''.join(random.SystemRandom().choices(string.ascii_letters, k=8))
|
||||||
|
LOGGER.info("Generating Telegraph Token using '" + sname + "' name")
|
||||||
telegraph = Telegraph()
|
telegraph = Telegraph()
|
||||||
telegraph.create_account(short_name="mirror_bot")
|
telegraph.create_account(short_name=sname)
|
||||||
telegraph_token = telegraph.get_access_token()
|
telegraph_token = telegraph.get_access_token()
|
||||||
|
LOGGER.info("Telegraph Token Generated: '" + telegraph_token + "'")
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
INDEX_URL = getConfig('INDEX_URL')
|
INDEX_URL = getConfig('INDEX_URL')
|
||||||
if len(INDEX_URL) == 0:
|
if len(INDEX_URL) == 0:
|
||||||
|
|
@ -145,6 +163,15 @@ try:
|
||||||
except KeyError:
|
except KeyError:
|
||||||
BLOCK_MEGA_LINKS = False
|
BLOCK_MEGA_LINKS = False
|
||||||
|
|
||||||
|
try:
|
||||||
|
SHORTENER = getConfig('SHORTENER')
|
||||||
|
SHORTENER_API = getConfig('SHORTENER_API')
|
||||||
|
if len(SHORTENER) == 0 or len(SHORTENER_API) == 0:
|
||||||
|
raise KeyError
|
||||||
|
except KeyError:
|
||||||
|
SHORTENER = None
|
||||||
|
SHORTENER_API = None
|
||||||
|
|
||||||
app = Client('slam', api_id=TELEGRAM_API, api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN)
|
app = Client('slam', api_id=TELEGRAM_API, api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN)
|
||||||
updater = tg.Updater(token=BOT_TOKEN,use_context=True)
|
updater = tg.Updater(token=BOT_TOKEN,use_context=True)
|
||||||
bot = updater.bot
|
bot = updater.bot
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ def stats(update, context):
|
||||||
f'<b>Total disk space:</b> {total}\n' \
|
f'<b>Total disk space:</b> {total}\n' \
|
||||||
f'<b>Used:</b> {used} ' \
|
f'<b>Used:</b> {used} ' \
|
||||||
f'<b>Free:</b> {free}\n\n' \
|
f'<b>Free:</b> {free}\n\n' \
|
||||||
f'📊Data Usage📊\n<b>Upload:</b> {sent}\n' \
|
f'<b>Data Usage</b>\n<b>Upload:</b> {sent}\n' \
|
||||||
f'<b>Down:</b> {recv}\n\n' \
|
f'<b>Down:</b> {recv}\n\n' \
|
||||||
f'<b>CPU:</b> {cpuUsage}%\n' \
|
f'<b>CPU:</b> {cpuUsage}%\n' \
|
||||||
f'<b>RAM:</b> {memory}%\n' \
|
f'<b>RAM:</b> {memory}%\n' \
|
||||||
|
|
@ -86,7 +86,7 @@ def bot_help(update, context):
|
||||||
|
|
||||||
/{BotCommands.TarMirrorCommand} [download_url][magnet_link]: Start mirroring and upload the archived (.tar) version of the download
|
/{BotCommands.TarMirrorCommand} [download_url][magnet_link]: Start mirroring and upload the archived (.tar) version of the download
|
||||||
|
|
||||||
/{BotCommands.WatchCommand} [youtube-dl supported link]: Mirror through youtube-dl
|
/{BotCommands.WatchCommand} [youtube-dl supported link]: Mirror through youtube-dl. Click /{BotCommands.WatchCommand} for more help.
|
||||||
|
|
||||||
/{BotCommands.TarWatchCommand} [youtube-dl supported link]: Mirror through youtube-dl and tar before uploading
|
/{BotCommands.TarWatchCommand} [youtube-dl supported link]: Mirror through youtube-dl and tar before uploading
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,7 @@ class YoutubeDLHelper(DownloadHelper):
|
||||||
self.opts = {
|
self.opts = {
|
||||||
'progress_hooks': [self.__onDownloadProgress],
|
'progress_hooks': [self.__onDownloadProgress],
|
||||||
'logger': MyLogger(self),
|
'logger': MyLogger(self),
|
||||||
'usenetrc': True,
|
'usenetrc': True
|
||||||
'format': "best/bestvideo+bestaudio"
|
|
||||||
}
|
}
|
||||||
self.__download_speed = 0
|
self.__download_speed = 0
|
||||||
self.download_speed_readable = ''
|
self.download_speed_readable = ''
|
||||||
|
|
@ -72,10 +71,14 @@ class YoutubeDLHelper(DownloadHelper):
|
||||||
elif d['status'] == "downloading":
|
elif d['status'] == "downloading":
|
||||||
with self.__resource_lock:
|
with self.__resource_lock:
|
||||||
self.__download_speed = d['speed']
|
self.__download_speed = d['speed']
|
||||||
|
try:
|
||||||
|
tbyte = d['total_bytes']
|
||||||
|
except KeyError:
|
||||||
|
tbyte = d['total_bytes_estimate']
|
||||||
if self.is_playlist:
|
if self.is_playlist:
|
||||||
progress = d['downloaded_bytes'] / d['total_bytes']
|
progress = d['downloaded_bytes'] / tbyte
|
||||||
chunk_size = d['downloaded_bytes'] - self.last_downloaded
|
chunk_size = d['downloaded_bytes'] - self.last_downloaded
|
||||||
self.last_downloaded = d['total_bytes'] * progress
|
self.last_downloaded = tbyte * progress
|
||||||
self.downloaded_bytes += chunk_size
|
self.downloaded_bytes += chunk_size
|
||||||
try:
|
try:
|
||||||
self.progress = (self.downloaded_bytes / self.size) * 100
|
self.progress = (self.downloaded_bytes / self.size) * 100
|
||||||
|
|
@ -95,14 +98,17 @@ class YoutubeDLHelper(DownloadHelper):
|
||||||
def onDownloadError(self, error):
|
def onDownloadError(self, error):
|
||||||
self.__listener.onDownloadError(error)
|
self.__listener.onDownloadError(error)
|
||||||
|
|
||||||
def extractMetaData(self, link):
|
def extractMetaData(self, link, qual):
|
||||||
if 'hotstar' in link:
|
if 'hotstar' or 'sonyliv' in link:
|
||||||
self.opts['geo_bypass_country'] = 'IN'
|
self.opts['geo_bypass_country'] = 'IN'
|
||||||
|
|
||||||
with YoutubeDL(self.opts) as ydl:
|
with YoutubeDL(self.opts) as ydl:
|
||||||
try:
|
try:
|
||||||
result = ydl.extract_info(link, download=False)
|
result = ydl.extract_info(link, download=False)
|
||||||
name = ydl.prepare_filename(result)
|
name = ydl.prepare_filename(result)
|
||||||
|
# noobway hack for changing extension after converting to mp3
|
||||||
|
if qual == "audio":
|
||||||
|
name = name.replace(".mp4", ".mp3").replace(".webm", ".mp3")
|
||||||
except DownloadError as e:
|
except DownloadError as e:
|
||||||
self.onDownloadError(str(e))
|
self.onDownloadError(str(e))
|
||||||
return
|
return
|
||||||
|
|
@ -138,14 +144,19 @@ class YoutubeDLHelper(DownloadHelper):
|
||||||
LOGGER.info("Download Cancelled by User!")
|
LOGGER.info("Download Cancelled by User!")
|
||||||
self.onDownloadError("Download Cancelled by User!")
|
self.onDownloadError("Download Cancelled by User!")
|
||||||
|
|
||||||
def add_download(self, link, path):
|
def add_download(self, link, path, qual):
|
||||||
pattern = '^.*(youtu\.be\/|youtube.com\/)(playlist?)'
|
pattern = '^.*(youtu\.be\/|youtube.com\/)(playlist?)'
|
||||||
if re.match(pattern, link):
|
if re.match(pattern, link):
|
||||||
self.opts['ignoreerrors'] = True
|
self.opts['ignoreerrors'] = True
|
||||||
self.__onDownloadStart()
|
self.__onDownloadStart()
|
||||||
self.extractMetaData(link)
|
self.extractMetaData(link, qual)
|
||||||
LOGGER.info(f"Downloading with YT-DL: {link}")
|
LOGGER.info(f"Downloading with YT-DL: {link}")
|
||||||
self.__gid = f"{self.vid_id}{self.__listener.uid}"
|
self.__gid = f"{self.vid_id}{self.__listener.uid}"
|
||||||
|
if qual == "audio":
|
||||||
|
self.opts['format'] = 'bestaudio/best'
|
||||||
|
self.opts['postprocessors'] = [{'key': 'FFmpegExtractAudio','preferredcodec': 'mp3','preferredquality': '192',}]
|
||||||
|
else:
|
||||||
|
self.opts['format'] = qual
|
||||||
if not self.is_playlist:
|
if not self.is_playlist:
|
||||||
self.opts['outtmpl'] = f"{path}/{self.name}"
|
self.opts['outtmpl'] = f"{path}/{self.name}"
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from bot import DOWNLOAD_DIR
|
from bot import DOWNLOAD_DIR
|
||||||
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
|
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
|
||||||
from .status import Status
|
from .status import Status
|
||||||
|
from bot.helper.ext_utils.fs_utils import get_path_size
|
||||||
|
|
||||||
class YoutubeDLDownloadStatus(Status):
|
class YoutubeDLDownloadStatus(Status):
|
||||||
def __init__(self, obj, listener):
|
def __init__(self, obj, listener):
|
||||||
|
|
@ -16,7 +16,10 @@ class YoutubeDLDownloadStatus(Status):
|
||||||
return f"{DOWNLOAD_DIR}{self.uid}"
|
return f"{DOWNLOAD_DIR}{self.uid}"
|
||||||
|
|
||||||
def processed_bytes(self):
|
def processed_bytes(self):
|
||||||
|
if self.obj.downloaded_bytes != 0:
|
||||||
return self.obj.downloaded_bytes
|
return self.obj.downloaded_bytes
|
||||||
|
else:
|
||||||
|
return get_path_size(f"{DOWNLOAD_DIR}{self.uid}")
|
||||||
|
|
||||||
def size_raw(self):
|
def size_raw(self):
|
||||||
return self.obj.size
|
return self.obj.size
|
||||||
|
|
@ -49,7 +52,7 @@ class YoutubeDLDownloadStatus(Status):
|
||||||
try:
|
try:
|
||||||
seconds = (self.size_raw() - self.processed_bytes()) / self.speed_raw()
|
seconds = (self.size_raw() - self.processed_bytes()) / self.speed_raw()
|
||||||
return f'{get_readable_time(seconds)}'
|
return f'{get_readable_time(seconds)}'
|
||||||
except ZeroDivisionError:
|
except:
|
||||||
return '-'
|
return '-'
|
||||||
|
|
||||||
def download(self):
|
def download(self):
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ from telegram import InlineKeyboardMarkup
|
||||||
from bot.helper.telegram_helper import button_build
|
from bot.helper.telegram_helper import button_build
|
||||||
from telegraph import Telegraph
|
from telegraph import Telegraph
|
||||||
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
|
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
|
||||||
USE_SERVICE_ACCOUNTS, download_dict, telegraph_token
|
USE_SERVICE_ACCOUNTS, download_dict, telegraph_token, SHORTENER, SHORTENER_API
|
||||||
from bot.helper.ext_utils.bot_utils import *
|
from bot.helper.ext_utils.bot_utils import *
|
||||||
from bot.helper.ext_utils.fs_utils import get_mime_type
|
from bot.helper.ext_utils.fs_utils import get_mime_type, get_path_size
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
logging.getLogger('googleapiclient.discovery').setLevel(logging.ERROR)
|
logging.getLogger('googleapiclient.discovery').setLevel(logging.ERROR)
|
||||||
|
|
@ -209,6 +209,7 @@ class GoogleDriveHelper:
|
||||||
self.__listener.onUploadStarted()
|
self.__listener.onUploadStarted()
|
||||||
file_dir = f"{DOWNLOAD_DIR}{self.__listener.message.message_id}"
|
file_dir = f"{DOWNLOAD_DIR}{self.__listener.message.message_id}"
|
||||||
file_path = f"{file_dir}/{file_name}"
|
file_path = f"{file_dir}/{file_name}"
|
||||||
|
size = get_readable_file_size(get_path_size(file_path))
|
||||||
LOGGER.info("Uploading File: " + file_path)
|
LOGGER.info("Uploading File: " + file_path)
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
self.updater = setInterval(self.update_interval, self._on_upload_progress)
|
self.updater = setInterval(self.update_interval, self._on_upload_progress)
|
||||||
|
|
@ -250,7 +251,7 @@ class GoogleDriveHelper:
|
||||||
finally:
|
finally:
|
||||||
self.updater.cancel()
|
self.updater.cancel()
|
||||||
LOGGER.info(download_dict)
|
LOGGER.info(download_dict)
|
||||||
self.__listener.onUploadComplete(link)
|
self.__listener.onUploadComplete(link, size)
|
||||||
LOGGER.info("Deleting downloaded file/folder..")
|
LOGGER.info("Deleting downloaded file/folder..")
|
||||||
return link
|
return link
|
||||||
|
|
||||||
|
|
@ -317,22 +318,40 @@ class GoogleDriveHelper:
|
||||||
dir_id = self.create_directory(meta.get('name'), parent_id)
|
dir_id = self.create_directory(meta.get('name'), parent_id)
|
||||||
result = self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id)
|
result = self.cloneFolder(meta.get('name'), meta.get('name'), meta.get('id'), dir_id)
|
||||||
msg += f'<b>Filename : </b><code>{meta.get("name")}</code>\n<b>Size : </b>{get_readable_file_size(self.transferred_size)}'
|
msg += f'<b>Filename : </b><code>{meta.get("name")}</code>\n<b>Size : </b>{get_readable_file_size(self.transferred_size)}'
|
||||||
|
durl = self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)
|
||||||
buttons = button_build.ButtonMaker()
|
buttons = button_build.ButtonMaker()
|
||||||
buttons.buildbutton("✨Drive Link✨", self.__G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id))
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
surl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, durl)).text
|
||||||
|
buttons.buildbutton("✨Drive Link✨", surl)
|
||||||
|
else:
|
||||||
|
buttons.buildbutton("✨Drive Link✨", durl)
|
||||||
if INDEX_URL is not None:
|
if INDEX_URL is not None:
|
||||||
url = requests.utils.requote_uri(f'{INDEX_URL}/{meta.get("name")}/')
|
url = requests.utils.requote_uri(f'{INDEX_URL}/{meta.get("name")}/')
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, url)).text
|
||||||
|
buttons.buildbutton("⚡Index Link⚡", siurl)
|
||||||
|
else:
|
||||||
buttons.buildbutton("⚡Index Link⚡", url)
|
buttons.buildbutton("⚡Index Link⚡", url)
|
||||||
else:
|
else:
|
||||||
file = self.copyFile(meta.get('id'), parent_id)
|
file = self.copyFile(meta.get('id'), parent_id)
|
||||||
msg += f'<b>Filename : </b><code>{file.get("name")}</code>'
|
msg += f'<b>Filename : </b><code>{file.get("name")}</code>'
|
||||||
|
durl = self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get("id"))
|
||||||
buttons = button_build.ButtonMaker()
|
buttons = button_build.ButtonMaker()
|
||||||
buttons.buildbutton("✨Drive Link✨", self.__G_DRIVE_BASE_DOWNLOAD_URL.format(file.get("id")))
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
surl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, durl)).text
|
||||||
|
buttons.buildbutton("✨Drive Link ✨", surl)
|
||||||
|
else:
|
||||||
|
buttons.buildbutton("✨Drive Link✨", durl)
|
||||||
try:
|
try:
|
||||||
msg += f'\n<b>Size : </b><code>{get_readable_file_size(int(meta.get("size")))}</code>'
|
msg += f'\n<b>Size : </b><code>{get_readable_file_size(int(meta.get("size")))}</code>'
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
if INDEX_URL is not None:
|
if INDEX_URL is not None:
|
||||||
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
|
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, url)).text
|
||||||
|
buttons.buildbutton("⚡Index Link⚡", siurl)
|
||||||
|
else:
|
||||||
buttons.buildbutton("⚡Index Link⚡", url)
|
buttons.buildbutton("⚡Index Link⚡", url)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
if isinstance(err, RetryError):
|
if isinstance(err, RetryError):
|
||||||
|
|
@ -476,16 +495,34 @@ class GoogleDriveHelper:
|
||||||
msg += f'<h4>Results : {fileName}</h4><br><br>'
|
msg += f'<h4>Results : {fileName}</h4><br><br>'
|
||||||
for file in response.get('files', []):
|
for file in response.get('files', []):
|
||||||
if file.get('mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File.
|
if file.get('mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File.
|
||||||
msg += f"⁍<code>{file.get('name')}<br>(folder📁)</code><br>" \
|
furl = f"https://drive.google.com/drive/folders/{file.get('id')}"
|
||||||
f"<b><a href='https://drive.google.com/drive/folders/{file.get('id')}'>Drive Link</a></b>"
|
msg += f"⁍<code>{file.get('name')}<br>(folder📁)</code><br>"
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
sfurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, furl)).text
|
||||||
|
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
|
||||||
|
else:
|
||||||
|
msg += f"<b><a href={furl}>Drive Link</a></b>"
|
||||||
if INDEX_URL is not None:
|
if INDEX_URL is not None:
|
||||||
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}/')
|
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}/')
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, url)).text
|
||||||
|
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
||||||
|
else:
|
||||||
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
||||||
else:
|
else:
|
||||||
msg += f"⁍<code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})📄</code><br>" \
|
furl = f"https://drive.google.com/uc?id={file.get('id')}&export=download"
|
||||||
f"<b><a href='https://drive.google.com/uc?id={file.get('id')}&export=download'>Drive Link</a></b>"
|
msg += f"⁍<code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})📄</code><br>"
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
sfurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, furl)).text
|
||||||
|
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
|
||||||
|
else:
|
||||||
|
msg += f"<b><a href={furl}>Drive Link</a></b>"
|
||||||
if INDEX_URL is not None:
|
if INDEX_URL is not None:
|
||||||
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
|
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, url)).text
|
||||||
|
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
||||||
|
else:
|
||||||
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
||||||
msg += '<br><br>'
|
msg += '<br><br>'
|
||||||
content_count += 1
|
content_count += 1
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ from telegram.ext import CommandHandler, run_async
|
||||||
from telegram import InlineKeyboardMarkup
|
from telegram import InlineKeyboardMarkup
|
||||||
|
|
||||||
from bot import Interval, INDEX_URL, BLOCK_MEGA_LINKS
|
from bot import Interval, INDEX_URL, BLOCK_MEGA_LINKS
|
||||||
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock
|
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock, SHORTENER, SHORTENER_API
|
||||||
from bot.helper.ext_utils import fs_utils, bot_utils
|
from bot.helper.ext_utils import fs_utils, bot_utils
|
||||||
from bot.helper.ext_utils.bot_utils import setInterval
|
from bot.helper.ext_utils.bot_utils import setInterval
|
||||||
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
|
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
|
||||||
|
|
@ -93,12 +93,12 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
else:
|
else:
|
||||||
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
up_name = pathlib.PurePath(path).name
|
up_name = pathlib.PurePath(path).name
|
||||||
|
up_path = f'{DOWNLOAD_DIR}{self.uid}/{up_name}'
|
||||||
if up_name == "None":
|
if up_name == "None":
|
||||||
up_name = "".join(os.listdir(f'{DOWNLOAD_DIR}{self.uid}/'))
|
up_name = "".join(os.listdir(f'{DOWNLOAD_DIR}{self.uid}/'))
|
||||||
LOGGER.info(f"Upload Name : {up_name}")
|
LOGGER.info(f"Upload Name : {up_name}")
|
||||||
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
||||||
if size == 0:
|
size = fs_utils.get_path_size(up_path)
|
||||||
size = fs_utils.get_path_size(m_path)
|
|
||||||
upload_status = UploadStatus(drive, size, self)
|
upload_status = UploadStatus(drive, size, self)
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
download_dict[self.uid] = upload_status
|
download_dict[self.uid] = upload_status
|
||||||
|
|
@ -137,16 +137,24 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
def onUploadProgress(self):
|
def onUploadProgress(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def onUploadComplete(self, link: str):
|
def onUploadComplete(self, link: str, size):
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
msg = f'<b>Filename : </b><code>{download_dict[self.uid].name()}</code>\n<b>Size : </b><code>{download_dict[self.uid].size()}</code>'
|
msg = f'<b>Filename : </b><code>{download_dict[self.uid].name()}</code>\n<b>Size : </b><code>{size}</code>'
|
||||||
buttons = button_build.ButtonMaker()
|
buttons = button_build.ButtonMaker()
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
surl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, link)).text
|
||||||
|
buttons.buildbutton("✨Drive Link✨", surl)
|
||||||
|
else:
|
||||||
buttons.buildbutton("✨Drive Link✨", link)
|
buttons.buildbutton("✨Drive Link✨", link)
|
||||||
LOGGER.info(f'Done Uploading {download_dict[self.uid].name()}')
|
LOGGER.info(f'Done Uploading {download_dict[self.uid].name()}')
|
||||||
if INDEX_URL is not None:
|
if INDEX_URL is not None:
|
||||||
share_url = requests.utils.requote_uri(f'{INDEX_URL}/{download_dict[self.uid].name()}')
|
share_url = requests.utils.requote_uri(f'{INDEX_URL}/{download_dict[self.uid].name()}')
|
||||||
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
|
if os.path.isdir(f'{DOWNLOAD_DIR}/{self.uid}/{download_dict[self.uid].name()}'):
|
||||||
share_url += '/'
|
share_url += '/'
|
||||||
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
|
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, share_url)).text
|
||||||
|
buttons.buildbutton("⚡Index Link⚡", siurl)
|
||||||
|
else:
|
||||||
buttons.buildbutton("⚡Index Link⚡", share_url)
|
buttons.buildbutton("⚡Index Link⚡", share_url)
|
||||||
if self.message.from_user.username:
|
if self.message.from_user.username:
|
||||||
uname = f"@{self.message.from_user.username}"
|
uname = f"@{self.message.from_user.username}"
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from telegram.ext import CallbackContext, Filters, run_async, CommandHandler
|
||||||
|
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
def speedtst(update, context):
|
def speedtest(update, context):
|
||||||
message = update.effective_message
|
message = update.effective_message
|
||||||
ed_msg = message.reply_text("Running Speed Test . . . ")
|
ed_msg = message.reply_text("Running Speed Test . . . ")
|
||||||
test = Speedtest()
|
test = Speedtest()
|
||||||
|
|
@ -18,16 +18,16 @@ def speedtst(update, context):
|
||||||
result = test.results.dict()
|
result = test.results.dict()
|
||||||
path = (result['share'])
|
path = (result['share'])
|
||||||
string_speed = f'''
|
string_speed = f'''
|
||||||
📬 <b>Server</b>
|
<b>Server</b>
|
||||||
🌀 <b>Name:</b> <code>{result['server']['name']}</code>
|
<b>Name:</b> <code>{result['server']['name']}</code>
|
||||||
🏁 <b>Country:</b> <code>{result['server']['country']}, {result['server']['cc']}</code>
|
<b>Country:</b> <code>{result['server']['country']}, {result['server']['cc']}</code>
|
||||||
🌐 <b>Sponsor:</b> <code>{result['server']['sponsor']}</code>
|
<b>Sponsor:</b> <code>{result['server']['sponsor']}</code>
|
||||||
|
|
||||||
<b>SpeedTest Results</b>
|
<b>SpeedTest Results</b>
|
||||||
🔼 <b>Upload:</b> <code>{speed_convert(result['upload'] / 8)}</code>
|
<b>Upload:</b> <code>{speed_convert(result['upload'] / 8)}</code>
|
||||||
🔽 <b>Download:</b> <code>{speed_convert(result['download'] / 8)}</code>
|
<b>Download:</b> <code>{speed_convert(result['download'] / 8)}</code>
|
||||||
📶 <b>Ping:</b> <code>{result['ping']} ms</code>
|
<b>Ping:</b> <code>{result['ping']} ms</code>
|
||||||
🖥️ <b>ISP:</b> <code>{result['client']['isp']}</code>
|
<b>ISP:</b> <code>{result['client']['isp']}</code>
|
||||||
'''
|
'''
|
||||||
ed_msg.delete()
|
ed_msg.delete()
|
||||||
try:
|
try:
|
||||||
|
|
@ -46,7 +46,7 @@ def speed_convert(size):
|
||||||
return f"{round(size, 2)} {units[zero]}"
|
return f"{round(size, 2)} {units[zero]}"
|
||||||
|
|
||||||
|
|
||||||
SPEED_HANDLER = CommandHandler(BotCommands.SpeedCommand, speedtst,
|
SPEED_HANDLER = CommandHandler(BotCommands.SpeedCommand, speedtest,
|
||||||
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
|
||||||
|
|
||||||
dispatcher.add_handler(SPEED_HANDLER)
|
dispatcher.add_handler(SPEED_HANDLER)
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,16 @@ def _watch(bot: Bot, update: Update, args: list, isTar=False):
|
||||||
try:
|
try:
|
||||||
link = args[0]
|
link = args[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
sendMessage(f'/{BotCommands.WatchCommand} [yt_dl supported link] to mirror with youtube_dl', bot, update)
|
msg = f"/{BotCommands.WatchCommand} [yt_dl supported link] [quality] to mirror with youtube_dl.\n\n"
|
||||||
|
msg += "Example of quality :- audio, 144, 360, 720, 1080.\nNote :- Quality is optional"
|
||||||
|
sendMessage(msg, bot, update)
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
|
qual = args[1]
|
||||||
|
if qual != "audio":
|
||||||
|
qual = f'bestvideo[height<={qual}]+bestaudio/best[height<={qual}]'
|
||||||
|
except IndexError:
|
||||||
|
qual = "bestvideo+bestaudio/best"
|
||||||
reply_to = update.message.reply_to_message
|
reply_to = update.message.reply_to_message
|
||||||
if reply_to is not None:
|
if reply_to is not None:
|
||||||
tag = reply_to.from_user.username
|
tag = reply_to.from_user.username
|
||||||
|
|
@ -24,7 +32,7 @@ def _watch(bot: Bot, update: Update, args: list, isTar=False):
|
||||||
|
|
||||||
listener = MirrorListener(bot, update, isTar, tag)
|
listener = MirrorListener(bot, update, isTar, tag)
|
||||||
ydl = YoutubeDLHelper(listener)
|
ydl = YoutubeDLHelper(listener)
|
||||||
threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}')).start()
|
threading.Thread(target=ydl.add_download,args=(link, f'{DOWNLOAD_DIR}{listener.uid}', qual)).start()
|
||||||
sendStatusMessage(update, bot)
|
sendStatusMessage(update, bot)
|
||||||
if len(Interval) == 0:
|
if len(Interval) == 0:
|
||||||
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
|
Interval.append(setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages))
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,5 @@ MEGA_API_KEY = ""
|
||||||
MEGA_EMAIL_ID = ""
|
MEGA_EMAIL_ID = ""
|
||||||
MEGA_PASSWORD = ""
|
MEGA_PASSWORD = ""
|
||||||
BLOCK_MEGA_LINKS = ""
|
BLOCK_MEGA_LINKS = ""
|
||||||
|
SHORTENER = ""
|
||||||
|
SHORTENER_API = ""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue