From 14d6ebf0f43c87d6e199e6fdd57a02bfa6acc973 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Fri, 5 Jul 2024 18:54:24 +0200 Subject: [PATCH] fix: I forgot something I need to release for elfhosted bruh --- comet/api/stream.py | 12 +++++++----- comet/debrid/alldebrid.py | 8 +++++--- comet/debrid/realdebrid.py | 28 +++++++++++++++++----------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/comet/api/stream.py b/comet/api/stream.py index 44fca59..0a69b12 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -71,9 +71,7 @@ async def stream(request: Request, b64config: str, type: str, id: str): name = metadata["d"][0 if len(metadata["d"]) == 1 else 1]["l"] except Exception as e: - logger.warning( - f"Exception while getting metadata for {id}: {e}" - ) + logger.warning(f"Exception while getting metadata for {id}: {e}") return { "streams": [ @@ -303,7 +301,9 @@ async def playback(request: Request, b64config: str, hash: str, index: str): async with aiohttp.ClientSession() as session: debrid = getDebrid(session, config) download_link = await debrid.generate_download_link(hash, index) - proxy = debrid.proxy if config["debridService"] == "alldebrid" else None # proxy is not needed to proxy realdebrid stream + proxy = ( + debrid.proxy if config["debridService"] == "alldebrid" else None + ) # proxy is not needed to proxy realdebrid stream if ( settings.PROXY_DEBRID_STREAM @@ -313,7 +313,9 @@ async def playback(request: Request, b64config: str, hash: str, index: str): async def stream_content(headers: dict): async with aiohttp.ClientSession() as session: - async with session.get(download_link, headers=headers, proxy=proxy) as response: + async with session.get( + download_link, headers=headers, proxy=proxy + ) as response: while True: chunk = await response.content.read( settings.PROXY_DEBRID_STREAM_BYTES_PER_CHUNK diff --git a/comet/debrid/alldebrid.py b/comet/debrid/alldebrid.py index c594e96..99661d4 100644 --- a/comet/debrid/alldebrid.py +++ b/comet/debrid/alldebrid.py @@ -31,7 +31,9 @@ async def check_premium(self): return False - async def get_files(self, torrent_hashes: list, type: str, season: str, episode: str): + async def get_files( + self, torrent_hashes: list, type: str, season: str, episode: str + ): try: get_instant = await self.session.get( f"{self.api_url}/magnet/instant?agent={self.agent}&magnets[]={'&magnets[]='.join(hash for hash in torrent_hashes)}" @@ -44,9 +46,9 @@ async def get_files(self, torrent_hashes: list, type: str, season: str, episode: return {} - if not "status" in availability or availability["status"] != "success": + if "status" not in availability or availability["status"] != "success": return {} - + files = {} for magnet in availability["data"]["magnets"]: if not magnet["instant"]: diff --git a/comet/debrid/realdebrid.py b/comet/debrid/realdebrid.py index 6725164..47823f0 100644 --- a/comet/debrid/realdebrid.py +++ b/comet/debrid/realdebrid.py @@ -12,6 +12,7 @@ class RealDebrid: def __init__(self, session: aiohttp.ClientSession, debrid_api_key: str): session.headers["Authorization"] = f"Bearer {debrid_api_key}" self.session = session + self.proxy = None self.api_url = "https://api.real-debrid.com/rest/1.0" @@ -40,7 +41,9 @@ async def get_instant(self, hash: str): ) return - async def get_files(self, torrent_hashes: list, type: str, season: str, episode: str): + async def get_files( + self, torrent_hashes: list, type: str, season: str, episode: str + ): tasks = [] for hash in torrent_hashes: tasks.append(self.get_instant(hash)) @@ -53,7 +56,7 @@ async def get_files(self, torrent_hashes: list, type: str, season: str, episode: continue availability.update(response) - + files = {} for hash, details in availability.items(): if "rd" not in details: @@ -99,44 +102,47 @@ async def generate_download_link(self, hash: str, index: str): try: check_blacklisted = await self.session.get("https://real-debrid.com/vpn") check_blacklisted = await check_blacklisted.text() - proxy = None if ( "Your ISP or VPN provider IP address is currently blocked on our website" in check_blacklisted ): - proxy = settings.DEBRID_PROXY_URL - if not proxy: + self.proxy = settings.DEBRID_PROXY_URL + if not self.proxy: logger.warning( "Real-Debrid blacklisted server's IP. No proxy found." ) else: logger.warning( - f"Real-Debrid blacklisted server's IP. Switching to proxy {proxy} for {hash}|{index}" + f"Real-Debrid blacklisted server's IP. Switching to proxy {self.proxy} for {hash}|{index}" ) add_magnet = await self.session.post( f"{self.api_url}/torrents/addMagnet", data={"magnet": f"magnet:?xt=urn:btih:{hash}"}, - proxy=proxy, + proxy=self.proxy, ) add_magnet = await add_magnet.json() - get_magnet_info = await self.session.get(add_magnet["uri"], proxy=proxy) + get_magnet_info = await self.session.get( + add_magnet["uri"], proxy=self.proxy + ) get_magnet_info = await get_magnet_info.json() await self.session.post( f"{self.api_url}/torrents/selectFiles/{add_magnet['id']}", data={"files": index}, - proxy=proxy, + proxy=self.proxy, ) - get_magnet_info = await self.session.get(add_magnet["uri"], proxy=proxy) + get_magnet_info = await self.session.get( + add_magnet["uri"], proxy=self.proxy + ) get_magnet_info = await get_magnet_info.json() unrestrict_link = await self.session.post( f"{self.api_url}/unrestrict/link", data={"link": get_magnet_info["links"][0]}, - proxy=proxy, + proxy=self.proxy, ) unrestrict_link = await unrestrict_link.json()