Spaces:
Running
Running
Z User commited on
Commit ·
d4916a1
1
Parent(s): 905e847
v6: Remove HDMovie2, add VidSrc source
Browse filesFiles changed (2)
4 unmodified lines567889101122 unmodified lines113311341135113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238113612401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415113711381139396 unmodified lines153615371538181818191539154015412 unmodified lines1544154515461828154715481549155086 unmodified lines1637163816391921164016411642164367 unmodified lines1711171217131995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221531714171517164 unmodified lines
from fastapi import FastAPI, HTTPException, Queryfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import Responsefrom pydantic import BaseModelfrom typing import Optionalimport httpx1122 unmodified lines return results, errors
# ===== HDMovie2 Scraper (Hindi - molop.art with proxy) =====
# Cache for molop.art PHPSESSID cookies: {watch_url: {"cookie": "PHPSESSID=...", "expires": timestamp}}_molop_sessions = {}
async def _get_molop_session(watch_url: str, client: httpx.AsyncClient) -> str: """Visit the molop.art watch page to get a PHPSESSID cookie.""" now = time.time() cached = _molop_sessions.get(watch_url) if cached and cached["expires"] > now: return cached["cookie"] resp = await client.get(watch_url, headers={"Referer": "https://hdmovie2.com.se/"}) cookie_header = "" for cookie_name, cookie_value in resp.cookies.items(): if cookie_name == "PHPSESSID": cookie_header = f"PHPSESSID={cookie_value}" break if not cookie_header: # Try from Set-Cookie header set_cookie = resp.headers.get("set-cookie", "") m = re.search(r'PHPSESSID=([^;]+)', set_cookie) if m: cookie_header = f"PHPSESSID={m.group(1)}" if cookie_header: _molop_sessions[watch_url] = {"cookie": cookie_header, "expires": now + 600} return cookie_header
async def scrape_hdmovie2(tmdb_id: int, media_type: str, season: int = None, episode: int = None): results = [] errors = []
try: BASE = "https://hdmovie2.com.se" CDN = "https://hdm2.ink" UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
info = await get_tmdb_info(tmdb_id, media_type) title = info.get("title", "") year = info.get("year", "") if not title: errors.append("HDMovie2: Could not get title from TMDB") return results, errors
async with httpx.AsyncClient(timeout=15, follow_redirects=True, headers={"User-Agent": UA}) as client:
# Step 1: Search on the site search_url = f"{BASE}/?s={title}" search_resp = await client.get(search_url, headers={"Referer": f"{BASE}/"}) search_html = search_resp.text
# Parse search results article_pattern = re.compile(r'<article[^>]*>(.*?)</article>', re.DOTALL) link_pattern = re.compile(r'href="(https://hdmovie2\.com\.se/movies/([^"]+)/)"') alt_pattern = re.compile(r'alt="([^"]+)"')
best_match = None best_score = 0 title_lower = title.lower().replace(":", "").replace("-", " ").strip()
for article_match in article_pattern.finditer(search_html): article = article_match.group(1) link_m = link_pattern.search(article) if not link_m: continue if "/feed/" in link_m.group(1): continue
alt_m = alt_pattern.search(article) if not alt_m: continue
item_url = link_m.group(1) item_title = alt_m.group(1).strip()
item_lower = item_title.lower().replace(":", "").replace("-", " ").strip() score = 0 if item_lower == title_lower: score = 100 elif item_lower.startswith(title_lower) or title_lower.startswith(item_lower): score = 80 elif title_lower in item_lower: score = 60
if year and year in item_title: score += 10
if score > best_score: best_score = score best_match = item_url
if not best_match or best_score < 30: errors.append("HDMovie2: No matching result found") return results, errors
# Step 2: Get the movie page to extract post ID page_resp = await client.get(best_match, headers={"Referer": f"{BASE}/"}) page_html = page_resp.text
post_id_match = re.search(r'postid-(\d+)', page_html) if not post_id_match: errors.append("HDMovie2: Could not find post ID") return results, errors
post_id = post_id_match.group(1)
# Step 3: Try servers (up to 4) via AJAX for nume in range(1, 5): try: ajax_resp = await client.post( f"{BASE}/wp-admin/admin-ajax.php", data=f"action=doo_player_ajax&post={post_id}&nume={nume}&type=movie", headers={ "Referer": best_match, "Content-Type": "application/x-www-form-urlencoded", "User-Agent": UA, }, )
if ajax_resp.status_code != 200: continue
try: ajax_data = ajax_resp.json() except: continue
embed_url = ajax_data.get("embed_url", "") if not embed_url: continue
embed_url = embed_url.replace("\\/", "/")
# Try hdm2.ink player hdm2_match = re.search(r'src="(https://hdm2\.ink/play\?v=[^"]+)"', embed_url) if hdm2_match: player_resp = await client.get(hdm2_match.group(1), headers={"Referer": f"{BASE}/"}) player_html = player_resp.text stream_match = re.search(r'data-stream-url="([^"]+)"', player_html) if stream_match: stream_path = stream_match.group(1).replace("&", "&") final_url = f"{CDN}{stream_path}" if ".m3u8" not in final_url: final_url += "#index.m3u8"
results.append({ "source": f"HDMovie2/srv{nume}", "title": "Hindi Dubbed HD", "quality": "1080p", "language": "Hindi", "url": final_url, "type": "m3u8", "headers": { "Referer": f"{CDN}/", "Origin": CDN, "User-Agent": UA, }, }) break
# Try molop.art player - use proxy for m3u8 molop_match = re.search(r'src="(https://molop\.art/watch\?v=[^"]+)"', embed_url) if molop_match: watch_url = molop_match.group(1) molop_resp = await client.get(watch_url, headers={"Referer": f"{BASE}/"}) molop_html = molop_resp.text
# Extract sniff params: sniff("ID", "TYPE", "HASH", ...) sniff_match = re.search(r'sniff\s*\(\s*"[^"]+"\s*,\s*"(\d+)"\s*,\s*"([a-f0-9]{20,})"', molop_html) if sniff_match: stream_type = sniff_match.group(1) hash_val = sniff_match.group(2)
# Get session cookie from molop.art session_cookie = await _get_molop_session(watch_url, client)
if session_cookie: # Fetch the actual m3u8 content server-side (with cookie) m3u8_url = f"https://molop.art/m3u8/{stream_type}/{hash_val}/master.m3u8?s=1&cache=1" m3u8_resp = await client.get(m3u8_url, headers={ "Referer": "https://molop.art/", "Origin": "https://molop.art", "Cookie": session_cookie, }) m3u8_text = m3u8_resp.text
if "#EXTM3U" in m3u8_text: # Parse quality variants and expose them through our proxy variants = [] lines = m3u8_text.split("\n") for i, line in enumerate(lines): if line.startswith("#EXT-X-STREAM-INF:"): res_m = re.search(r'RESOLUTION=(\d+x\d+)', line) bw_m = re.search(r'BANDWIDTH=(\d+)', line) quality = res_m.group(1) if res_m else "Auto" bandwidth = int(bw_m.group(1)) if bw_m else 0 # Convert resolution to label if "1920x1080" in quality or "1080" in quality: qlabel = "1080p" elif "1280x720" in quality or "720" in quality: qlabel = "720p" elif "640x360" in quality or "360" in quality: qlabel = "360p" else: qlabel = quality if i + 1 < len(lines) and lines[i + 1].strip().startswith("http"): variant_url = lines[i + 1].strip() variants.append({ "quality": qlabel, "bandwidth": bandwidth, "url": variant_url, })
if variants: # Sort by bandwidth desc, pick best quality variants.sort(key=lambda v: v["bandwidth"], reverse=True) best_var = variants[0]
# Store the m3u8 data for the proxy to serve results.append({ "source": f"HDMovie2/molop{nume}", "title": "Hindi Dubbed HD", "quality": best_var["quality"], "language": "Hindi", "url": best_var["url"], "type": "m3u8", "headers": { "Referer": "https://molop.art/", "Origin": "https://molop.art", "User-Agent": UA, }, }) break else: # No variants found - return master through proxy results.append({ "source": f"HDMovie2/molop{nume}", "title": "Hindi Dubbed HD", "quality": "Auto", "language": "Hindi", "url": m3u8_url, "type": "m3u8", "proxy": True, "proxy_cookie": session_cookie, "headers": { "Referer": "https://molop.art/", "Origin": "https://molop.art", "User-Agent": UA, }, }) break else: errors.append(f"HDMovie2/molop{nume}: m3u8 returned invalid content (cookie session may have expired)") else: errors.append(f"HDMovie2/molop{nume}: Could not get molop.art session cookie") else: errors.append(f"HDMovie2/molop{nume}: No sniff hash found in player page")
# Skip prvs.top and ok.ru if "prvs.top" in embed_url or "ok.ru" in embed_url: continue
except Exception as e: errors.append(f"HDMovie2/srv{nume}: {str(e)}") continue
if not results: errors.append("HDMovie2: No working streams found")
except Exception as e: errors.append(f"HDMovie2: {str(e)}")
return results, errors
# ===== AllMovieLand Scraper (Hindi/Tamil/Multi via allmovieland.one) =====396 unmodified lines "languages": ["Hindi", "English"], "reliability": "high"}, "allmovieland": {"name": "AllMovieLand", "fn": lambda tid, mt, s, e: scrape_allmovieland(tid, mt, s, e), "languages": ["Hindi", "Tamil", "Telugu", "English", "Multi"], "reliability": "medium"}, "hdmovie2": {"name": "HDMovie2", "fn": lambda tid, mt, s, e: scrape_hdmovie2(tid, mt, s, e), "languages": ["Hindi", "English"], "reliability": "high"}, "netmirror": {"name": "NetMirror", "fn": lambda tid, mt, s, e: scrape_netmirror(tid, mt, s, e), "languages": ["Hindi", "English", "Multi"], "reliability": "high"}, "videasy": {"name": "Videasy", "fn": lambda tid, mt, s, e: scrape_videasy(tid, mt, s, e),2 unmodified lines "languages": ["English"], "reliability": "medium"},}
DEFAULT_SOURCES = ["cinesu", "vidnest", "dooflix", "castle", "movieboxhindi", "netmirror", "hdmovie2", "vidsrc", "vidrock"]DEFAULT_SOURCES = ["cinesu", "vidnest", "dooflix", "castle", "movieboxhindi", "netmirror", "vidsrc", "vidrock"]
# ===== Helper: Run scrapers =====86 unmodified lines for key, src in SOURCE_MAP.items()}, "default_sources": DEFAULT_SOURCES, "tips": [ "No source = default sources (cinesu, vidnest, dooflix, castle, movieboxhindi, netmirror, hdmovie2, vidsrc, vidrock)", "No source = default sources (cinesu, vidnest, dooflix, castle, movieboxhindi, netmirror, vidsrc, vidrock)", "Best for Hindi: /movie/ID/allmovieland or /movie/ID/dooflix or /movie/ID/movieboxhindi or /movie/ID/castle", "Best for English: /movie/ID/cinesu or /movie/ID/vidrock or /movie/ID/videasy", "Best for French: /movie/ID/vidnest",67 unmodified lines return {"status": "ok", "timestamp": int(time.time())}
# ===== HDMovie2 m3u8 Proxy =====# molop.art requires PHPSESSID cookie from the watch page session.# Direct m3u8 access without cookie redirects to banned.php.# This proxy fetches the m3u8 server-side with the cookie and returns it.
@app.get("/proxy/m3u8")async def proxy_m3u8(url: str = Query(..., description="The molop.art m3u8 URL to proxy")): """Proxy m3u8 requests through the server to handle molop.art session cookies.""" if not url or not url.startswith("https://molop.art/"): raise HTTPException(400, {"error": "Only molop.art URLs are supported by this proxy"})
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
try: # Extract watch URL from m3u8 URL hash to get the right session # m3u8 URL format: https://molop.art/m3u8/{type}/{hash}/master.m3u8 hash_m = re.search(r'/m3u8/\d+/([a-f0-9]+)/', url) async with httpx.AsyncClient(timeout=15, follow_redirects=False, headers={"User-Agent": UA}) as client: session_cookie = "" # Try to find a cached session for this hash now = time.time() for watch_url, cached in _molop_sessions.items(): if hash_m and hash_m.group(1) in watch_url: if cached["expires"] > now: session_cookie = cached["cookie"] break if not session_cookie: # If no cached session, try to get one by visiting a generic molop page resp = await client.get("https://molop.art/", headers={"Referer": "https://hdmovie2.com.se/"}) for cn, cv in resp.cookies.items(): if cn == "PHPSESSID": session_cookie = f"PHPSESSID={cv}" break if not session_cookie: sc = resp.headers.get("set-cookie", "") scm = re.search(r'PHPSESSID=([^;]+)', sc) if scm: session_cookie = f"PHPSESSID={scm.group(1)}"
# Fetch the m3u8 with session cookie headers = { "Referer": "https://molop.art/", "Origin": "https://molop.art", "User-Agent": UA, } if session_cookie: headers["Cookie"] = session_cookie
resp = await client.get(url, headers=headers) # If we get a redirect (banned.php), try getting a fresh session if resp.status_code in (301, 302, 303, 307): location = resp.headers.get("location", "") if "banned" in location: # Get a fresh session fresh_resp = await client.get("https://molop.art/", headers={"Referer": "https://hdmovie2.com.se/"}) fresh_cookie = "" for cn, cv in fresh_resp.cookies.items(): if cn == "PHPSESSID": fresh_cookie = f"PHPSESSID={cv}" break if not fresh_cookie: sc = fresh_resp.headers.get("set-cookie", "") scm = re.search(r'PHPSESSID=([^;]+)', sc) if scm: fresh_cookie = f"PHPSESSID={scm.group(1)}" if fresh_cookie: headers["Cookie"] = fresh_cookie resp = await client.get(url, headers=headers)
content = resp.text
# If the m3u8 has relative/absolute stream URLs, rewrite them to be absolute if "#EXTM3U" in content: base_url = url.rsplit("/", 1)[0] + "/" lines = content.split("\n") rewritten = [] for line in lines: stripped = line.strip() if stripped and not stripped.startswith("#") and not stripped.startswith("http"): # Relative URL -> make absolute rewritten.append(base_url + stripped) elif stripped and not stripped.startswith("#") and stripped.startswith("/"): rewritten.append("https://molop.art" + stripped) else: rewritten.append(line) content = "\n".join(rewritten)
return Response( content=content, media_type="application/vnd.apple.mpegurl", headers={ "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "*", "Cache-Control": "no-cache", } )
except Exception as e: raise HTTPException(500, {"error": f"Proxy error: {str(e)}"})
# Proxy for individual stream segments (molop.art/stream/...)@app.get("/proxy/stream")async def proxy_stream(url: str = Query(..., description="The molop.art stream URL to proxy")): """Proxy stream segment requests through the server.""" if not url or not url.startswith("https://molop.art/"): raise HTTPException(400, {"error": "Only molop.art URLs are supported"})
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
try: async with httpx.AsyncClient(timeout=15, follow_redirects=False, headers={"User-Agent": UA}) as client: # Try with any available session cookie now = time.time() session_cookie = "" for watch_url, cached in _molop_sessions.items(): if cached["expires"] > now: session_cookie = cached["cookie"] break
headers = { "Referer": "https://molop.art/", "Origin": "https://molop.art", "User-Agent": UA, } if session_cookie: headers["Cookie"] = session_cookie
resp = await client.get(url, headers=headers)
if resp.status_code in (301, 302, 303, 307): location = resp.headers.get("location", "") if "banned" in location: fresh_resp = await client.get("https://molop.art/", headers={"Referer": "https://hdmovie2.com.se/"}) fresh_cookie = "" for cn, cv in fresh_resp.cookies.items(): if cn == "PHPSESSID": fresh_cookie = f"PHPSESSID={cv}" break if fresh_cookie: headers["Cookie"] = fresh_cookie resp = await client.get(url, headers=headers)
content_type = resp.headers.get("content-type", "application/octet-stream") return Response( content=resp.content, media_type=content_type, headers={ "Access-Control-Allow-Origin": "*", "Cache-Control": "no-cache", } ) except Exception as e: raise HTTPException(500, {"error": f"Proxy error: {str(e)}"})
@app.get("/api/sources")async def list_sources():__pycache__/main.cpython-312.pyc
main.py+2-442