diff --git a/bot/__init__.py b/bot/__init__.py index a8d09c62fd2..5f1ee78c4c4 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -4,15 +4,13 @@ from pymongo import MongoClient from asyncio import Lock from dotenv import load_dotenv, dotenv_values -from threading import Thread -from time import sleep, time +from time import time from subprocess import Popen, run as srun from os import remove as osremove, path as ospath, environ, getcwd from aria2p import API as ariaAPI, Client as ariaClient from qbittorrentapi import Client as qbClient - -# from faulthandler import enable as faulthandler_enable from socket import setdefaulttimeout +from uvloop import install from logging import ( getLogger, FileHandler, @@ -24,9 +22,10 @@ warning as log_warning, ERROR, ) -from uvloop import install +# from faulthandler import enable as faulthandler_enable # faulthandler_enable() + install() setdefaulttimeout(600) @@ -454,36 +453,13 @@ osremove("accounts.zip") if not ospath.exists("accounts"): config_dict["USE_SERVICE_ACCOUNTS"] = False -sleep(0.5) aria2 = ariaAPI(ariaClient(host="http://localhost", port=6800, secret="")) def get_client(): - return qbClient( - host="localhost", - port=8090, - VERIFY_WEBUI_CERTIFICATE=False, - REQUESTS_ARGS={"timeout": (30, 60)}, - ) - - -def aria2c_init(): - try: - log_info("Initializing Aria2c") - link = "https://linuxmint.com/torrents/lmde-5-cinnamon-64bit.iso.torrent" - dire = DOWNLOAD_DIR.rstrip("/") - aria2.add_uris([link], {"dir": dire}) - sleep(3) - downloads = aria2.get_downloads() - sleep(10) - aria2.remove(downloads, force=True, files=True, clean=True) - except Exception as e: - log_error(f"Aria2c initializing error: {e}") - + return qbClient(host="localhost", port=8090) -Thread(target=aria2c_init).start() -sleep(1.5) aria2c_global = [ "bt-max-open-files", diff --git a/bot/helper/ext_utils/files_utils.py b/bot/helper/ext_utils/files_utils.py index cb36b2fc431..47054b964c5 100644 --- a/bot/helper/ext_utils/files_utils.py +++ b/bot/helper/ext_utils/files_utils.py @@ -74,7 +74,7 @@ async def clean_target(path): try: if await aiopath.isdir(path): await aiormtree(path) - elif await aiopath.isfile(path): + else: await aioremove(path) except Exception as e: LOGGER.error(str(e)) @@ -90,6 +90,7 @@ async def clean_download(path): async def start_cleanup(): + aria2.remove_all(True) get_client().torrents_delete(torrent_hashes="all") try: await aiormtree(DOWNLOAD_DIR) diff --git a/bot/helper/ext_utils/task_manager.py b/bot/helper/ext_utils/task_manager.py index 7f7f00e1c4e..d6c0c2dca3f 100644 --- a/bot/helper/ext_utils/task_manager.py +++ b/bot/helper/ext_utils/task_manager.py @@ -8,7 +8,6 @@ non_queued_dl, queue_dict_lock, LOGGER, - DOWNLOAD_DIR, ) from bot.helper.mirror_utils.gdrive_utils.search import gdSearch from bot.helper.ext_utils.files_utils import get_base_name diff --git a/bot/helper/mirror_utils/download_utils/direct_link_generator.py b/bot/helper/mirror_utils/download_utils/direct_link_generator.py index 00cc529cc95..bfb5b40cb3c 100644 --- a/bot/helper/mirror_utils/download_utils/direct_link_generator.py +++ b/bot/helper/mirror_utils/download_utils/direct_link_generator.py @@ -1,12 +1,3 @@ -# Copyright (C) 2019 The Raphielscape Company LLC. -# -# Licensed under the Raphielscape Public License, Version 1.c (the "License"); -# you may not use this file except in compliance with the License. -# -""" Helper Module containing various sites direct links generators. This module is copied and modified as per need -from https://github.com/AvinashReddy3108/PaperplaneExtended . I hereby take no credit of the following code other -than the modifications. See https://github.com/AvinashReddy3108/PaperplaneExtended/commits/master/userbot/modules/direct_links.py -for original authorship. """ from hashlib import sha256 from http.cookiejar import MozillaCookieJar from json import loads @@ -15,9 +6,7 @@ from time import sleep from urllib.parse import parse_qs, urlparse from uuid import uuid4 - from cloudscraper import create_scraper -from lk21 import Bypass from lxml.etree import HTML from requests import Session, post from requests import session as req_session @@ -130,27 +119,6 @@ def direct_link_generator(link): ] ): return terabox(link) - elif any( - x in domain - for x in [ - "fembed.net", - "fembed.com", - "femax20.com", - "fcdn.stream", - "feurl.com", - "layarkacaxxi.icu", - "naniplay.nanime.in", - "naniplay.nanime.biz", - "naniplay.com", - "mm9842.com", - ] - ): - return fembed(link) - elif any( - x in domain - for x in ["sbembed.com", "watchsb.com", "streamsb.net", "sbplay.org"] - ): - return sbembed(link) elif any( x in domain for x in [ @@ -287,32 +255,6 @@ def hxfile(url): raise DirectDownloadLinkException("ERROR: Direct download link not found") -def fembed(link): - """Fembed direct link generator - Based on https://github.com/zevtyardt/lk21 - """ - try: - dl_url = Bypass().bypass_fembed(link) - count = len(dl_url) - lst_link = [dl_url[i] for i in dl_url] - return lst_link[count - 1] - except Exception as e: - raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") - - -def sbembed(link): - """Sbembed direct link generator - Based on https://github.com/zevtyardt/lk21 - """ - try: - dl_url = Bypass().bypass_sbembed(link) - count = len(dl_url) - lst_link = [dl_url[i] for i in dl_url] - return lst_link[count - 1] - except Exception as e: - raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") - - def onedrive(link): """Onedrive direct link generator By https://github.com/junedkh""" @@ -1378,7 +1320,14 @@ def filelions_and_streamwish(url): scheme = parsed_url.scheme if any( x in hostname - for x in ["filelions.co", "filelions.live", "filelions.to", "filelions.site", "cabecabean.lol", "filelions.online"] + for x in [ + "filelions.co", + "filelions.live", + "filelions.to", + "filelions.site", + "cabecabean.lol", + "filelions.online", + ] ): apiKey = config_dict["FILELION_API"] apiUrl = "https://api.filelions.co" @@ -1513,12 +1462,13 @@ def streamhub(url): raise DirectDownloadLinkException(f"ERROR: {error[0]}") raise DirectDownloadLinkException("ERROR: direct link not found!") + def pcloud(url): with create_scraper() as session: try: res = session.get(url) except Exception as e: raise DirectDownloadLinkException(f"ERROR: {e.__class__.__name__}") - if link := findall(r'.downloadlink.:..(https:.*)..', res.text): - return link[0].replace('\/', '/') + if link := findall(r".downloadlink.:..(https:.*)..", res.text): + return link[0].replace("\/", "/") raise DirectDownloadLinkException("ERROR: Direct link not found") diff --git a/bot/helper/mirror_utils/download_utils/yt_dlp_download.py b/bot/helper/mirror_utils/download_utils/yt_dlp_download.py index a6adc14ce4f..699b2784d8b 100644 --- a/bot/helper/mirror_utils/download_utils/yt_dlp_download.py +++ b/bot/helper/mirror_utils/download_utils/yt_dlp_download.py @@ -66,7 +66,6 @@ def __init__(self, listener): "overwrites": True, "writethumbnail": True, "trim_file_name": 220, - "compat_opts": {"prefer-legacy-http-handler": "urllib"}, "retry_sleep_functions": { "http": lambda n: 3, "fragment": lambda n: 3, diff --git a/bot/modules/ytdlp.py b/bot/modules/ytdlp.py index 6609bd13333..69c52a0a4dc 100644 --- a/bot/modules/ytdlp.py +++ b/bot/modules/ytdlp.py @@ -403,7 +403,6 @@ async def newEvent(self): options[key] = value options["playlist_items"] = "0" - options["compat_opts"] = {"prefer-legacy-http-handler": "urllib"} try: result = await sync_to_async(extract_info, self.link, options) diff --git a/requirements.txt b/requirements.txt index 63def79443d..792f79dcd93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,15 +14,12 @@ google-api-python-client google-auth-httplib2 google-auth-oauthlib gunicorn -git+https://github.com/zevtyardt/lk21.git httpx lxml motor -mutagen natsort pillow psutil -pybase64 pymongo pyrogram python-dotenv @@ -32,6 +29,7 @@ requests telegraph tenacity tgcrypto +urllib3 uvloop xattr -yt-dlp \ No newline at end of file +yt-dlp