Spaces:
Running
Running
Z User commited on
Commit ·
1d6e15b
1
Parent(s): 699389b
v5: Add DooFlix, Castle, MovieBoxHindi, Videasy sources
Browse files12234511 unmodified lines1718192020212223125 unmodified lines1491501511521521531541551 unmodified line15715815916016016116214 unmodified lines1771781791811801811821851831841859 unmodified lines1951961972011981992005 unmodified lines2062072082132142152162172182092102112122202132142232242152162172272282182192202212222232342242252263 unmodified lines2302312322442332342358 unmodified lines24424524625924724824921 unmodified lines271272273287274275276126 unmodified lines40340440542040640740840956 unmodified lines4664674684834694704718 unmodified lines4804814824984834844854867 unmodified lines4944954965124974984993 unmodified lines50350450552250650750850952751051151228 unmodified lines5415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169178 unmodified lines92692792892993093193293393493593693793857893994094194212 unmodified lines9559569575979589599606009619629639648 unmodified lines9739749759769779789799809819829836169849859869879886219899909919924 unmodified lines997998999632100010011002100325 unmodified lines1029103010316646656661032103310341035103610376681038103910401041"""StreamForge API v4 - Multi-Language Stream ScraperStreamForge API v5 - Multi-Language Stream ScraperScrapes direct m3u8 URLs from multiple sources"""
11 unmodified linesapp = FastAPI( title="StreamForge API", description="Multi-language m3u8 stream scraper", version="4.0.0", version="5.0.0",)
app.add_middleware(125 unmodified lines return results, errors
# ===== VixSrc Scraper (Fixed: uses window.masterPlaylist) =====# ===== VixSrc Scraper =====
async def scrape_vixsrc(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = []1 unmodified line
try: async with httpx.AsyncClient(timeout=15, follow_redirects=True, headers=HEADERS) as client: # Step 1: Get embed path if media_type == "movie": api_url = f"https://vixsrc.to/api/movie/{tmdb_id}" else:14 unmodified lines errors.append("VixSrc: No embed path returned") return results, errors
# Step 2: Fetch embed HTML embed_resp = await client.get(f"https://vixsrc.to{src_path}")
if embed_resp.status_code == 410: # Token expired, retry once api_resp2 = await client.get(api_url) try: api_data2 = api_resp2.json()9 unmodified lines
html = embed_resp.text
# Step 3: Extract from window.masterPlaylist token = None expires = None playlist_url = None5 unmodified lines expires_m = re.search(r"'expires'\s*:\s*'([^']+)'", mp_text) url_m = re.search(r"url\s*:\s*'([^']+)'", mp_text)
if token_m: token = token_m.group(1) if expires_m: expires = expires_m.group(1) if url_m: playlist_url = url_m.group(1) if token_m: token = token_m.group(1) if expires_m: expires = expires_m.group(1) if url_m: playlist_url = url_m.group(1)
# Fallback: try old patterns if not token: token_match = re.search(r'token["\']\s*:\s*["\']([^"\']+)', html) if token_match: token = token_match.group(1) if token_match: token = token_match.group(1) if not playlist_url: url_match = re.search(r'url\s*:\s*["\']([^"\']+playlist[^"\']*)', html) if url_match: playlist_url = url_match.group(1) if url_match: playlist_url = url_match.group(1)
if not (token and playlist_url): errors.append("VixSrc: Could not extract stream parameters from embed") return results, errors
# Step 4: Build master URL and fetch if not expires: expires = str(int(time.time()) + 86400) sep = "&" if "?" in playlist_url else "?"3 unmodified lines pl_content = pl_resp.text
if "#EXTM3U" in pl_content: # Parse audio tracks audio_tracks = [] lines = pl_content.split("\n") for line in lines:8 unmodified lines "uri": uri_match.group(1), })
# Parse video streams for i, line in enumerate(lines): if line.startswith("#EXT-X-STREAM-INF:"): resolution = re.search(r'RESOLUTION=(\d+x\d+)', line)21 unmodified lines "type": "m3u8", }) else: # Return master URL as-is if we can't parse results.append({ "source": "VixSrc", "title": "Stream",126 unmodified lines return results, errors
# ===== Popr Scraper (Improved dedup) =====# ===== Popr Scraper =====
async def scrape_popr(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = []56 unmodified lines if error: errors.append(f"Popr {error}")
# Deduplicate by URL seen_urls = set() unique_results = [] for r in results:8 unmodified lines return results, errors
# ===== VidRock Scraper (AES-encrypted API - Multi-server English) =====# ===== VidRock Scraper (AES-encrypted API) =====
async def scrape_vidrock(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = []7 unmodified lines aes_key = passphrase[:32] aes_iv = passphrase[:16]
# Build item ID if media_type == "tv": s = season or 1 e = episode or 13 unmodified lines item_id = str(tmdb_id) api_type = "movie"
# Encrypt item ID cipher = CryptoAES.new(aes_key, CryptoAES.MODE_CBC, aes_iv) ct = cipher.encrypt(crypto_pad(item_id.encode(), CryptoAES.block_size)) encoded = base64.b64encode(ct).decode().replace("+", "-").replace("/", "_").replace("=", "")
# Fetch servers async with httpx.AsyncClient(timeout=15, follow_redirects=True, headers=HEADERS) as client: resp = await client.get(f"https://vidrock.net/api/{api_type}/{encoded}") if resp.status_code != 200:28 unmodified lines return results, errors
# ===== DooFlix Scraper (Hindi/Indian content - API based) =====
async def scrape_dooflix(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = [] errors = []
try: async with httpx.AsyncClient(timeout=15, follow_redirects=False) as client: BASE_API = "https://panel.watchkaroabhi.com" API_KEY = "qNhKLJiZVyoKdi9NCQGz8CIGrpUijujE"
dooflix_headers = { "X-Package-Name": "com.king.moja", "User-Agent": "dooflix", "X-App-Version": "305", } STREAM_REFERER = "https://molop.art/"
if media_type == "movie": url = f"{BASE_API}/api/3/movie/{tmdb_id}/links?api_key={API_KEY}" else: s = season or 1 e = episode or 1 url = f"{BASE_API}/api/3/tv/{tmdb_id}/season/{s}/episode/{e}/links?api_key={API_KEY}"
resp = await client.get(url, headers=dooflix_headers) if resp.status_code != 200: errors.append(f"DooFlix: API error HTTP {resp.status_code}") return results, errors
data = resp.json() links = data.get("links", [])
if not links: errors.append("DooFlix: No links found") return results, errors
for link_obj in links: try: link_url = link_obj.get("url", "") host = link_obj.get("host", "Server") if not link_url: continue
redir_resp = await client.get( link_url, headers={ "Referer": STREAM_REFERER, "User-Agent": "dooflix", }, )
stream_url = None if redir_resp.status_code in (301, 302, 303, 307, 308): stream_url = redir_resp.headers.get("location", "") elif redir_resp.status_code == 200: stream_url = link_url else: stream_url = redir_resp.headers.get("location", link_url)
if not stream_url: continue
s_type = "m3u8" if ".m3u8" in stream_url else "direct" quality = "Auto" q_match = re.search(r'(\d{3,4})p', stream_url) if q_match: quality = q_match.group(1) + "p"
results.append({ "source": f"DooFlix/{host}", "title": f"DooFlix - {host}", "quality": quality, "language": "Hindi", "url": stream_url, "type": s_type, "headers": { "Referer": STREAM_REFERER, "User-Agent": "dooflix", }, })
except Exception as e: errors.append(f"DooFlix/{host}: {str(e)}")
if not results: errors.append("DooFlix: No streams resolved")
except Exception as e: errors.append(f"DooFlix: {str(e)}")
return results, errors
# ===== Castle Scraper (Stremio-style aggregator) =====
async def scrape_castle(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = [] errors = []
try: import urllib.parse
info = await get_tmdb_info(tmdb_id, media_type) imdb_id = info.get("imdb_id")
if not imdb_id: errors.append("Castle: Could not get IMDB ID from TMDB") return results, errors
CASTLE_API = "https://meowtv.vflix.shop" SKIP_PATTERNS = ["4khdhub", "instant download", "iosmirror", "xdm", "redirecting"]
async with httpx.AsyncClient(timeout=20, follow_redirects=True, headers=HEADERS) as client: if media_type == "movie": url = f"{CASTLE_API}/stream/movie/{imdb_id}.json" else: s = season or 1 e = episode or 1 url = f"{CASTLE_API}/stream/series/{imdb_id}:{s}:{e}.json"
resp = await client.get(url, headers={"Accept": "application/json"}) if resp.status_code != 200: errors.append(f"Castle: HTTP {resp.status_code}") return results, errors
data = resp.json() streams = data.get("streams", [])
if not streams: errors.append("Castle: No streams found") return results, errors
for s in streams: s_url = s.get("url", "") if not s_url: continue
name = (s.get("name") or "").lower() title = (s.get("title") or "").lower() if any(p in name or p in title for p in SKIP_PATTERNS): continue if "github.com" in s_url or "googleusercontent" in s_url: continue
# Castle often wraps URLs like: https://...?url=ACTUAL_URL actual_url = s_url url_param = re.search(r'[?&]url=([^&]+)', s_url) if url_param: actual_url = urllib.parse.unquote(url_param.group(1))
quality = "Auto" q_match = re.search(r'(\d{3,4})p', name + title + actual_url) if q_match: quality = q_match.group(1) + "p" elif "4k" in (name + title).lower() or "2160" in actual_url: quality = "4K"
lang = detect_language(name + " " + title)
s_type = "m3u8" if ".m3u8" in actual_url else ("direct" if ".mp4" in actual_url or ".mkv" in actual_url else "m3u8")
results.append({ "source": "Castle", "title": s.get("name", "Castle Stream"), "quality": quality, "language": lang, "url": actual_url, "type": s_type, })
seen_urls = set() unique_results = [] for r in results: if r["url"] not in seen_urls: seen_urls.add(r["url"]) unique_results.append(r) results = unique_results
if not results: errors.append("Castle: No usable streams after filtering")
except Exception as e: errors.append(f"Castle: {str(e)}")
return results, errors
# ===== MovieBoxHindi Scraper (Hindi - Cloudflare Worker API) =====
async def scrape_movieboxhindi(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = [] errors = []
try: WORKER_BASE = "https://moviebox.s4nch1tt.workers.dev"
async with httpx.AsyncClient(timeout=15, follow_redirects=True, headers=HEADERS) as client: url = f"{WORKER_BASE}/streams?tmdb_id={tmdb_id}&type={media_type}&proxy={WORKER_BASE}" if media_type == "tv": s = season or 1 e = episode or 1 url += f"&se={s}&ep={e}"
resp = await client.get(url, headers={ "Accept": "application/json", "User-Agent": "StreamForge/1.0", })
if resp.status_code != 200: errors.append(f"MovieBoxHindi: HTTP {resp.status_code}") return results, errors
data = resp.json()
raw_streams = [] if isinstance(data, list): raw_streams = data elif isinstance(data, dict): raw_streams = data.get("streams", [])
if not raw_streams: errors.append("MovieBoxHindi: No streams returned") return results, errors
for s in raw_streams: stream_url = s.get("proxy_url") or s.get("url", "") if not stream_url: continue
quality = "Auto" resolution = s.get("resolution", "") if resolution: m = re.search(r'(\d+)', str(resolution)) quality = m.group(1) + "p" if m else str(resolution)
s_name = s.get("name", "") lang = detect_language(s_name)
results.append({ "source": "MovieBoxHindi", "title": s_name or "MovieBox Stream", "quality": quality, "language": lang, "url": stream_url, "type": "m3u8", })
if not results: errors.append("MovieBoxHindi: No valid streams parsed")
except Exception as e: errors.append(f"MovieBoxHindi: {str(e)}")
return results, errors
# ===== Videasy Scraper (Multi-server encrypted API) =====
async def scrape_videasy(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = [] errors = []
try: VIDEASY_HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", "Accept": "application/json, text/plain, */*", "Origin": "https://player.videasy.net", "Referer": "https://player.videasy.net/", } DECRYPT_API = "https://enc-dec.app/api/dec-videasy"
SERVERS = { "Neon": "https://api.videasy.net/myflixerzupcloud/sources-with-title", "Cypher": "https://api.videasy.net/moviebox/sources-with-title", "Reyna": "https://api.videasy.net/primewire/sources-with-title", "Omen": "https://api.videasy.net/onionplay/sources-with-title", "Breach": "https://api.videasy.net/m4uhd/sources-with-title", "Ghost": "https://api.videasy.net/primesrcme/sources-with-title", "Sage": "https://api.videasy.net/1movies/sources-with-title", "Vyse": "https://api.videasy.net/hdmovie/sources-with-title", "Raze": "https://api.videasy.net/superflix/sources-with-title", }
info = await get_tmdb_info(tmdb_id, media_type) title = info.get("title", "") year = info.get("year", "") imdb_id = info.get("imdb_id", "")
async with httpx.AsyncClient(timeout=15, follow_redirects=True, headers=VIDEASY_HEADERS) as client: async def fetch_server(name: str, endpoint: str): server_results = [] try: url = f"{endpoint}?title={title}&mediaType={media_type}&year={year}&tmdbId={tmdb_id}&imdbId={imdb_id or ''}" if media_type == "tv": s = season or 1 e = episode or 1 url += f"&seasonId={s}&episodeId={e}"
resp = await client.get(url) encrypted_text = resp.text
if not encrypted_text or len(encrypted_text) < 20 or encrypted_text.startswith("<!"): return server_results, f"{name}: No data or blocked"
dec_resp = await client.post( DECRYPT_API, json={"text": encrypted_text, "id": str(tmdb_id)}, headers={"Content-Type": "application/json"}, )
if dec_resp.status_code != 200: return server_results, f"{name}: Decrypt failed"
decrypted = dec_resp.json() res_data = decrypted.get("result") or decrypted
if not res_data or not res_data.get("sources"): return server_results, f"{name}: No sources"
for s in res_data["sources"]: stream_url = s.get("url", "") if not stream_url: continue quality = s.get("quality", "Auto")
server_results.append({ "source": f"Videasy/{name}", "title": f"Videasy {name}", "quality": quality, "language": "English", "url": stream_url, "type": "m3u8", "headers": { "Referer": "https://player.videasy.net/", "Origin": "https://player.videasy.net", "User-Agent": VIDEASY_HEADERS["User-Agent"], }, })
except Exception as e: return server_results, f"{name}: {str(e)}"
return server_results, None
tasks = [fetch_server(name, endpoint) for name, endpoint in SERVERS.items()] task_results = await asyncio.gather(*tasks, return_exceptions=True)
for result in task_results: if isinstance(result, Exception): errors.append(f"Videasy: {str(result)}") else: server_results, error = result results.extend(server_results) if error: errors.append(f"Videasy {error}")
seen_urls = set() unique_results = [] for r in results: if r["url"] not in seen_urls: seen_urls.add(r["url"]) unique_results.append(r) results = unique_results
except Exception as e: errors.append(f"Videasy: {str(e)}")
return results, errors
# ===== Source Map =====
SOURCE_MAP = {8 unmodified lines "languages": ["Hindi", "Tamil", "Telugu", "English", "French"], "reliability": "high"}, "vidrock": {"name": "VidRock", "fn": lambda tid, mt, s, e: scrape_vidrock(tid, mt, s, e), "languages": ["English"], "reliability": "high"}, "dooflix": {"name": "DooFlix", "fn": lambda tid, mt, s, e: scrape_dooflix(tid, mt, s, e), "languages": ["Hindi", "English", "Multi"], "reliability": "high"}, "castle": {"name": "Castle", "fn": lambda tid, mt, s, e: scrape_castle(tid, mt, s, e), "languages": ["English", "Hindi", "Multi"], "reliability": "high"}, "movieboxhindi": {"name": "MovieBoxHindi", "fn": lambda tid, mt, s, e: scrape_movieboxhindi(tid, mt, s, e), "languages": ["Hindi", "English"], "reliability": "high"}, "videasy": {"name": "Videasy", "fn": lambda tid, mt, s, e: scrape_videasy(tid, mt, s, e), "languages": ["English", "Multi"], "reliability": "medium"},}
DEFAULT_SOURCES = ["cinesu", "popr", "vidnest", "vidrock"]DEFAULT_SOURCES = ["cinesu", "popr", "vidnest", "dooflix", "castle", "movieboxhindi"]
# ===== Helper: Run scrapers =====12 unmodified lines if not src: return [], [f"{key}: Unknown source"] try: r, e = await asyncio.wait_for(src["fn"](tmdb_id, media_type, season, episode), timeout=30) r, e = await asyncio.wait_for(src["fn"](tmdb_id, media_type, season, episode), timeout=45) return r, e except asyncio.TimeoutError: return [], [f"{src['name']}: Timeout (30s)"] return [], [f"{src['name']}: Timeout (45s)"] except Exception as ex: return [], [f"{src['name']}: {str(ex)}"]
8 unmodified lines all_results.extend(r) all_errors.extend(e)
seen_urls = set() unique_results = [] for r in all_results: if r["url"] not in seen_urls: seen_urls.add(r["url"]) unique_results.append(r)
return { "success": len(all_results) > 0, "success": len(unique_results) > 0, "tmdb_id": tmdb_id, "imdb_id": imdb_id, "title": title, "year": info.get("year"), "results": all_results, "results": unique_results, "errors": all_errors if all_errors else None, }
4 unmodified linesasync def root(): return { "api": "StreamForge", "version": "4.0.0", "version": "5.0.0", "description": "Multi-language m3u8 stream scraper", "endpoints": { "movie": {25 unmodified lines for key, src in SOURCE_MAP.items()}, "default_sources": DEFAULT_SOURCES, "tips": [ "No source = default sources (cinesu, popr, vidnest, vidrock)", "Best for Hindi: /movie/ID/popr", "Best for English: /movie/ID/cinesu or /movie/ID/vidrock", "No source = default sources (cinesu, popr, vidnest, dooflix, castle, movieboxhindi)", "Best for Hindi: /movie/ID/popr or /movie/ID/dooflix or /movie/ID/movieboxhindi", "Best for English: /movie/ID/cinesu or /movie/ID/vidrock or /movie/ID/videasy", "Best for French: /movie/ID/vidnest", "Castle: Stremio aggregator, returns multiple streams from different providers", "Videasy: Multi-server English source (9 servers), use /movie/ID/videasy", "VixSrc (Italian) blocked from cloud IPs, works residential only", "VixSrc: Blocked from cloud IPs, works residential only", "m3u8 links work in VLC, mpv, or any HLS player", ], }main.py+408-38