Skip to content

Commit

Permalink
Cherry-pick from anasty17
Browse files Browse the repository at this point in the history
/mltb
- (fbcb951) Edit help message
- (7697082) Minor Fixes
- (eace91d) mino fix for bulk
- (fb355b5) Break Usage Changes

Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
junedkh committed Jun 9, 2023
1 parent cd5e35e commit 6b87fde
Show file tree
Hide file tree
Showing 20 changed files with 577 additions and 698 deletions.
17 changes: 5 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ In each single file there is a major change from base code, it's almost totaly d
- Queueing System for all tasks
- Ability to zip/unzip multi links in same directory. Mostly helpful in unziping tg file parts
- Bulk download from telegram txt file or text message contains links seperated by new line
- Join splitted files that have splitted before by split linux pkg
- Almost all repository functions have been improved and many other details can't mention all of them
- Many bugs have been fixed

Expand Down Expand Up @@ -471,23 +472,15 @@ sudo docker image prune -a

```
mirror - or /m Mirror
zipmirror - or /zm Mirror and upload as zip
unzipmirror - or /uzm Mirror and extract files
qbmirror - or /qm Mirror torrent using qBittorrent
qbzipmirror - or /qzm Mirror torrent using qb and upload as zip
qbunzipmirror - or /quzm Mirror torrent using qb and extract files
leech - or /l Leech
zipleech - or /zl Leech and upload as zip
unzipleech - or /uzl Leech and extract files
qbleech - or /ql Leech torrent using qBittorrent
qbzipleech - or /qzl Leech torrent using qb and upload as zip
qbunzipleech - or /quzl Leech torrent using qb and extract
clone - Copy file/folder to Drive
count - Count file/folder from Drive
ytdl - or /y Mirror yt-dlp supported link
ytdlzip - or /yz Mirror yt-dlp supported link as zip
ytdlleech - or /yl Leech through yt-dlp supported link
ytdlzipleech - or /yzl Leech yt-dlp support link as zip
clone - Copy file/folder to Drive
count - Count file/folder from Drive
usetting - User settings
status - Get Mirror Status message
btsel - Select files from torrent
Expand Down Expand Up @@ -563,8 +556,7 @@ python3 generate_drive_token.py

## Bittorrent Seed

- Add `d:ratio:time` prefix along with leech or mirror cmd.
- Using `d` prefix alone will lead to use global options for aria2c or qbittorrent.
- Using `-d` argument alone will lead to use global options for aria2c or qbittorrent.

### Qbittorrent

Expand Down Expand Up @@ -797,6 +789,7 @@ Where host is the name of extractor (eg. instagram, Twitch). Multiple accounts o
[!["Buy Me A Coffee"](https://storage.ko-fi.com/cdn/kofi2.png)](https://ko-fi.com/anasty17)

Binance ID:

```
52187862
```
Expand Down
2 changes: 1 addition & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
if len(USER_SESSION_STRING) != 0:
log_info("Creating client from USER_SESSION_STRING")
user = tgClient('user', TELEGRAM_API, TELEGRAM_HASH, session_string=USER_SESSION_STRING,
parse_mode=enums.ParseMode.HTML, no_updates=True, max_concurrent_transmissions=1000).start()
parse_mode=enums.ParseMode.HTML, max_concurrent_transmissions=1000).start()
if user.me.is_bot:
log_warning(
"You added bot string for USER_SESSION_STRING this is not allowed! Exiting now")
Expand Down
10 changes: 0 additions & 10 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,11 @@ async def log(_, message):
help_string = f'''
NOTE: Try each command without any argument to see more detalis.
/{BotCommands.MirrorCommand[0]} or /{BotCommands.MirrorCommand[1]}: Start mirroring to Google Drive.
/{BotCommands.ZipMirrorCommand[0]} or /{BotCommands.ZipMirrorCommand[1]}: Start mirroring and upload the file/folder compressed with zip extension.
/{BotCommands.UnzipMirrorCommand[0]} or /{BotCommands.UnzipMirrorCommand[1]}: Start mirroring and upload the file/folder extracted from any archive extension.
/{BotCommands.QbMirrorCommand[0]} or /{BotCommands.QbMirrorCommand[1]}: Start Mirroring to Google Drive using qBittorrent.
/{BotCommands.QbZipMirrorCommand[0]} or /{BotCommands.QbZipMirrorCommand[1]}: Start mirroring using qBittorrent and upload the file/folder compressed with zip extension.
/{BotCommands.QbUnzipMirrorCommand[0]} or /{BotCommands.QbUnzipMirrorCommand[1]}: Start mirroring using qBittorrent and upload the file/folder extracted from any archive extension.
/{BotCommands.YtdlCommand[0]} or /{BotCommands.YtdlCommand[1]}: Mirror yt-dlp supported link.
/{BotCommands.YtdlZipCommand[0]} or /{BotCommands.YtdlZipCommand[1]}: Mirror yt-dlp supported link as zip.
/{BotCommands.LeechCommand[0]} or /{BotCommands.LeechCommand[1]}: Start leeching to Telegram.
/{BotCommands.ZipLeechCommand[0]} or /{BotCommands.ZipLeechCommand[1]}: Start leeching and upload the file/folder compressed with zip extension.
/{BotCommands.UnzipLeechCommand[0]} or /{BotCommands.UnzipLeechCommand[1]}: Start leeching and upload the file/folder extracted from any archive extension.
/{BotCommands.QbLeechCommand[0]} or /{BotCommands.QbLeechCommand[1]}: Start leeching using qBittorrent.
/{BotCommands.QbZipLeechCommand[0]} or /{BotCommands.QbZipLeechCommand[1]}: Start leeching using qBittorrent and upload the file/folder compressed with zip extension.
/{BotCommands.QbUnzipLeechCommand[0]} or /{BotCommands.QbUnzipLeechCommand[1]}: Start leeching using qBittorrent and upload the file/folder extracted from any archive extension.
/{BotCommands.YtdlLeechCommand[0]} or /{BotCommands.YtdlLeechCommand[1]}: Leech yt-dlp supported link.
/{BotCommands.YtdlZipLeechCommand[0]} or /{BotCommands.YtdlZipLeechCommand[1]}: Leech yt-dlp supported link as zip.
/{BotCommands.CloneCommand} [drive_url]: Copy file/folder to Google Drive.
/{BotCommands.CountCommand} [drive_url]: Count file/folder of Google Drive.
/{BotCommands.DeleteCommand} [drive_url]: Delete file/folder from Google Drive (Only Owner & Sudo).
Expand Down
48 changes: 12 additions & 36 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
from html import escape
from re import match as re_match
from time import time
from urllib.request import urlopen
from html import escape
from uuid import uuid4

from psutil import cpu_percent, disk_usage, virtual_memory
from psutil import virtual_memory, cpu_percent, disk_usage, virtual_memory
from pyrogram.types import BotCommand
from requests import head as rhead
from asyncio import create_subprocess_exec, create_subprocess_shell, run_coroutine_threadsafe, sleep
from asyncio.subprocess import PIPE
from functools import partial, wraps
from concurrent.futures import ThreadPoolExecutor
from aiohttp import ClientSession

from bot import (bot_loop, bot_name, botStartTime, config_dict, download_dict,
download_dict_lock, extra_buttons, user_data)
Expand Down Expand Up @@ -236,6 +239,7 @@ def is_url(url):
def is_gdrive_link(url):
return "drive.google.com" in url


def is_telegram_link(url):
return url.startswith(('https://t.me/', 'tg://openmessage?user_id='))

Expand All @@ -259,18 +263,10 @@ def get_mega_link_type(url):
return "folder" if "folder" in url or "/#F!" in url else "file"


def get_content_type(link):
try:
res = rhead(link, allow_redirects=True, timeout=5,
headers={'user-agent': 'Wget/1.12'})
content_type = res.headers.get('content-type')
except:
try:
res = urlopen(link, timeout=5)
content_type = res.info().get_content_type()
except:
content_type = None
return content_type
async def get_content_type(url):
async with ClientSession(trust_env=True) as session:
async with session.get(url) as response:
return response.headers.get('Content-Type')


def update_user_ldata(id_, key, value):
Expand Down Expand Up @@ -357,34 +353,14 @@ async def set_commands(client):
f'{BotCommands.MirrorCommand[0]}', f'or /{BotCommands.MirrorCommand[1]} Mirror'),
BotCommand(
f'{BotCommands.LeechCommand[0]}', f'or /{BotCommands.LeechCommand[1]} Leech'),
BotCommand(
f'{BotCommands.ZipMirrorCommand[0]}', f'or /{BotCommands.ZipMirrorCommand[1]} Mirror and upload as zip'),
BotCommand(
f'{BotCommands.ZipLeechCommand[0]}', f'or /{BotCommands.ZipLeechCommand[1]} Leech and upload as zip'),
BotCommand(
f'{BotCommands.UnzipMirrorCommand[0]}', f'or /{BotCommands.UnzipMirrorCommand[1]} Mirror and extract files'),
BotCommand(
f'{BotCommands.UnzipLeechCommand[0]}', f'or /{BotCommands.UnzipLeechCommand[1]} Leech and extract files'),
BotCommand(
f'{BotCommands.QbMirrorCommand[0]}', f'or /{BotCommands.QbMirrorCommand[1]} Mirror torrent using qBittorrent'),
BotCommand(
f'{BotCommands.QbLeechCommand[0]}', f'or /{BotCommands.QbLeechCommand[1]} Leech torrent using qBittorrent'),
BotCommand(
f'{BotCommands.QbZipMirrorCommand[0]}', f'or /{BotCommands.QbZipMirrorCommand[1]} Mirror torrent and upload as zip using qb'),
BotCommand(
f'{BotCommands.QbZipLeechCommand[0]}', f'or /{BotCommands.QbZipLeechCommand[1]} Leech torrent and upload as zip using qb'),
BotCommand(
f'{BotCommands.QbUnzipMirrorCommand[0]}', f'or /{BotCommands.QbUnzipMirrorCommand[1]} Mirror torrent and extract files using qb'),
BotCommand(
f'{BotCommands.QbUnzipLeechCommand[0]}', f'or /{BotCommands.QbUnzipLeechCommand[1]} Leech torrent and extract using qb'),
BotCommand(
f'{BotCommands.YtdlCommand[0]}', f'or /{BotCommands.YtdlCommand[1]} Mirror yt-dlp supported link'),
BotCommand(
f'{BotCommands.YtdlLeechCommand[0]}', f'or /{BotCommands.YtdlLeechCommand[1]} Leech through yt-dlp supported link'),
BotCommand(
f'{BotCommands.YtdlZipCommand[0]}', f'or /{BotCommands.YtdlZipCommand[1]} Mirror yt-dlp supported link as zip'),
BotCommand(
f'{BotCommands.YtdlZipLeechCommand[0]}', f'or /{BotCommands.YtdlZipLeechCommand[1]} Leech yt-dlp support link as zip'),
BotCommand(f'{BotCommands.CloneCommand}',
'Copy file/folder to Drive'),
BotCommand(
Expand Down
4 changes: 2 additions & 2 deletions bot/helper/ext_utils/bulk_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

async def get_links_from_message(text, bulk_start, bulk_end):
links_list = text.split('\n')
links_list = [item for item in links_list if len(item) != 0]
links_list = [item.strip() for item in links_list if len(item) != 0]

if bulk_start != 0 and bulk_end != 0:
links_list = links_list[bulk_start:bulk_end]
Expand All @@ -23,7 +23,7 @@ async def get_links_from_file(message, bulk_start, bulk_end):

async with aiopen(text_file_dir, 'r+') as f:
lines = await f.readlines()
links_list.extend(line for line in lines if len(line) != 0)
links_list.extend(line.strip() for line in lines if len(line) != 0)

if bulk_start != 0 and bulk_end != 0:
links_list = links_list[bulk_start:bulk_end]
Expand Down
5 changes: 5 additions & 0 deletions bot/helper/ext_utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ class NotSupportedExtractionArchive(Exception):
class RssShutdownException(Exception):
"""This exception should be raised when shutdown is called to stop the montior"""
pass


class TgLinkException(Exception):
"""No Access granted for this chat"""
pass
21 changes: 20 additions & 1 deletion bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from .exceptions import NotSupportedExtractionArchive
from bot import aria2, LOGGER, DOWNLOAD_DIR, get_client, GLOBAL_EXTENSION_FILTER
from bot.helper.ext_utils.bot_utils import sync_to_async, async_to_sync
from bot.helper.ext_utils.bot_utils import sync_to_async, cmd_exec, async_to_sync
from bot.helper.ext_utils.telegraph_helper import telegraph


Expand Down Expand Up @@ -149,6 +149,25 @@ def get_mime_type(file_path):
return mime_type


async def join_files(path):
files = await listdir(path)
results = []
for file_ in files:
if re_search(r"\.0+2$", file_) and await sync_to_async(get_mime_type, f'{path}/{file_}') == 'application/octet-stream':
final_name = file_.rsplit('.', 1)[0]
cmd = f'cat {path}/{final_name}.* > {path}/{final_name}'
_, stderr, code = await cmd_exec(cmd, True)
if code != 0:
LOGGER.error(f'Failed to join {final_name}, stderr: {stderr}')
else:
results.append(final_name)
if results:
for res in results:
for file_ in files:
if re_search(fr"{res}\.0[0-9]+$", file_):
await aioremove(f'{path}/{file_}')


def check_storage_threshold(size, threshold, arch=False, alloc=False):
free = disk_usage(DOWNLOAD_DIR).free
if not alloc:
Expand Down
Loading

0 comments on commit 6b87fde

Please sign in to comment.