Exemplo n.º 1
0
def clean_all():
    aria2.remove_all(True)
    get_client().torrents_delete(torrent_hashes="all", delete_files=True)
    try:
        shutil.rmtree(DOWNLOAD_DIR)
    except FileNotFoundError:
        pass
Exemplo n.º 2
0
 def clean(self):
     try:
         aria2.purge()
         get_client().torrents_delete(torrent_hashes="all",
                                      delete_files=True)
         Interval[0].cancel()
         del Interval[0]
         delete_all_messages()
     except IndexError:
         pass
Exemplo n.º 3
0
def clean_all():
    aria2.remove_all(True)
    qbc = get_client()
    qbc.torrents_delete(torrent_hashes="all", delete_files=True)
    qbc.app_shutdown()
    try:
        rmtree(DOWNLOAD_DIR)
    except FileNotFoundError:
        pass
Exemplo n.º 4
0
def _plugin_buttons(user_id):
    buttons = button_build.ButtonMaker()
    if not PLUGINS:
        qbclient = get_client()
        pl = qbclient.search_plugins()
        for name in pl:
            PLUGINS.append(name['name'])
        qbclient.auth_log_out()
    for siteName in PLUGINS:
        buttons.sbutton(siteName.capitalize(),
                        f"torser {user_id} {siteName} plugin")
    buttons.sbutton('All', f"torser {user_id} all plugin")
    buttons.sbutton("Cancel", f"torser {user_id} cancel")
    button = InlineKeyboardMarkup(buttons.build_menu(2))
    return button
Exemplo n.º 5
0
def _search(key, site, message, tool):
    LOGGER.info(f"Searching: {key} from {site}")
    if tool == 'api':
        api = f"{SEARCH_API_LINK}/api/{site}/{key}"
        try:
            resp = rget(api)
            search_results = resp.json()
            if site == "all":
                search_results = list(
                    itertools.chain.from_iterable(search_results))
            if isinstance(search_results, list):
                msg = f"<b>Found {min(len(search_results), SEARCH_LIMIT)}</b>"
                msg += f" <b>result for <i>{key}</i>\nTorrent Site:- <i>{SITES.get(site)}</i></b>"
            else:
                return editMessage(
                    f"No result found for <i>{key}</i>\nTorrent Site:- <i>{SITES.get(site)}</i>",
                    message)
        except Exception as e:
            editMessage(str(e), message)
    else:
        client = get_client()
        search = client.search_start(pattern=str(key),
                                     plugins=str(site),
                                     category='all')
        search_id = search.id
        while True:
            result_status = client.search_status(search_id=search_id)
            status = result_status[0].status
            if status != 'Running':
                break
        dict_search_results = client.search_results(search_id=search_id)
        search_results = dict_search_results.results
        total_results = dict_search_results.total
        if total_results != 0:
            msg = f"<b>Found {min(total_results, SEARCH_LIMIT)}</b>"
            msg += f" <b>result for <i>{key}</i>\nTorrent Site:- <i>{site.capitalize()}</i></b>"
        else:
            return editMessage(
                f"No result found for <i>{key}</i>\nTorrent Site:- <i>{site.capitalize()}</i>",
                message)
    link = _getResult(search_results, key, message, tool)
    buttons = button_build.ButtonMaker()
    buttons.buildbutton("🔎 VIEW", link)
    button = InlineKeyboardMarkup(buttons.build_menu(1))
    editMessage(msg, message, button)
    if tool != 'api':
        client.search_delete(search_id=search_id)
