Add PelixPlay HD 16-thread downloader and auto-metadata
Browse files- _panel_app.py +167 -6
_panel_app.py
CHANGED
|
@@ -355,6 +355,138 @@ def _verify_and_extract_hls_segments(master_url, referer, ua):
|
|
| 355 |
return variant_url, seg_urls, res_label
|
| 356 |
|
| 357 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1, skip_embeds=None):
|
| 359 |
"""Consulta api.php de PelixPlay con reintentos y extrae la lista verificada de segmentos HLS en Audio Latino HD."""
|
| 360 |
skip_set = set(skip_embeds or [])
|
|
@@ -438,9 +570,7 @@ def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1, skip
|
|
| 438 |
if norm_u != u and norm_u not in embed_candidates and norm_u not in skip_set:
|
| 439 |
embed_candidates.append(norm_u)
|
| 440 |
|
| 441 |
-
if not embed_candidates:
|
| 442 |
-
if captcha_only_servers:
|
| 443 |
-
raise RuntimeError("Esta película en PelixPlay solo tiene servidores con Captcha humano (PowVideo/Streamplay en Castellano) y aún no fue subida en servidor HD descargable.")
|
| 444 |
raise RuntimeError("No se encontraron servidores de video activos en PelixPlay para este título.")
|
| 445 |
|
| 446 |
# 1. Intentar desempaquetar directamente desde nuestra IP o vía Worker de Morencius (HLS4 / HLS3 / HLS2) y verificar segmento 0
|
|
@@ -500,9 +630,27 @@ def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1, skip
|
|
| 500 |
time.sleep(1.2)
|
| 501 |
continue
|
| 502 |
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
|
| 507 |
|
| 508 |
def strip_fake_png_header(chunk_bytes):
|
|
@@ -558,6 +706,19 @@ def download_pelixplay_to_mp4(job, p_info, job_dir):
|
|
| 558 |
if api_title and not job.get("title"):
|
| 559 |
job["title"] = api_title
|
| 560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
headers = {
|
| 562 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
| 563 |
"Referer": referer
|
|
|
|
| 355 |
return variant_url, seg_urls, res_label
|
| 356 |
|
| 357 |
|
| 358 |
+
|
| 359 |
+
def extract_streamtape_mp4(st_url, ua):
|
| 360 |
+
"""Extrae el enlace .mp4 directo de Streamtape sin Captcha."""
|
| 361 |
+
try:
|
| 362 |
+
r = requests.get(st_url, headers={"User-Agent": ua, "Referer": "https://pelixplay.app/"}, timeout=15)
|
| 363 |
+
if r.status_code != 200:
|
| 364 |
+
return None
|
| 365 |
+
matches = re.findall(
|
| 366 |
+
r"getElementById\(['\"](?:norobotlink|robotlink|ideoooolink)['\"]\)\.innerHTML\s*=\s*['\"]([^'\"]*)['\"]\s*\+\s*\(['\"]([^'\"]+)['\"]\)\.substring\((\d+)\)(?:\.substring\((\d+)\))?",
|
| 367 |
+
r.text
|
| 368 |
+
)
|
| 369 |
+
if matches:
|
| 370 |
+
prefix, token_part, sub1, sub2 = matches[-1]
|
| 371 |
+
s_cut = int(sub1) + (int(sub2) if sub2 else 0)
|
| 372 |
+
direct_mp4 = "https:" + prefix + token_part[s_cut:] + "&stream=1"
|
| 373 |
+
return {"mp4_url": direct_mp4, "referer": st_url, "cookies": dict(r.cookies)}
|
| 374 |
+
except Exception:
|
| 375 |
+
pass
|
| 376 |
+
return None
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
def extract_powvideo_or_streamplay_auto(emb_url, ua, job=None):
|
| 380 |
+
"""
|
| 381 |
+
Abre PowVideo (powwideo.org) o Streamplay (straemplay.org) en Chromium oculto,
|
| 382 |
+
hace Auto-Clic en el cuadradito 'No soy un robot' y extrae los streams HLS/MP4 de JWPlayer.
|
| 383 |
+
"""
|
| 384 |
+
try:
|
| 385 |
+
from playwright.sync_api import sync_playwright
|
| 386 |
+
except ImportError:
|
| 387 |
+
if job:
|
| 388 |
+
job["status"] = "⚙️ Instalando motor Auto-Clic (Playwright Chromium) por única vez..."
|
| 389 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "-q", "playwright"], check=False)
|
| 390 |
+
subprocess.run([sys.executable, "-m", "playwright", "install", "chromium"], check=False)
|
| 391 |
+
from playwright.sync_api import sync_playwright
|
| 392 |
+
|
| 393 |
+
for attempt in range(2):
|
| 394 |
+
try:
|
| 395 |
+
with sync_playwright() as p:
|
| 396 |
+
browser = p.chromium.launch(
|
| 397 |
+
headless=True,
|
| 398 |
+
args=["--disable-blink-features=AutomationControlled", "--mute-audio", "--no-sandbox"]
|
| 399 |
+
)
|
| 400 |
+
context = browser.new_context(user_agent=ua, viewport={"width": 1280, "height": 720})
|
| 401 |
+
context.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined});")
|
| 402 |
+
page = context.new_page()
|
| 403 |
+
|
| 404 |
+
page.goto(emb_url, referer="https://pelixplay.app/", wait_until="domcontentloaded", timeout=25000)
|
| 405 |
+
time.sleep(1.6)
|
| 406 |
+
page.evaluate("if (typeof letgo === 'function') letgo();")
|
| 407 |
+
time.sleep(3.8)
|
| 408 |
+
|
| 409 |
+
box_info = page.evaluate("""() => {
|
| 410 |
+
document.querySelectorAll('iframe').forEach(el => {
|
| 411 |
+
if (!el.src || !el.src.includes('recaptcha')) el.remove();
|
| 412 |
+
});
|
| 413 |
+
document.querySelectorAll('div').forEach(el => {
|
| 414 |
+
if (el.style && parseInt(el.style.zIndex || 0) > 1000) el.remove();
|
| 415 |
+
});
|
| 416 |
+
const rc = document.querySelector('iframe[src*="recaptcha/api2/anchor"]');
|
| 417 |
+
if (!rc) return null;
|
| 418 |
+
const r = rc.getBoundingClientRect();
|
| 419 |
+
return {x: r.x + 28, y: r.y + 38};
|
| 420 |
+
}""")
|
| 421 |
+
|
| 422 |
+
if box_info:
|
| 423 |
+
if job:
|
| 424 |
+
job["status"] = "🤖 Haciendo Auto-Clic en 'No soy un robot' (PowVideo/Streamplay)..."
|
| 425 |
+
page.mouse.click(box_info["x"], box_info["y"])
|
| 426 |
+
for _ in range(14):
|
| 427 |
+
time.sleep(1.0)
|
| 428 |
+
try:
|
| 429 |
+
srcs = page.evaluate("() => (typeof window.sources !== 'undefined' && Array.isArray(window.sources)) ? window.sources : null")
|
| 430 |
+
if srcs:
|
| 431 |
+
cookies_dict = {c["name"]: c["value"] for c in context.cookies()}
|
| 432 |
+
ref_url = page.url
|
| 433 |
+
browser.close()
|
| 434 |
+
hls_u = None
|
| 435 |
+
mp4_u = None
|
| 436 |
+
for s_item in srcs:
|
| 437 |
+
f_u = (s_item.get("file") or "") if isinstance(s_item, dict) else ""
|
| 438 |
+
if ".m3u8" in f_u:
|
| 439 |
+
hls_u = f_u
|
| 440 |
+
elif ".mp4" in f_u:
|
| 441 |
+
mp4_u = f_u
|
| 442 |
+
return {"hls_url": hls_u, "mp4_url": mp4_u, "referer": ref_url, "cookies": cookies_dict}
|
| 443 |
+
except Exception:
|
| 444 |
+
continue
|
| 445 |
+
browser.close()
|
| 446 |
+
except Exception:
|
| 447 |
+
time.sleep(1.0)
|
| 448 |
+
continue
|
| 449 |
+
return None
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def download_direct_mp4_stream(mp4_url, referer, cookies, ua, out_mp4_path, job, label_srv="Directo HD"):
|
| 453 |
+
"""Descarga un archivo .mp4 directo (Streamtape / PowVideo / Streamplay) mostrando velocidad y ETA."""
|
| 454 |
+
import urllib3
|
| 455 |
+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 456 |
+
hdrs = {"User-Agent": ua, "Referer": referer}
|
| 457 |
+
with requests.get(mp4_url, headers=hdrs, cookies=cookies, stream=True, timeout=(12, 45), verify=False, allow_redirects=True) as r:
|
| 458 |
+
if r.status_code not in (200, 206):
|
| 459 |
+
raise RuntimeError(f"Servidor {label_srv} devolvió HTTP {r.status_code}")
|
| 460 |
+
total_bytes = int(r.headers.get("Content-Length") or 0)
|
| 461 |
+
done_bytes = 0
|
| 462 |
+
t_start = time.time()
|
| 463 |
+
last_ui = 0
|
| 464 |
+
with open(out_mp4_path, "wb") as f:
|
| 465 |
+
for chunk in r.iter_content(chunk_size=512 * 1024):
|
| 466 |
+
if job.get("cancelled"):
|
| 467 |
+
raise InterruptedError("Cancelado por el usuario")
|
| 468 |
+
if not chunk:
|
| 469 |
+
continue
|
| 470 |
+
f.write(chunk)
|
| 471 |
+
done_bytes += len(chunk)
|
| 472 |
+
now = time.time()
|
| 473 |
+
if now - last_ui >= 0.5:
|
| 474 |
+
last_ui = now
|
| 475 |
+
elapsed = max(0.3, now - t_start)
|
| 476 |
+
speed_mb = (done_bytes / (1024 * 1024)) / elapsed
|
| 477 |
+
if total_bytes > 0:
|
| 478 |
+
pct = int((done_bytes / total_bytes) * 100)
|
| 479 |
+
rem_b = max(0, total_bytes - done_bytes)
|
| 480 |
+
eta_s = (rem_b / (done_bytes / elapsed)) if done_bytes > 0 else 0
|
| 481 |
+
job["progress"] = min(68, 6 + int((done_bytes / total_bytes) * 62))
|
| 482 |
+
job["status"] = f"⬇️ Descargando {label_srv}: {pct}% ({format_size(done_bytes)} / {format_size(total_bytes)}) a {speed_mb:.1f} MB/s — {format_eta(eta_s)}"
|
| 483 |
+
else:
|
| 484 |
+
job["status"] = f"⬇️ Descargando {label_srv}: {format_size(done_bytes)} a {speed_mb:.1f} MB/s..."
|
| 485 |
+
if not os.path.exists(out_mp4_path) or os.path.getsize(out_mp4_path) < 2 * 1024 * 1024:
|
| 486 |
+
raise RuntimeError(f"Archivo descargado de {label_srv} incompleto o vacío.")
|
| 487 |
+
return out_mp4_path
|
| 488 |
+
|
| 489 |
+
|
| 490 |
def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1, skip_embeds=None):
|
| 491 |
"""Consulta api.php de PelixPlay con reintentos y extrae la lista verificada de segmentos HLS en Audio Latino HD."""
|
| 492 |
skip_set = set(skip_embeds or [])
|
|
|
|
| 570 |
if norm_u != u and norm_u not in embed_candidates and norm_u not in skip_set:
|
| 571 |
embed_candidates.append(norm_u)
|
| 572 |
|
| 573 |
+
if not embed_candidates and not captcha_only_servers:
|
|
|
|
|
|
|
| 574 |
raise RuntimeError("No se encontraron servidores de video activos en PelixPlay para este título.")
|
| 575 |
|
| 576 |
# 1. Intentar desempaquetar directamente desde nuestra IP o vía Worker de Morencius (HLS4 / HLS3 / HLS2) y verificar segmento 0
|
|
|
|
| 630 |
time.sleep(1.2)
|
| 631 |
continue
|
| 632 |
|
| 633 |
+
# 3. Fallback Automático: Streamtape (.mp4 directo) y Auto-Clic en PowVideo / Streamplay (Playwright Chromium)
|
| 634 |
+
for emb_url in embed_candidates:
|
| 635 |
+
if "streamtape.com" in emb_url.lower():
|
| 636 |
+
st_info = extract_streamtape_mp4(emb_url, ua)
|
| 637 |
+
if st_info and st_info.get("mp4_url"):
|
| 638 |
+
return "DIRECT_MP4::" + st_info["mp4_url"], [], "Streamtape HD", st_info["referer"], data.get("tmdb_title"), emb_url
|
| 639 |
+
|
| 640 |
+
for pow_url in captcha_only_servers:
|
| 641 |
+
if pow_url in skip_set:
|
| 642 |
+
continue
|
| 643 |
+
pw_info = extract_powvideo_or_streamplay_auto(pow_url, ua)
|
| 644 |
+
if pw_info:
|
| 645 |
+
if pw_info.get("hls_url"):
|
| 646 |
+
verified = _verify_and_extract_hls_segments(pw_info["hls_url"], pw_info["referer"], ua)
|
| 647 |
+
if verified:
|
| 648 |
+
variant_url, seg_urls, res_label = verified
|
| 649 |
+
return variant_url, seg_urls, res_label, pw_info["referer"], data.get("tmdb_title"), pow_url
|
| 650 |
+
if pw_info.get("mp4_url"):
|
| 651 |
+
return "DIRECT_MP4::" + pw_info["mp4_url"], pw_info.get("cookies") or {}, "PowVideo 720p", pw_info["referer"], data.get("tmdb_title"), pow_url
|
| 652 |
+
|
| 653 |
+
raise RuntimeError("No se pudo extraer un stream HLS/MP4 directo de los servidores de PelixPlay.")
|
| 654 |
|
| 655 |
|
| 656 |
def strip_fake_png_header(chunk_bytes):
|
|
|
|
| 706 |
if api_title and not job.get("title"):
|
| 707 |
job["title"] = api_title
|
| 708 |
|
| 709 |
+
if isinstance(variant_url, str) and variant_url.startswith("DIRECT_MP4::"):
|
| 710 |
+
direct_mp4_url = variant_url.split("DIRECT_MP4::", 1)[1]
|
| 711 |
+
cookies_extra = seg_urls if isinstance(seg_urls, dict) else {}
|
| 712 |
+
raw_mp4_out = os.path.join(job_dir, "pelix_direct_dl.mp4")
|
| 713 |
+
try:
|
| 714 |
+
download_direct_mp4_stream(direct_mp4_url, referer, cookies_extra, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36", raw_mp4_out, job, label_srv=res_label)
|
| 715 |
+
return remux_video_to_latino_mp4(raw_mp4_out, job_dir, job)
|
| 716 |
+
except InterruptedError:
|
| 717 |
+
raise
|
| 718 |
+
except Exception as e_dmp4:
|
| 719 |
+
last_srv_err = e_dmp4
|
| 720 |
+
continue
|
| 721 |
+
|
| 722 |
headers = {
|
| 723 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
|
| 724 |
"Referer": referer
|