From b641c69c04173b82386a4e150fccba2e078a85be Mon Sep 17 00:00:00 2001 From: Goldy <153996346+g0ldyy@users.noreply.github.com> Date: Fri, 19 Jul 2024 00:26:49 +0200 Subject: [PATCH] feat: Kitsu support --- comet/api/core.py | 26 ++++++-------------------- comet/api/stream.py | 28 +++++++++++++++++++--------- comet/debrid/alldebrid.py | 25 +++++++++++++++---------- comet/debrid/debridlink.py | 25 +++++++++++++++---------- comet/debrid/premiumize.py | 25 +++++++++++++++---------- comet/debrid/realdebrid.py | 27 ++++++++++++++++----------- comet/debrid/torbox.py | 25 +++++++++++++++---------- 7 files changed, 101 insertions(+), 80 deletions(-) diff --git a/comet/api/core.py b/comet/api/core.py index 47059d0..561c096 100644 --- a/comet/api/core.py +++ b/comet/api/core.py @@ -75,27 +75,13 @@ async def manifest(b64config: str = None): "catalogs": [], "resources": [ { - "name": "stream", - "types": [ - "movie", - "series" - ], - "idPrefixes": [ - "tt", - "kitsu" - ] + "name": "stream", + "types": ["movie", "series"], + "idPrefixes": ["tt", "kitsu"], } ], - "types": [ - "movie", - "series", - "anime", - "other" - ], + "types": ["movie", "series", "anime", "other"], "logo": "https://i.imgur.com/jmVoVMu.jpeg", "background": "https://i.imgur.com/WwnXB3k.jpeg", - "behaviorHints": { - "configurable": True, - "configurationRequired": False - } - } \ No newline at end of file + "behaviorHints": {"configurable": True, "configurationRequired": False}, + } diff --git a/comet/api/stream.py b/comet/api/stream.py index 9f65a28..a96bdb8 100644 --- a/comet/api/stream.py +++ b/comet/api/stream.py @@ -49,18 +49,26 @@ async def stream(request: Request, b64config: str, type: str, id: str): episode = None if type == "series": info = id.split(":") - id = info[0] season = int(info[1]) episode = int(info[2]) try: - get_metadata = await session.get( - f"https://v3.sg.media-imdb.com/suggestion/a/{id}.json" - ) - metadata = await get_metadata.json() - - name = metadata["d"][0 if len(metadata["d"]) == 1 else 1]["l"] + kitsu = False + if id == "kitsu": + kitsu = True + get_metadata = await session.get( + f"https://kitsu.io/api/edge/anime/{season}" + ) + get_metadata = await get_metadata.json() + name = get_metadata["data"]["attributes"]["canonicalTitle"] + season = 1 + else: + get_metadata = await session.get( + f"https://v3.sg.media-imdb.com/suggestion/a/{id}.json" + ) + metadata = await get_metadata.json() + 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}") @@ -185,9 +193,10 @@ async def stream(request: Request, b64config: str, type: str, id: str): f"Start of {indexer_manager_type} search for {log_name} with indexers {config['indexers']}" ) - search_terms = [name] + search_terms = [name] if not kitsu else [f"{name} {episode}"] if type == "series": - search_terms.append(f"{name} S0{season}E0{episode}") + if not kitsu: + search_terms.append(f"{name} S0{season}E0{episode}") tasks.extend( get_indexer_manager( session, indexer_manager_type, config["indexers"], term @@ -261,6 +270,7 @@ async def stream(request: Request, b64config: str, type: str, id: str): type, season, episode, + kitsu, ) ranked_files = set() diff --git a/comet/debrid/alldebrid.py b/comet/debrid/alldebrid.py index e0cda1a..db55719 100644 --- a/comet/debrid/alldebrid.py +++ b/comet/debrid/alldebrid.py @@ -44,7 +44,7 @@ class AllDebrid: ) async def get_files( - self, torrent_hashes: list, type: str, season: str, episode: str + self, torrent_hashes: list, type: str, season: str, episode: str, kitsu: bool ): chunk_size = 500 chunks = [ @@ -86,15 +86,20 @@ class AllDebrid: continue filename_parsed = parse(filename) - if ( - season in filename_parsed.season - and episode in filename_parsed.episode - ): - files[magnet["hash"]] = { - "index": magnet["files"].index(file), - "title": filename, - "size": file["e"][0]["s"] if pack else file["s"], - } + if episode not in filename_parsed.episode: + continue + + if not kitsu and season not in filename_parsed.season: + continue + + if kitsu and filename_parsed.season != []: + continue + + files[magnet["hash"]] = { + "index": magnet["files"].index(file), + "title": filename, + "size": file["e"][0]["s"] if pack else file["s"], + } continue diff --git a/comet/debrid/debridlink.py b/comet/debrid/debridlink.py index 3ebcb02..7a66d78 100644 --- a/comet/debrid/debridlink.py +++ b/comet/debrid/debridlink.py @@ -40,7 +40,7 @@ class DebridLink: ) async def get_files( - self, torrent_hashes: list, type: str, season: str, episode: str + self, torrent_hashes: list, type: str, season: str, episode: str, kitsu: bool ): chunk_size = 250 chunks = [ @@ -76,15 +76,20 @@ class DebridLink: continue filename_parsed = parse(filename) - if ( - season in filename_parsed.season - and episode in filename_parsed.episode - ): - files[hash] = { - "index": hash_files.index(file), - "title": filename, - "size": file["size"], - } + if episode not in filename_parsed.episode: + continue + + if not kitsu and season not in filename_parsed.season: + continue + + if kitsu and filename_parsed.season != []: + continue + + files[hash] = { + "index": hash_files.index(file), + "title": filename, + "size": file["size"], + } continue diff --git a/comet/debrid/premiumize.py b/comet/debrid/premiumize.py index 04328ab..27d0e40 100644 --- a/comet/debrid/premiumize.py +++ b/comet/debrid/premiumize.py @@ -49,7 +49,7 @@ class Premiumize: ) async def get_files( - self, torrent_hashes: list, type: str, season: str, episode: str + self, torrent_hashes: list, type: str, season: str, episode: str, kitsu: bool ): chunk_size = 100 chunks = [ @@ -89,15 +89,20 @@ class Premiumize: filename = filenames[index] if type == "series": filename_parsed = parse(filename) - if ( - season in filename_parsed.season - and episode in filename_parsed.episode - ): - files[hashes[index]] = { - "index": f"{season}|{episode}", - "title": filename, - "size": int(filesizes[index]), - } + if episode not in filename_parsed.episode: + continue + + if not kitsu and season not in filename_parsed.season: + continue + + if kitsu and filename_parsed.season != []: + continue + + files[hashes[index]] = { + "index": f"{season}|{episode}", + "title": filename, + "size": int(filesizes[index]), + } continue diff --git a/comet/debrid/realdebrid.py b/comet/debrid/realdebrid.py index a0ea316..7e62296 100644 --- a/comet/debrid/realdebrid.py +++ b/comet/debrid/realdebrid.py @@ -41,7 +41,7 @@ class RealDebrid: ) async def get_files( - self, torrent_hashes: list, type: str, season: str, episode: str + self, torrent_hashes: list, type: str, season: str, episode: str, kitsu: bool ): chunk_size = 50 chunks = [ @@ -76,15 +76,20 @@ class RealDebrid: continue filename_parsed = parse(filename) - if ( - season in filename_parsed.season - and episode in filename_parsed.episode - ): - files[hash] = { - "index": index, - "title": filename, - "size": file["filesize"], - } + if episode not in filename_parsed.episode: + continue + + if not kitsu and season not in filename_parsed.season: + continue + + if kitsu and filename_parsed.season != []: + continue + + files[hash] = { + "index": index, + "title": filename, + "size": file["filesize"], + } continue @@ -141,7 +146,7 @@ class RealDebrid: for file in get_magnet_info["files"] if is_video(file["path"]) ) - }, # "all" because bad + }, proxy=self.proxy, ) diff --git a/comet/debrid/torbox.py b/comet/debrid/torbox.py index 053ec53..2567d16 100644 --- a/comet/debrid/torbox.py +++ b/comet/debrid/torbox.py @@ -41,7 +41,7 @@ class TorBox: ) async def get_files( - self, torrent_hashes: list, type: str, season: str, episode: str + self, torrent_hashes: list, type: str, season: str, episode: str, kitsu: bool ): chunk_size = 100 chunks = [ @@ -80,15 +80,20 @@ class TorBox: continue filename_parsed = parse(filename) - if ( - season in filename_parsed.season - and episode in filename_parsed.episode - ): - files[hash] = { - "index": hash_files.index(file), - "title": filename, - "size": file["size"], - } + if episode not in filename_parsed.episode: + continue + + if not kitsu and season not in filename_parsed.season: + continue + + if kitsu and filename_parsed.season != []: + continue + + files[hash] = { + "index": hash_files.index(file), + "title": filename, + "size": file["size"], + } continue