Exemplo n.º 6
0
 def add_torrent(self, link, dire, listener, qbitsel):
     self.client = get_client()
     self.listener = listener
     is_file = False
     count = 0
     pincode = ""
     markup = None
     try:
         if os.path.exists(link):
             is_file = True
             self.ext_hash = get_hash_file(link)
         else:
             self.ext_hash = get_hash_magnet(link)
         tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
         if len(tor_info) > 0:
             sendMessage("This torrent is already in list.", listener.bot, listener.update)
             return
         if is_file:
             op = self.client.torrents_add(torrent_files=[link], save_path=dire)
             os.remove(link)
         else:
             op = self.client.torrents_add(link, save_path=dire)
         if op.lower() == "ok.":
             LOGGER.info(f"QbitDownload started: {self.ext_hash}")
             tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
             if len(tor_info) == 0:
                 while True:
                     if time.time() - self.meta_time >= 300:
                         sendMessage("The torrent was not added. report when u see this error", listener.bot, listener.update)
                         return False
                     tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
                     if len(tor_info) > 0:
                         break
         else:
             sendMessage("This is an unsupported/invalid link.", listener.bot, listener.update)
             return
         gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
         with download_dict_lock:
             download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client)
         self.updater = setInterval(self.update_interval, self.update)
         tor_info = tor_info[0]
         if BASE_URL is not None and qbitsel:
             if not is_file and (tor_info.state == "checkingResumeData" or tor_info.state == "metaDL"):
                 meta = sendMessage("Downloading Metadata...Please wait then you can select files or mirror torrent file if it have low seeders", listener.bot, listener.update)
                 while True:
                         tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
                         if len(tor_info) == 0:
                             deleteMessage(listener.bot, meta)
                             return False
                         tor_info = tor_info[0]
                         if tor_info.state == "metaDL" or tor_info.state == "checkingResumeData":
                             time.sleep(1)
                         else:
                             break  
                 deleteMessage(listener.bot, meta)
             for n in str(self.ext_hash):
                 if n.isdigit():
                     pincode += str(n)
                     count += 1
                 if count == 4:
                     break
             URL = f"{BASE_URL}/slam/files/{self.ext_hash}"
             pindata = f"pin {gid} {pincode}"
             donedata = f"done {gid} {self.ext_hash}"
             buttons = button_build.ButtonMaker()
             buttons.buildbutton("Select Files", URL)
             buttons.sbutton("Pincode", pindata)
             buttons.sbutton("Done Selecting", donedata)
             QBBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
             msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
             markup = sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
             self.client.torrents_pause(torrent_hashes=self.ext_hash)
             with download_dict_lock:
                 download = download_dict[listener.uid]
                 download.markup = markup
         else:
             sendStatusMessage(listener.update, listener.bot)
     except qba.UnsupportedMediaType415Error as e:
         LOGGER.error(str(e))
         sendMessage("This is an unsupported/invalid link. {str(e)}", listener.bot, listener.update)
     except Exception as e:
         LOGGER.error(str(e))
         sendMessage(str(e), listener.bot, listener.update)
         self.client.torrents_delete(torrent_hashes=self.ext_hash)
