{ "name": "AnimeKai Streamer", "version": "1.2.1", "author": "Animex", "description": "Resolves AnimeKai.to streams using backend encrypted APIs. Fully optimized for Cloud Tunneling.", "type": ["ANIME_STREAMER"], "requirements":["httpx", "beautifulsoup4"] } --- import re import httpx import asyncio import json import urllib.parse from typing import Optional, Dict, List # ========================= # CONSTANTS # ========================= BASE_URL = "https://animekai.to" ENC_API = "https://enc-dec.app/api" DB_URL = "https://enc-dec.app/db/kai/find" HEADERS = { "User-Agent": ( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " "AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/137.0.0.0 Safari/537.36" ), "Referer": BASE_URL } # ========================= # ENCRYPT / DECRYPT HELPERS # ========================= async def enc_kai(client, text: str) -> str: r = await client.get( f"{ENC_API}/enc-kai", params={"text": text}, headers=HEADERS, timeout=10 ) r.raise_for_status() return r.json()["result"] async def dec_kai(client, text: str) -> str: r = await client.post( f"{ENC_API}/dec-kai", json={"text": text}, headers=HEADERS, timeout=10 ) r.raise_for_status() return r.json()["result"] async def dec_mega(client, text: str) -> Dict: r = await client.post( f"{ENC_API}/dec-mega", json={ "text": text, "agent": HEADERS["User-Agent"] }, headers=HEADERS, timeout=15 ) r.raise_for_status() return r.json() # ========================= # INTERNAL LOGIC # ========================= async def get_anime_id(client, slug: str) -> str: # slug is actually mal_id (int) resp = await client.get(f"{DB_URL}?mal_id={slug}", headers=HEADERS) resp.raise_for_status() data = resp.json() if not data or not data[0].get("info", {}).get("kai_id"): raise RuntimeError("Anime ID not found in JSON response") return data[0]["info"]["kai_id"], data[0] async def get_episode_token(data: dict, episode: int) -> str: # Always fetch the sub ("1") token for the episode try: token = data["episodes"]["1"][str(episode)]["token"] except Exception: raise RuntimeError("Episode token not found in JSON response") return token async def get_server_id(client, ep_token: str, dub: bool) -> str: enc = await enc_kai(client, ep_token) html = await client.get( f"{BASE_URL}/ajax/links/list", params={"token": ep_token, "_": enc}, headers=HEADERS ) # The actual HTML is in the 'result' field of the JSON response try: html_content = html.json()["result"] except Exception: html_content = html.text # Determine which language group to use # Default: sub (Hard Sub), or dub if requested lang_order = ["dub", "sub"] if dub else ["sub", "softsub", "dub"] all_server_ids =[] for lang in lang_order: group_pattern = rf'