diff --git a/bot/__main__.py b/bot/__main__.py index 75bbeeadd..22d9b63e7 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -75,6 +75,8 @@ def bot_help(update, context): /{BotCommands.UnzipMirrorCommand} [download_url][magnet_link] : starts mirroring and if downloaded file is any archive , extracts it to google drive +/{BotCommands.SearchMirrorCommand} [query_string] : search and mirror from torrent websites to google drive + /{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. Click /{BotCommands.WatchCommand} for more help. diff --git a/bot/helper/ext_utils/torrent_search_utils.py b/bot/helper/ext_utils/torrent_search_utils.py new file mode 100644 index 000000000..04c8121d5 --- /dev/null +++ b/bot/helper/ext_utils/torrent_search_utils.py @@ -0,0 +1,19 @@ +import requests +from bot import LOGGER + +def search_torrent_link(query): + LOGGER.info("Searching torrent on query") + query = query.replace("/", "") + try: + r = requests.get( + "https://torrent-paradise.ml/api/search?q=" + query) + torrents = r.json() + torrents = sorted(torrents, key=lambda i: i['s'], reverse=True) + torrent = torrents[0] + except: + return "not found" + LOGGER.info("Torrent Found") + reply = "" + reply += "magnet:?xt=urn:btih:" + torrent['id'] + reply += "&tr=udp://tracker.coppersurfer.tk:6969/announce&tr=udp://tracker.opentrackr.org:1337/announce&tr=udp://tracker.leechers-paradise.org:6969/announce" + return reply \ No newline at end of file diff --git a/bot/helper/telegram_helper/bot_commands.py b/bot/helper/telegram_helper/bot_commands.py index bd1af0c25..9e0a7ca14 100644 --- a/bot/helper/telegram_helper/bot_commands.py +++ b/bot/helper/telegram_helper/bot_commands.py @@ -2,6 +2,7 @@ class _BotCommands: def __init__(self): self.StartCommand = 'start' self.MirrorCommand = 'mirror' + self.SearchMirrorCommand = "searchmirror" self.UnzipMirrorCommand = 'unzipmirror' self.TarMirrorCommand = 'tarmirror' self.CancelMirror = 'cancel' diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index 54aed781e..c28006e72 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -5,6 +5,7 @@ from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock from bot.helper.ext_utils import fs_utils, bot_utils from bot.helper.ext_utils.bot_utils import setInterval +from bot.helper.ext_utils.torrent_search_utils import search_torrent_link from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive from bot.helper.mirror_utils.download_utils.aria2_download import AriaDownloadHelper from bot.helper.mirror_utils.download_utils.direct_link_generator import direct_link_generator @@ -170,12 +171,20 @@ def onUploadError(self, error): else: update_all_messages() -def _mirror(bot, update, isTar=False, extract=False): - message_args = update.message.text.split(' ') - try: - link = message_args[1] - except IndexError: - link = '' +def _mirror(bot, update, isTar=False, extract=False, search=False): + if search: + LOGGER.info(update.message.text) + query = update.message.text.replace(BotCommands.SearchMirrorCommand,"") + link = search_torrent_link(query) + LOGGER.info(link) + if link == "not found": + link = '' + else: + message_args = update.message.text.split(' ') + try: + link = message_args[1] + except IndexError: + link = '' LOGGER.info(link) link = link.strip() reply_to = update.message.reply_to_message @@ -203,7 +212,10 @@ def _mirror(bot, update, isTar=False, extract=False): else: tag = None if not bot_utils.is_url(link) and not bot_utils.is_magnet(link): - sendMessage('No download source provided', bot, update) + if search: + sendMessage('Provided query did\'nt return any result, \n Try Again with right name or Torrent API may be down', bot , update) + else: + sendMessage('No download source provided', bot, update) return try: @@ -229,9 +241,13 @@ def tar_mirror(update, context): def unzip_mirror(update, context): _mirror(context.bot,update, extract=True) +def search_mirror(update, context): + _mirror(context.bot, update, search=True) mirror_handler = CommandHandler(BotCommands.MirrorCommand, mirror, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) +search_mirror_handler = CommandHandler(BotCommands.SearchMirrorCommand, search_mirror, + filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) tar_mirror_handler = CommandHandler(BotCommands.TarMirrorCommand, tar_mirror, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True) unzip_mirror_handler = CommandHandler(BotCommands.UnzipMirrorCommand, unzip_mirror, @@ -239,3 +255,4 @@ def unzip_mirror(update, context): dispatcher.add_handler(mirror_handler) dispatcher.add_handler(tar_mirror_handler) dispatcher.add_handler(unzip_mirror_handler) +dispatcher.add_handler(search_mirror_handler)