Initializing aria2c at bot startup

- Fix leech thumbnail/video size
- Fix gdtot delete first cloned file after if duplicated

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2021-12-05 12:33:42 +02:00
parent 1b6b681165
commit 38c60139af
11 changed files with 38 additions and 26 deletions

View File

@ -25,7 +25,7 @@ This is a Telegram Bot written in Python for mirroring files on the Internet to
- Search for torrents with Torrent Search API
- Docker image support for `linux/amd64, linux/arm64, linux/arm/v7, linux/arm/v6` (**Note**: Use `anasty17/mltb-oracle:latest` for oracle or if u faced problem with arm64 docker run)
- Update bot at startup and with restart command using `UPSTREAM_REPO`
- Clone/zip/unzip from gdtot links (main script from [Yusuf](https://github.com/oxosec)) and delete first cloned file from main drive or TeamDrive
- Clone/Zip/Unzip/Count from gdtot links (main script from [Yusuf](https://github.com/oxosec)) and delete first cloned file from main drive or TeamDrive
- Many bugs have been fixed
## From Other Repositories

View File

@ -112,6 +112,23 @@ trackerslist = "\n\n".join(trackerslist)
get_client().application.set_preferences({"add_trackers":f"{trackerslist}"})
"""
def aria2c_init():
try:
if not os.path.isfile(".restartmsg"):
logging.info("Initializing Aria2c")
link = "https://releases.ubuntu.com/21.10/ubuntu-21.10-desktop-amd64.iso.torrent"
path = "/usr/src/app/"
aria2.add_uris([link], {'dir': path})
time.sleep(3)
downloads = aria2.get_downloads()
time.sleep(30)
for download in downloads:
aria2.remove([download], force=True, files=True)
except Exception as e:
logging.error(f"Aria2c initializing error: {e}")
pass
threading.Thread(target=aria2c_init).start()
DOWNLOAD_DIR = None
BOT_TOKEN = None

View File

@ -167,7 +167,7 @@ def get_readable_message():
dlspeed_bytes += float(speedy.split('M')[0]) * 1048576
if download.status() == MirrorStatus.STATUS_UPLOADING:
if 'KB/s' in speedy:
uldl_bytes += float(speedy.split('K')[0]) * 1024
uldl_bytes += float(speedy.split('K')[0]) * 1024
elif 'MB/s' in speedy:
uldl_bytes += float(speedy.split('M')[0]) * 1048576
dlspeed = get_readable_file_size(dlspeed_bytes)

View File

@ -29,7 +29,7 @@ def start_cleanup():
def clean_all():
aria2.remove_all(True)
get_client().torrents_delete(torrent_hashes="all", delete_files=True)
get_client().torrents_delete(torrent_hashes="all")
try:
shutil.rmtree(DOWNLOAD_DIR)
except FileNotFoundError:
@ -167,10 +167,7 @@ def take_ss(video_file):
if not os.path.lexists(des_dir):
return None
Image.open(des_dir).convert("RGB").save(des_dir)
img = Image.open(des_dir)
img.resize((480, 320))
img.save(des_dir, "JPEG")
Image.open(des_dir).convert("RGB").save(des_dir, "JPEG")
return des_dir
def split(path, size, filee, dirpath, split_size, start_time=0, i=1, inLoop=False):

View File

@ -73,7 +73,7 @@ class AriaDownloadStatus(Status):
def getListener(self):
return self.__listener
def uid(self):
return self.__uid

View File

@ -679,7 +679,7 @@ class GoogleDriveHelper:
elif not response["files"]:
continue
if not Title:
msg += f'<h4>Search Result For {fileName}</h4><br><br>'
msg += f'<h4>Search Result For {fileName}</h4>'
Title = True
if len(DRIVES_NAMES) > 1 and DRIVES_NAMES[index] is not None:
msg += f"╾────────────╼<br><b>{DRIVES_NAMES[index]}</b><br>╾────────────╼<br>"

View File

@ -4,6 +4,7 @@ import time
import threading
from pyrogram.errors import FloodWait, RPCError
from PIL import Image
from bot import app, DOWNLOAD_DIR, AS_DOCUMENT, AS_DOC_USERS, AS_MEDIA_USERS, CUSTOM_FILENAME
from bot.helper.ext_utils.fs_utils import take_ss, get_media_info
@ -83,6 +84,8 @@ class TgUploader:
if self.thumb is None and thumb is not None and os.path.lexists(thumb):
os.remove(thumb)
return
img = Image.open(thumb)
width, height = img.size
if not filee.upper().endswith(("MKV", "MP4")):
filee = os.path.splitext(filee)[0] + '.mp4'
new_path = os.path.join(dirpath, filee)
@ -93,8 +96,8 @@ class TgUploader:
caption=cap_mono,
parse_mode="html",
duration=duration,
width=480,
height=320,
width=width,
height=height,
thumb=thumb,
supports_streaming=True,
disable_notification=True,

View File

@ -39,6 +39,8 @@ def cloneNode(update, context):
if smsg:
msg3 = "File/Folder is already available in Drive.\nHere are the search results:"
sendMarkup(msg3, context.bot, update, button)
if gdtot_link:
gd.deletefile(link)
return
if CLONE_LIMIT is not None:
LOGGER.info('Checking File/Folder Size...')

View File

@ -1,7 +1,4 @@
# Implement By - @anasty17 (https://github.com/SlamDevs/slam-mirrorbot/commit/d888a1e7237f4633c066f7c2bbfba030b83ad616)
# Leech Settings V2 Implement By - @VarnaX-279
# (c) https://github.com/SlamDevs/slam-mirrorbot
# All rights reserved
import os
import threading
@ -32,16 +29,16 @@ def getleechinfo(from_user):
else:
ltype = "MEDIA"
buttons.sbutton("Send As Document", f"doc {user_id}")
if os.path.exists(thumbpath):
thumbmsg = "Exists"
buttons.sbutton("Delete Thumbnail", f"thumb {user_id}")
else:
thumbmsg = "Not Exists"
if AUTO_DELETE_MESSAGE_DURATION == -1:
buttons.sbutton("Close", f"closeset {user_id}")
button = InlineKeyboardMarkup(buttons.build_menu(1))
text = f"<u>Leech Settings for <a href='tg://user?id={user_id}'>{name}</a></u>\n"\
@ -103,9 +100,7 @@ def setThumb(update, context):
photo_msg = app.get_messages(update.message.chat.id, reply_to_message_ids=update.message.message_id)
photo_dir = app.download_media(photo_msg, file_name=path)
des_dir = os.path.join(path, str(user_id) + ".jpg")
img = Image.open(photo_dir)
img.thumbnail((480, 320))
img.save(des_dir, "JPEG")
Image.open(photo_dir).convert("RGB").save(des_dir, "JPEG")
os.remove(photo_dir)
sendMessage(f"Custom thumbnail saved for <a href='tg://user?id={user_id}'>{update.message.from_user.full_name}</a> .", context.bot, update)
else:

View File

@ -415,12 +415,9 @@ def _mirror(bot, update, isZip=False, extract=False, isQbit=False, isLeech=False
link = direct_link_generator(link)
except DirectDownloadLinkException as e:
LOGGER.info(e)
if "ERROR:" in str(e):
sendMessage(str(e), bot, update)
return
if "Youtube" in str(e):
sendMessage(str(e), bot, update)
return
if "ERROR:" in str(e) or "Youtube" in str(e):
return sendMessage(str(e), bot, update)
if bot_utils.is_gdrive_link(link):
if not isZip and not extract and not isLeech:

View File

@ -3,6 +3,7 @@ Accepted=true
[BitTorrent]
Session\AsyncIOThreadsCount=8
Session\MultiConnectionsPerIp=true
Session\SlowTorrentsDownloadRate=100
Session\SlowTorrentsInactivityTimer=600