From 49cd90bd0092fd25fe866c3a9120e966a855cd76 Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:33:41 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20GG=20Debrid-Link,=20restrictions=20defe?= =?UTF-8?q?ated=20=F0=9F=A4=93=E2=98=9D=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comet/debrid/debridlink.py | 113 +++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 48 deletions(-) diff --git a/comet/debrid/debridlink.py b/comet/debrid/debridlink.py index e7206de..810ed41 100644 --- a/comet/debrid/debridlink.py +++ b/comet/debrid/debridlink.py @@ -29,20 +29,31 @@ async def check_premium(self): return False async def get_instant(self, chunk: list): - try: - get_instant = await self.session.get( - f"{self.api_url}/seedbox/cached?url={','.join(chunk)}" - ) - return await get_instant.json() - except Exception as e: - logger.warning( - f"Exception while checking hashes instant availability on Debrid-Link: {e}" - ) + responses = [] + for hash in chunk: + try: + add_torrent = await self.session.post( + "https://debrid-link.com/api/v2/seedbox/add", + data={"url": hash, "wait": True, "async": True}, + ) + add_torrent = await add_torrent.json() + + torrent_id = add_torrent["value"]["id"] + await self.session.delete(f"{self.api_url}/seedbox/{torrent_id}/remove") + + responses.append(add_torrent) + except Exception as e: + logger.warning( + f"Exception while checking cached status on DebridLink for {hash}: {e}" + ) + pass + + return responses async def get_files( self, torrent_hashes: list, type: str, season: str, episode: str, kitsu: bool ): - chunk_size = 250 + chunk_size = 10 chunks = [ torrent_hashes[i : i + chunk_size] for i in range(0, len(torrent_hashes), chunk_size) @@ -54,61 +65,67 @@ async def get_files( responses = await asyncio.gather(*tasks) - availability = [ - response for response in responses if response and response.get("success") - ] + availability = [] + for response_list in responses: + for response in response_list: + availability.append(response) files = {} if type == "series": for result in availability: - for hash, torrent_data in result["value"].items(): - for file in torrent_data["files"]: - filename = file["name"] + torrent_files = result["value"]["files"] + for file in torrent_files: + if file["downloadPercent"] != 100: + continue - if not is_video(filename): - continue + filename = file["name"] - if "sample" in filename.lower(): - continue + if not is_video(filename): + continue - filename_parsed = parse(filename) - if episode not in filename_parsed.episodes: - continue + if "sample" in filename.lower(): + continue - if kitsu: - if filename_parsed.seasons: - continue - else: - if season not in filename_parsed.seasons: - continue + filename_parsed = parse(filename) + if episode not in filename_parsed.episodes: + continue - files[hash] = { - "index": torrent_data["files"].index(file), - "title": filename, - "size": file["size"], - } + if kitsu: + if filename_parsed.seasons: + continue + else: + if season not in filename_parsed.seasons: + continue - break + files[result["value"]["hashString"]] = { + "index": torrent_files.index(file), + "title": filename, + "size": file["size"], + } + + break else: for result in availability: - for hash, torrent_data in result["value"].items(): - for file in torrent_data["files"]: - filename = file["name"] + value = result["value"] + torrent_files = value["files"] + for file in torrent_files: + if file["downloadPercent"] != 100: + continue - if not is_video(filename): - continue + filename = file["name"] - if "sample" in filename.lower(): - continue + if not is_video(filename): + continue - files[hash] = { - "index": torrent_data["files"].index(file), - "title": filename, - "size": file["size"], - } + if "sample" in filename.lower(): + continue - break + files[value["hashString"]] = { + "index": torrent_files.index(file), + "title": filename, + "size": file["size"], + } return files