Exemplo n.º 7
0
def add_qb_torrent(link, path, listener, select):
    client = get_client()
    pincode = ""
    try:
        if ospath.exists(link):
            is_file = True
            ext_hash = _get_hash_file(link)
        else:
            is_file = False
            ext_hash = _get_hash_magnet(link)
        tor_info = client.torrents_info(torrent_hashes=ext_hash)
        if len(tor_info) > 0:
            sendMessage("This Torrent is already in list.", listener.bot,
                        listener.update)
            client.auth_log_out()
            return
        if is_file:
            op = client.torrents_add(torrent_files=[link], save_path=path)
            osremove(link)
        else:
            op = client.torrents_add(link, save_path=path)
        sleep(0.3)
        if op.lower() == "ok.":
            meta_time = time()
            tor_info = client.torrents_info(torrent_hashes=ext_hash)
            if len(tor_info) == 0:
                while True:
                    if time() - meta_time >= 30:
                        ermsg = "The Torrent was not added. Report when you see this error"
                        sendMessage(ermsg, listener.bot, listener.update)
                        client.torrents_delete(torrent_hashes=ext_hash,
                                               delete_files=True)
                        client.auth_log_out()
                        return
                    tor_info = client.torrents_info(torrent_hashes=ext_hash)
                    if len(tor_info) > 0:
                        break
        else:
            sendMessage("This is an unsupported/invalid link.", listener.bot,
                        listener.update)
            client.torrents_delete(torrent_hashes=ext_hash, delete_files=True)
            client.auth_log_out()
            return
        tor_info = tor_info[0]
        ext_hash = tor_info.hash
        gid = ''.join(random.SystemRandom().choices(string.ascii_letters +
                                                    string.digits,
                                                    k=14))
        with download_dict_lock:
            download_dict[listener.uid] = QbDownloadStatus(
                listener, client, gid, ext_hash, select)
        LOGGER.info(
            f"QbitDownload started: {tor_info.name} - Hash: {ext_hash}")
        Thread(target=_qb_listener,
               args=(listener, client, gid, ext_hash, select, meta_time,
                     path)).start()
        if BASE_URL is not None and select:
            if not is_file:
                metamsg = "Downloading Metadata, wait then you can select files or mirror torrent file"
                meta = sendMessage(metamsg, listener.bot, listener.update)
                while True:
                    tor_info = client.torrents_info(torrent_hashes=ext_hash)
                    if len(tor_info) == 0:
                        deleteMessage(listener.bot, meta)
                        return
                    try:
                        tor_info = tor_info[0]
                        if tor_info.state in ["metaDL", "checkingResumeData"]:
                            sleep(1)
                        else:
                            deleteMessage(listener.bot, meta)
                            break
                    except:
                        deleteMessage(listener.bot, meta)
                        return
            sleep(0.5)
            client.torrents_pause(torrent_hashes=ext_hash)
            for n in str(ext_hash):
                if n.isdigit():
                    pincode += str(n)
                if len(pincode) == 4:
                    break
            buttons = button_build.ButtonMaker()
            if WEB_PINCODE:
                buttons.buildbutton("Select Files",
                                    f"{BASE_URL}/app/files/{ext_hash}")
                buttons.sbutton("Pincode", f"pin {gid} {pincode}")
            else:
                buttons.buildbutton(
                    "Select Files",
                    f"{BASE_URL}/app/files/{ext_hash}?pin_code={pincode}")
            buttons.sbutton("Done Selecting", f"done {gid} {ext_hash}")
            QBBUTTONS = InlineKeyboardMarkup(buttons.build_menu(2))
            msg = "Your download paused. Choose files then press Done Selecting button to start downloading."
            sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
        else:
            sendStatusMessage(listener.update, listener.bot)
    except Exception as e:
        sendMessage(str(e), listener.bot, listener.update)
        client.auth_log_out()
Exemplo n.º 8
0
from html import escape
from urllib.parse import quote
from telegram import InlineKeyboardMarkup
from telegram.ext import CommandHandler, CallbackQueryHandler

from bot import dispatcher, LOGGER, SEARCH_API_LINK, SEARCH_PLUGINS, get_client
from bot.helper.ext_utils.telegraph_helper import telegraph
from bot.helper.telegram_helper.message_utils import editMessage, sendMessage, sendMarkup
from bot.helper.telegram_helper.filters import CustomFilters
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.ext_utils.bot_utils import get_readable_file_size
from bot.helper.telegram_helper import button_build

if SEARCH_PLUGINS is not None:
    PLUGINS = []
    qbclient = get_client()
    qb_plugins = qbclient.search_plugins()
    if qb_plugins:
        for plugin in qb_plugins:
            qbclient.search_uninstall_plugin(names=plugin['name'])
    qbclient.search_install_plugin(SEARCH_PLUGINS)
    qbclient.auth_log_out()

SITES = {
    "1337x": "1337x",
    "yts": "YTS",
    "eztv": "EzTv",
    "tgx": "TorrentGalaxy",
    "torlock": "Torlock",
    "piratebay": "PirateBay",
    "nyaasi": "NyaaSi",