Add PelixPlay HD 16-thread downloader and auto-metadata
Browse files- _panel_app.py +132 -62
_panel_app.py
CHANGED
|
@@ -299,18 +299,75 @@ def unpack_js_eval(html_text):
|
|
| 299 |
return re.sub(r"\b\w+\b", lambda match: repl.get(match.group(0), match.group(0)), p)
|
| 300 |
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1):
|
| 303 |
-
"""Consulta api.php de PelixPlay y extrae la
|
| 304 |
params = {"action": "details", "id": str(tmdb_id), "type": media_type}
|
| 305 |
if media_type == "tv":
|
| 306 |
params["season"] = str(season or 1)
|
| 307 |
params["episode"] = str(episode or 1)
|
| 308 |
|
|
|
|
| 309 |
headers = {
|
| 310 |
-
"User-Agent":
|
| 311 |
"Referer": f"https://pelixplay.app/embed/embed-final.html?id={tmdb_id}"
|
| 312 |
}
|
| 313 |
-
r =
|
| 314 |
data = r.json()
|
| 315 |
if not data.get("ok"):
|
| 316 |
raise RuntimeError("PelixPlay informó que este título/episodio no está disponible todavía.")
|
|
@@ -330,9 +387,9 @@ def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1):
|
|
| 330 |
if not chosen_embeds:
|
| 331 |
raise RuntimeError("No se encontraron servidores de video activos en PelixPlay para este título.")
|
| 332 |
|
| 333 |
-
# Recolectar URLs de StreamWish (dohaxe) y FileLions
|
| 334 |
embed_candidates = []
|
| 335 |
-
for prov_key in ["streamwish", "filelions", "vidhide"] + list(chosen_embeds.keys()):
|
| 336 |
urls = chosen_embeds.get(prov_key) or []
|
| 337 |
if isinstance(urls, str):
|
| 338 |
urls = [urls]
|
|
@@ -340,28 +397,27 @@ def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1):
|
|
| 340 |
if u and u not in embed_candidates:
|
| 341 |
embed_candidates.append(u)
|
| 342 |
|
| 343 |
-
# 1. Intentar desempaquetar directamente desde nuestra IP (HLS4 / HLS3)
|
| 344 |
for emb_url in embed_candidates:
|
| 345 |
try:
|
| 346 |
parsed_emb = urlparse(emb_url)
|
| 347 |
emb_origin = f"{parsed_emb.scheme}://{parsed_emb.netloc}"
|
| 348 |
-
r_emb =
|
| 349 |
unpacked = unpack_js_eval(r_emb.text)
|
| 350 |
if unpacked:
|
| 351 |
-
# Buscar hls4 primero, luego hls3, luego hls2
|
| 352 |
for hls_key in ["hls4", "hls3", "hls2"]:
|
| 353 |
m_h = re.search(rf'"{hls_key}"\s*:\s*"([^"]+)"', unpacked)
|
| 354 |
if m_h:
|
| 355 |
raw_hls = m_h.group(1).replace("\\/", "/")
|
| 356 |
full_hls = urljoin(emb_origin + "/", raw_hls)
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
return
|
| 361 |
except Exception:
|
| 362 |
continue
|
| 363 |
|
| 364 |
-
# 2. Fallback: usar extract.php de PelixPlay
|
| 365 |
for emb_url in embed_candidates:
|
| 366 |
try:
|
| 367 |
r_ext = requests.post(
|
|
@@ -374,9 +430,10 @@ def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1):
|
|
| 374 |
ext_data = r_ext.json()
|
| 375 |
ref = ext_data.get("referer") or "https://pelixplay.app/"
|
| 376 |
for s_url in (ext_data.get("streams") or []):
|
| 377 |
-
|
| 378 |
-
if
|
| 379 |
-
|
|
|
|
| 380 |
except Exception:
|
| 381 |
continue
|
| 382 |
|
|
@@ -414,7 +471,7 @@ def download_pelixplay_to_mp4(job, p_info, job_dir):
|
|
| 414 |
job["status"] = "🔍 Extrayendo stream Audio Latino HD desde PelixPlay..."
|
| 415 |
job["progress"] = 4
|
| 416 |
|
| 417 |
-
|
| 418 |
if api_title and not job.get("title"):
|
| 419 |
job["title"] = api_title
|
| 420 |
|
|
@@ -423,34 +480,6 @@ def download_pelixplay_to_mp4(job, p_info, job_dir):
|
|
| 423 |
"Referer": referer
|
| 424 |
}
|
| 425 |
|
| 426 |
-
r_master = requests.get(master_url, headers=headers, timeout=12)
|
| 427 |
-
master_text = r_master.text
|
| 428 |
-
|
| 429 |
-
# Elegir la variante de mayor calidad (BANDWIDTH / RESOLUTION más alta)
|
| 430 |
-
variant_url = master_url
|
| 431 |
-
res_label = "HD"
|
| 432 |
-
if "#EXT-X-STREAM-INF" in master_text:
|
| 433 |
-
best_bw = -1
|
| 434 |
-
lines = [l.strip() for l in master_text.splitlines() if l.strip()]
|
| 435 |
-
for i, line in enumerate(lines):
|
| 436 |
-
if line.startswith("#EXT-X-STREAM-INF") and i + 1 < len(lines):
|
| 437 |
-
bw_m = re.search(r"BANDWIDTH=(\d+)", line)
|
| 438 |
-
res_m = re.search(r"RESOLUTION=(\d+x\d+)", line)
|
| 439 |
-
bw = int(bw_m.group(1)) if bw_m else 0
|
| 440 |
-
next_uri = lines[i + 1]
|
| 441 |
-
if not next_uri.startswith("#") and bw > best_bw:
|
| 442 |
-
best_bw = bw
|
| 443 |
-
variant_url = urljoin(master_url, next_uri)
|
| 444 |
-
if res_m:
|
| 445 |
-
res_label = res_m.group(1)
|
| 446 |
-
|
| 447 |
-
r_var = requests.get(variant_url, headers=headers, timeout=15)
|
| 448 |
-
var_text = r_var.text
|
| 449 |
-
seg_urls = [urljoin(variant_url, l.strip()) for l in var_text.splitlines() if l.strip() and not l.strip().startswith("#")]
|
| 450 |
-
|
| 451 |
-
if not seg_urls:
|
| 452 |
-
raise RuntimeError("La lista HLS de PelixPlay no devolvió segmentos de video.")
|
| 453 |
-
|
| 454 |
total_segs = len(seg_urls)
|
| 455 |
job["status"] = f"⬇️ Descargando PelixPlay ({res_label}): 0% (0/{total_segs} segmentos)..."
|
| 456 |
job["progress"] = 6
|
|
@@ -470,7 +499,9 @@ def download_pelixplay_to_mp4(job, p_info, job_dir):
|
|
| 470 |
if job.get("cancelled"):
|
| 471 |
raise InterruptedError("Cancelado por el usuario")
|
| 472 |
try:
|
| 473 |
-
resp = requests.get(s_url, headers=
|
|
|
|
|
|
|
| 474 |
if resp.status_code == 200 and resp.content:
|
| 475 |
clean_ts = strip_fake_png_header(resp.content)
|
| 476 |
seg_file = os.path.join(seg_dir, f"seg_{idx:05d}.ts")
|
|
@@ -546,29 +577,68 @@ def download_pelixplay_to_mp4(job, p_info, job_dir):
|
|
| 546 |
return combined_ts
|
| 547 |
|
| 548 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 549 |
def resolve_download_url(url):
|
| 550 |
url = url.strip()
|
| 551 |
if "mediafire.com" in url.lower():
|
| 552 |
if re.match(r"^https?://download[0-9]*\.mediafire\.com/", url, flags=re.I):
|
| 553 |
return url
|
| 554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
try:
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"}
|
| 561 |
r = requests.get(url, headers=headers, timeout=15, allow_redirects=True)
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
btn = soup.find("a", {"id": "downloadButton"})
|
| 569 |
-
if btn and btn.get("href") and btn.get("href").startswith("http"):
|
| 570 |
-
return btn.get("href")
|
| 571 |
-
raise RuntimeError("No se pudo extraer el enlace directo de MediaFire. Verifique que el archivo siga activo.")
|
| 572 |
|
| 573 |
if "dropbox.com" in url.lower():
|
| 574 |
if "dl=0" in url:
|
|
|
|
| 299 |
return re.sub(r"\b\w+\b", lambda match: repl.get(match.group(0), match.group(0)), p)
|
| 300 |
|
| 301 |
|
| 302 |
+
def cffi_get(url, headers=None, params=None, timeout=15):
|
| 303 |
+
try:
|
| 304 |
+
from curl_cffi import requests as creq
|
| 305 |
+
r = creq.get(url, headers=headers, params=params, impersonate="chrome", timeout=timeout, allow_redirects=True)
|
| 306 |
+
if r.status_code == 200:
|
| 307 |
+
return r
|
| 308 |
+
except Exception:
|
| 309 |
+
pass
|
| 310 |
+
return requests.get(url, headers=headers, params=params, timeout=timeout, allow_redirects=True)
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def _verify_and_extract_hls_segments(master_url, referer, ua):
|
| 314 |
+
"""Verifica que el master.m3u8, su variante de mayor calidad y el primer segmento respondan 200 OK."""
|
| 315 |
+
hdrs = {"User-Agent": ua, "Referer": referer}
|
| 316 |
+
r_master = cffi_get(master_url, headers=hdrs, timeout=10)
|
| 317 |
+
if r_master.status_code != 200 or "#EXTM3U" not in r_master.text:
|
| 318 |
+
return None
|
| 319 |
+
master_text = r_master.text
|
| 320 |
+
|
| 321 |
+
variant_url = master_url
|
| 322 |
+
res_label = "HD"
|
| 323 |
+
if "#EXT-X-STREAM-INF" in master_text:
|
| 324 |
+
best_bw = -1
|
| 325 |
+
lines = [l.strip() for l in master_text.splitlines() if l.strip()]
|
| 326 |
+
for i, line in enumerate(lines):
|
| 327 |
+
if line.startswith("#EXT-X-STREAM-INF") and i + 1 < len(lines):
|
| 328 |
+
bw_m = re.search(r"BANDWIDTH=(\d+)", line)
|
| 329 |
+
res_m = re.search(r"RESOLUTION=(\d+x\d+)", line)
|
| 330 |
+
bw = int(bw_m.group(1)) if bw_m else 0
|
| 331 |
+
next_uri = lines[i + 1]
|
| 332 |
+
if not next_uri.startswith("#") and bw > best_bw:
|
| 333 |
+
best_bw = bw
|
| 334 |
+
variant_url = urljoin(master_url, next_uri)
|
| 335 |
+
if res_m:
|
| 336 |
+
res_label = res_m.group(1)
|
| 337 |
+
|
| 338 |
+
r_var = cffi_get(variant_url, headers=hdrs, timeout=12)
|
| 339 |
+
if r_var.status_code != 200 or "#EXTM3U" not in r_var.text:
|
| 340 |
+
return None
|
| 341 |
+
|
| 342 |
+
seg_urls = [
|
| 343 |
+
urljoin(variant_url, l.strip())
|
| 344 |
+
for l in r_var.text.splitlines()
|
| 345 |
+
if l.strip() and not l.strip().startswith("#") and "<html" not in l.lower()
|
| 346 |
+
]
|
| 347 |
+
if len(seg_urls) < 5:
|
| 348 |
+
return None
|
| 349 |
+
|
| 350 |
+
# Probar que el primer segmento realmente descargue bytes de video (evita 403 por bloqueo de IP)
|
| 351 |
+
r_s0 = cffi_get(seg_urls[0], headers=hdrs, timeout=10)
|
| 352 |
+
if r_s0.status_code != 200 or len(r_s0.content) < 1000:
|
| 353 |
+
return None
|
| 354 |
+
|
| 355 |
+
return variant_url, seg_urls, res_label
|
| 356 |
+
|
| 357 |
+
|
| 358 |
def resolve_pelixplay_hls(tmdb_id, media_type="movie", season=1, episode=1):
|
| 359 |
+
"""Consulta api.php de PelixPlay y extrae la lista verificada de segmentos HLS en Audio Latino HD."""
|
| 360 |
params = {"action": "details", "id": str(tmdb_id), "type": media_type}
|
| 361 |
if media_type == "tv":
|
| 362 |
params["season"] = str(season or 1)
|
| 363 |
params["episode"] = str(episode or 1)
|
| 364 |
|
| 365 |
+
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
|
| 366 |
headers = {
|
| 367 |
+
"User-Agent": ua,
|
| 368 |
"Referer": f"https://pelixplay.app/embed/embed-final.html?id={tmdb_id}"
|
| 369 |
}
|
| 370 |
+
r = cffi_get("https://pelixplay.app/embed/api.php", params=params, headers=headers, timeout=15)
|
| 371 |
data = r.json()
|
| 372 |
if not data.get("ok"):
|
| 373 |
raise RuntimeError("PelixPlay informó que este título/episodio no está disponible todavía.")
|
|
|
|
| 387 |
if not chosen_embeds:
|
| 388 |
raise RuntimeError("No se encontraron servidores de video activos en PelixPlay para este título.")
|
| 389 |
|
| 390 |
+
# Recolectar URLs de StreamWish (dohaxe), Morencius y FileLions primero
|
| 391 |
embed_candidates = []
|
| 392 |
+
for prov_key in ["streamwish", "morencius", "filelions", "vidhide"] + list(chosen_embeds.keys()):
|
| 393 |
urls = chosen_embeds.get(prov_key) or []
|
| 394 |
if isinstance(urls, str):
|
| 395 |
urls = [urls]
|
|
|
|
| 397 |
if u and u not in embed_candidates:
|
| 398 |
embed_candidates.append(u)
|
| 399 |
|
| 400 |
+
# 1. Intentar desempaquetar directamente desde nuestra IP (HLS4 / HLS3 / HLS2) y verificar segmento 0
|
| 401 |
for emb_url in embed_candidates:
|
| 402 |
try:
|
| 403 |
parsed_emb = urlparse(emb_url)
|
| 404 |
emb_origin = f"{parsed_emb.scheme}://{parsed_emb.netloc}"
|
| 405 |
+
r_emb = cffi_get(emb_url, headers={"User-Agent": ua, "Referer": "https://pelixplay.app/"}, timeout=12)
|
| 406 |
unpacked = unpack_js_eval(r_emb.text)
|
| 407 |
if unpacked:
|
|
|
|
| 408 |
for hls_key in ["hls4", "hls3", "hls2"]:
|
| 409 |
m_h = re.search(rf'"{hls_key}"\s*:\s*"([^"]+)"', unpacked)
|
| 410 |
if m_h:
|
| 411 |
raw_hls = m_h.group(1).replace("\\/", "/")
|
| 412 |
full_hls = urljoin(emb_origin + "/", raw_hls)
|
| 413 |
+
verified = _verify_and_extract_hls_segments(full_hls, emb_origin + "/", ua)
|
| 414 |
+
if verified:
|
| 415 |
+
variant_url, seg_urls, res_label = verified
|
| 416 |
+
return variant_url, seg_urls, res_label, emb_origin + "/", data.get("tmdb_title")
|
| 417 |
except Exception:
|
| 418 |
continue
|
| 419 |
|
| 420 |
+
# 2. Fallback: usar extract.php de PelixPlay verificando también que el segmento 0 no dé 403
|
| 421 |
for emb_url in embed_candidates:
|
| 422 |
try:
|
| 423 |
r_ext = requests.post(
|
|
|
|
| 430 |
ext_data = r_ext.json()
|
| 431 |
ref = ext_data.get("referer") or "https://pelixplay.app/"
|
| 432 |
for s_url in (ext_data.get("streams") or []):
|
| 433 |
+
verified = _verify_and_extract_hls_segments(s_url, ref, ua)
|
| 434 |
+
if verified:
|
| 435 |
+
variant_url, seg_urls, res_label = verified
|
| 436 |
+
return variant_url, seg_urls, res_label, ref, data.get("tmdb_title")
|
| 437 |
except Exception:
|
| 438 |
continue
|
| 439 |
|
|
|
|
| 471 |
job["status"] = "🔍 Extrayendo stream Audio Latino HD desde PelixPlay..."
|
| 472 |
job["progress"] = 4
|
| 473 |
|
| 474 |
+
variant_url, seg_urls, res_label, referer, api_title = resolve_pelixplay_hls(tmdb_id, media_type, season_num, episode_num)
|
| 475 |
if api_title and not job.get("title"):
|
| 476 |
job["title"] = api_title
|
| 477 |
|
|
|
|
| 480 |
"Referer": referer
|
| 481 |
}
|
| 482 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
total_segs = len(seg_urls)
|
| 484 |
job["status"] = f"⬇️ Descargando PelixPlay ({res_label}): 0% (0/{total_segs} segmentos)..."
|
| 485 |
job["progress"] = 6
|
|
|
|
| 499 |
if job.get("cancelled"):
|
| 500 |
raise InterruptedError("Cancelado por el usuario")
|
| 501 |
try:
|
| 502 |
+
resp = requests.get(s_url, headers=headers, timeout=20)
|
| 503 |
+
if resp.status_code != 200 or not resp.content:
|
| 504 |
+
resp = cffi_get(s_url, headers=headers, timeout=20)
|
| 505 |
if resp.status_code == 200 and resp.content:
|
| 506 |
clean_ts = strip_fake_png_header(resp.content)
|
| 507 |
seg_file = os.path.join(seg_dir, f"seg_{idx:05d}.ts")
|
|
|
|
| 577 |
return combined_ts
|
| 578 |
|
| 579 |
|
| 580 |
+
def _extract_mediafire_direct_from_html(html):
|
| 581 |
+
if not html:
|
| 582 |
+
return None
|
| 583 |
+
matches = re.findall(r'https?://download[0-9]*\.mediafire\.com/[^\s"\'<>]+', html)
|
| 584 |
+
if matches:
|
| 585 |
+
return matches[0]
|
| 586 |
+
# MediaFire en IPs de Google Cloud oculta el link en Base64 dentro de data-scrambled-url
|
| 587 |
+
b64_matches = re.findall(r'data-scrambled-url=["\']([A-Za-z0-9+/=]+)["\']', html)
|
| 588 |
+
if not b64_matches:
|
| 589 |
+
b64_matches = re.findall(r'(aHR0cHM6Ly9kb3dubG9hZ[A-Za-z0-9+/=]+)', html)
|
| 590 |
+
for b64_str in b64_matches:
|
| 591 |
+
try:
|
| 592 |
+
decoded = base64.b64decode(b64_str).decode("utf-8", errors="ignore").strip()
|
| 593 |
+
if decoded.startswith("http"):
|
| 594 |
+
return decoded
|
| 595 |
+
except Exception:
|
| 596 |
+
pass
|
| 597 |
+
soup = BeautifulSoup(html, "html.parser")
|
| 598 |
+
btn = soup.find("a", {"id": "downloadButton"})
|
| 599 |
+
if btn:
|
| 600 |
+
scr = btn.get("data-scrambled-url")
|
| 601 |
+
if scr:
|
| 602 |
+
try:
|
| 603 |
+
decoded = base64.b64decode(scr).decode("utf-8", errors="ignore").strip()
|
| 604 |
+
if decoded.startswith("http"):
|
| 605 |
+
return decoded
|
| 606 |
+
except Exception:
|
| 607 |
+
pass
|
| 608 |
+
href = btn.get("href") or ""
|
| 609 |
+
if href.startswith("http"):
|
| 610 |
+
return href
|
| 611 |
+
if href.startswith("//"):
|
| 612 |
+
return "https:" + href
|
| 613 |
+
return None
|
| 614 |
+
|
| 615 |
+
|
| 616 |
def resolve_download_url(url):
|
| 617 |
url = url.strip()
|
| 618 |
if "mediafire.com" in url.lower():
|
| 619 |
if re.match(r"^https?://download[0-9]*\.mediafire\.com/", url, flags=re.I):
|
| 620 |
return url
|
| 621 |
+
for imp in ["chrome120", "chrome110", "chrome", "safari15_5"]:
|
| 622 |
+
try:
|
| 623 |
+
from curl_cffi import requests as creq
|
| 624 |
+
r = creq.get(url, impersonate=imp, timeout=20, allow_redirects=True)
|
| 625 |
+
direct = _extract_mediafire_direct_from_html(r.text)
|
| 626 |
+
if direct:
|
| 627 |
+
return direct
|
| 628 |
+
except Exception:
|
| 629 |
+
continue
|
| 630 |
try:
|
| 631 |
+
headers = {
|
| 632 |
+
"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",
|
| 633 |
+
"Accept-Language": "es-AR,es;q=0.9,en;q=0.8"
|
| 634 |
+
}
|
|
|
|
| 635 |
r = requests.get(url, headers=headers, timeout=15, allow_redirects=True)
|
| 636 |
+
direct = _extract_mediafire_direct_from_html(r.text)
|
| 637 |
+
if direct:
|
| 638 |
+
return direct
|
| 639 |
+
except Exception:
|
| 640 |
+
pass
|
| 641 |
+
raise RuntimeError("No se pudo extraer el enlace directo de MediaFire. Intentá copiar el link directo del botón azul Download.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 642 |
|
| 643 |
if "dropbox.com" in url.lower():
|
| 644 |
if "dl=0" in url:
|