Add PelixPlay HD 16-thread downloader and auto-metadata
Browse files- _panel_app.py +349 -3
_panel_app.py
CHANGED
|
@@ -782,6 +782,232 @@ def extract_latinomegahd_info(url, target_season=None):
|
|
| 782 |
}
|
| 783 |
|
| 784 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 785 |
def remux_video_to_latino_mp4(video_path, job_dir, job):
|
| 786 |
ext = os.path.splitext(video_path)[1].lower()
|
| 787 |
orig_size = os.path.getsize(video_path)
|
|
@@ -903,6 +1129,14 @@ def process_job(job):
|
|
| 903 |
if p_info:
|
| 904 |
# Ruta A: Descarga desde PelixPlay (16 hilos HLS + limpieza PNG + remux MP4)
|
| 905 |
target_video_path = download_pelixplay_to_mp4(job, p_info, job_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 906 |
else:
|
| 907 |
# Ruta B: Descarga desde MediaFire / LatinoMegaHD / Directo (.rar, .part1.rar, .zip, .mkv, .mp4)
|
| 908 |
source_urls = job.get("source_urls") or [job["source_url"]]
|
|
@@ -1223,6 +1457,13 @@ def api_pelixplay_meta():
|
|
| 1223 |
except Exception as e:
|
| 1224 |
return jsonify({"success": False, "message": str(e)})
|
| 1225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1226 |
p_info = parse_pelixplay_url(url)
|
| 1227 |
if not p_info:
|
| 1228 |
return jsonify({"success": False})
|
|
@@ -1244,10 +1485,33 @@ def api_enqueue():
|
|
| 1244 |
episode_start = (data.get("episode_name") or "Capitulo 01").strip()
|
| 1245 |
dataset_repo = (data.get("dataset_repo") or CATALOG.get("dataset_repo") or DEFAULT_DATASET_REPO).strip()
|
| 1246 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1247 |
urls = extract_urls_from_text(raw_urls)
|
| 1248 |
if not urls:
|
| 1249 |
return jsonify({"success": False, "message": "Pegá al menos un enlace válido."}), 400
|
| 1250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1251 |
# Si es un enlace de LatinoMegaHD, extraer automáticamente los enlaces MediaFire internos y metadatos
|
| 1252 |
is_lmhd = is_latinomegahd_url(urls[0])
|
| 1253 |
lm_movie_multipart = False
|
|
@@ -1312,6 +1576,37 @@ def api_enqueue():
|
|
| 1312 |
if hits:
|
| 1313 |
poster_url = hits[0]["poster"]
|
| 1314 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1315 |
# Si es Película y pegaron varias partes (.part1.rar, .part2.rar) o viene de LatinoMegaHD, agrupar en 1 solo Job
|
| 1316 |
if content_type == "movie" and len(urls) > 1 and (lm_movie_multipart or any(".part" in u.lower() for u in urls)):
|
| 1317 |
job = {
|
|
@@ -1326,6 +1621,10 @@ def api_enqueue():
|
|
| 1326 |
"season_name": season_name,
|
| 1327 |
"episode_name": "",
|
| 1328 |
"dataset_repo": dataset_repo,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1329 |
"state": "queued",
|
| 1330 |
"status": f"En cola ({len(urls)} partes MediaFire)...",
|
| 1331 |
"progress": 0,
|
|
@@ -1381,6 +1680,10 @@ def api_enqueue():
|
|
| 1381 |
"season_name": season_name,
|
| 1382 |
"episode_name": ep_label,
|
| 1383 |
"dataset_repo": dataset_repo,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1384 |
"state": "queued",
|
| 1385 |
"status": "En cola esperando turno...",
|
| 1386 |
"progress": 0,
|
|
@@ -1954,6 +2257,29 @@ HTML_TEMPLATE = r"""<!DOCTYPE html>
|
|
| 1954 |
</div>
|
| 1955 |
</div>
|
| 1956 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1957 |
<!-- Barra de Póster Seleccionado -->
|
| 1958 |
<div class="selected-poster-bar" id="selectedPosterBar">
|
| 1959 |
<img id="posterPreviewImg" src="" alt="Poster">
|
|
@@ -2074,7 +2400,8 @@ HTML_TEMPLATE = r"""<!DOCTYPE html>
|
|
| 2074 |
|
| 2075 |
async function onUrlInputChanged() {
|
| 2076 |
const val = document.getElementById('downloadUrls').value.trim();
|
| 2077 |
-
|
|
|
|
| 2078 |
lastDetectedPelixUrl = val;
|
| 2079 |
const badge = document.getElementById('autoFillBadge');
|
| 2080 |
if (badge) {
|
|
@@ -2090,6 +2417,8 @@ HTML_TEMPLATE = r"""<!DOCTYPE html>
|
|
| 2090 |
badge.style.display = 'inline';
|
| 2091 |
if (data.source === 'latinomegahd') {
|
| 2092 |
badge.textContent = `(✨ LatinoMegaHD: ${data.mf_count || 1} link(s) MediaFire listos sin publicidad)`;
|
|
|
|
|
|
|
| 2093 |
} else {
|
| 2094 |
badge.textContent = '(✨ Autocompletado de PelixPlay)';
|
| 2095 |
}
|
|
@@ -2107,6 +2436,18 @@ HTML_TEMPLATE = r"""<!DOCTYPE html>
|
|
| 2107 |
document.getElementById('contentType').value = data.content_type;
|
| 2108 |
toggleTypeFields();
|
| 2109 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2110 |
if (data.poster) {
|
| 2111 |
selectPoster(data.poster, data.title, true);
|
| 2112 |
}
|
|
@@ -2174,9 +2515,13 @@ HTML_TEMPLATE = r"""<!DOCTYPE html>
|
|
| 2174 |
const season_name = document.getElementById('seasonName').value.trim();
|
| 2175 |
const episode_name = document.getElementById('episodeName').value.trim();
|
| 2176 |
const dataset_repo = document.getElementById('datasetRepoInput').value.trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2177 |
|
| 2178 |
if (!urls) {
|
| 2179 |
-
alert('Pegá el enlace de PelixPlay
|
| 2180 |
return;
|
| 2181 |
}
|
| 2182 |
|
|
@@ -2185,7 +2530,8 @@ HTML_TEMPLATE = r"""<!DOCTYPE html>
|
|
| 2185 |
headers: {'Content-Type': 'application/json'},
|
| 2186 |
body: JSON.stringify({
|
| 2187 |
content_type, urls, title, poster_url,
|
| 2188 |
-
rar_password, season_name, episode_name, dataset_repo
|
|
|
|
| 2189 |
})
|
| 2190 |
});
|
| 2191 |
const data = await res.json();
|
|
|
|
| 782 |
}
|
| 783 |
|
| 784 |
|
| 785 |
+
def ensure_ytdlp():
|
| 786 |
+
try:
|
| 787 |
+
import yt_dlp
|
| 788 |
+
return yt_dlp
|
| 789 |
+
except ImportError:
|
| 790 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "-q", "yt-dlp"], check=False)
|
| 791 |
+
import yt_dlp
|
| 792 |
+
return yt_dlp
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
def is_ytdlp_url(url):
|
| 796 |
+
if not url:
|
| 797 |
+
return False
|
| 798 |
+
low = url.lower()
|
| 799 |
+
return any(d in low for d in (
|
| 800 |
+
"youtube.com/", "youtu.be/", "tiktok.com/", "instagram.com/",
|
| 801 |
+
"facebook.com/", "fb.watch/", "dailymotion.com/", "vimeo.com/",
|
| 802 |
+
"twitter.com/", "x.com/"
|
| 803 |
+
))
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
def extract_ytdlp_info(url):
|
| 807 |
+
yt_dlp = ensure_ytdlp()
|
| 808 |
+
ydl_opts = {
|
| 809 |
+
"quiet": True,
|
| 810 |
+
"no_warnings": True,
|
| 811 |
+
"extract_flat": "in_playlist",
|
| 812 |
+
"skip_download": True,
|
| 813 |
+
}
|
| 814 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 815 |
+
info = ydl.extract_info(url, download=False)
|
| 816 |
+
|
| 817 |
+
raw_title = (info.get("title") or "").strip()
|
| 818 |
+
video_urls = []
|
| 819 |
+
entries = info.get("entries")
|
| 820 |
+
if entries:
|
| 821 |
+
for e in entries:
|
| 822 |
+
if not e:
|
| 823 |
+
continue
|
| 824 |
+
et = (e.get("title") or "").lower()
|
| 825 |
+
if "blooper" in et:
|
| 826 |
+
continue
|
| 827 |
+
vid_id = e.get("id")
|
| 828 |
+
e_url = e.get("url") or (f"https://www.youtube.com/watch?v={vid_id}" if vid_id else "")
|
| 829 |
+
if e_url and not e_url.startswith("http"):
|
| 830 |
+
e_url = f"https://www.youtube.com/watch?v={e_url}"
|
| 831 |
+
if e_url:
|
| 832 |
+
video_urls.append(e_url)
|
| 833 |
+
else:
|
| 834 |
+
video_urls = [url]
|
| 835 |
+
|
| 836 |
+
low_t = raw_title.lower()
|
| 837 |
+
is_wanda = ("amoroso" in low_t or "love triangle" in low_t or "PL1N7BKTuLUGsISxuLYKafdr3Y_n1t6BKJ" in url)
|
| 838 |
+
if is_wanda:
|
| 839 |
+
title = "El Triángulo Amoroso"
|
| 840 |
+
content_type = "serie"
|
| 841 |
+
poster = "https://i.ytimg.com/vi/6vmUq_5Vr5I/maxresdefault.jpg"
|
| 842 |
+
suggested_trim = 16
|
| 843 |
+
else:
|
| 844 |
+
title = re.sub(r"\s*[-|]\s*(Episodios?|Temporada.*|Telefe.*)$", "", raw_title, flags=re.I).strip() or raw_title
|
| 845 |
+
content_type = "serie" if len(video_urls) > 1 else "movie"
|
| 846 |
+
poster = info.get("thumbnail") or ""
|
| 847 |
+
if not poster and info.get("thumbnails"):
|
| 848 |
+
poster = info["thumbnails"][-1].get("url", "")
|
| 849 |
+
suggested_trim = ""
|
| 850 |
+
|
| 851 |
+
return {
|
| 852 |
+
"title": title,
|
| 853 |
+
"content_type": content_type,
|
| 854 |
+
"poster": poster,
|
| 855 |
+
"season_name": "Temporada 1",
|
| 856 |
+
"episode_range": "Capitulo 01 (Temporada Completa)" if len(video_urls) > 1 else "Capitulo 01",
|
| 857 |
+
"video_urls": video_urls,
|
| 858 |
+
"ep_count": len(video_urls),
|
| 859 |
+
"vertical_to_horiz": True,
|
| 860 |
+
"remove_subtitles": True,
|
| 861 |
+
"merge_clips": True if len(video_urls) > 1 else False,
|
| 862 |
+
"trim_end_sec": suggested_trim
|
| 863 |
+
}
|
| 864 |
+
|
| 865 |
+
|
| 866 |
+
def download_and_process_vertical_or_ytdlp(job, job_dir):
|
| 867 |
+
yt_dlp = ensure_ytdlp()
|
| 868 |
+
ffmpeg_bin = shutil.which("ffmpeg") or "ffmpeg"
|
| 869 |
+
ffprobe_bin = shutil.which("ffprobe") or "ffprobe"
|
| 870 |
+
|
| 871 |
+
source_urls = job.get("source_urls") or [job["source_url"]]
|
| 872 |
+
# Si el primer link es una playlist de YouTube y aún no fue expandido, expandirlo ahora
|
| 873 |
+
if len(source_urls) == 1 and ("list=" in source_urls[0] or "playlist" in source_urls[0]):
|
| 874 |
+
try:
|
| 875 |
+
yt_meta = extract_ytdlp_info(source_urls[0])
|
| 876 |
+
if yt_meta.get("video_urls"):
|
| 877 |
+
source_urls = yt_meta["video_urls"]
|
| 878 |
+
except Exception:
|
| 879 |
+
pass
|
| 880 |
+
|
| 881 |
+
total_clips = len(source_urls)
|
| 882 |
+
vertical_to_horiz = bool(job.get("vertical_to_horiz"))
|
| 883 |
+
remove_subtitles = bool(job.get("remove_subtitles", True))
|
| 884 |
+
trim_end_sec = float(job.get("trim_end_sec") or 0.0)
|
| 885 |
+
|
| 886 |
+
ts_segments = []
|
| 887 |
+
for idx, clip_url in enumerate(source_urls, start=1):
|
| 888 |
+
if job.get("cancelled"):
|
| 889 |
+
raise InterruptedError("Proceso detenido por el usuario")
|
| 890 |
+
|
| 891 |
+
raw_clip_path = os.path.join(job_dir, f"raw_clip_{idx:03d}.mp4")
|
| 892 |
+
job["progress"] = 4 + int(((idx - 1) / max(1, total_clips)) * 62)
|
| 893 |
+
job["status"] = f"⬇️ Descargando video {idx}/{total_clips}..."
|
| 894 |
+
|
| 895 |
+
if is_ytdlp_url(clip_url):
|
| 896 |
+
ydl_opts = {
|
| 897 |
+
"format": "bestvideo[height<=1920]+bestaudio/best",
|
| 898 |
+
"merge_output_format": "mp4",
|
| 899 |
+
"outtmpl": raw_clip_path,
|
| 900 |
+
"quiet": True,
|
| 901 |
+
"no_warnings": True,
|
| 902 |
+
}
|
| 903 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 904 |
+
ydl.download([clip_url])
|
| 905 |
+
else:
|
| 906 |
+
direct_u = resolve_download_url(clip_url)
|
| 907 |
+
headers = {"User-Agent": "Mozilla/5.0"}
|
| 908 |
+
with requests.get(direct_u, headers=headers, stream=True, timeout=60, allow_redirects=True) as r:
|
| 909 |
+
r.raise_for_status()
|
| 910 |
+
with open(raw_clip_path, "wb") as f:
|
| 911 |
+
for chunk in r.iter_content(chunk_size=1024 * 1024):
|
| 912 |
+
if job.get("cancelled"):
|
| 913 |
+
raise InterruptedError("Cancelado por el usuario")
|
| 914 |
+
if chunk:
|
| 915 |
+
f.write(chunk)
|
| 916 |
+
|
| 917 |
+
if not os.path.exists(raw_clip_path):
|
| 918 |
+
# yt-dlp puede haber guardado con otra extensión si falló el merge
|
| 919 |
+
candidates = [os.path.join(job_dir, fn) for fn in os.listdir(job_dir) if fn.startswith(f"raw_clip_{idx:03d}.")]
|
| 920 |
+
if candidates:
|
| 921 |
+
raw_clip_path = candidates[0]
|
| 922 |
+
else:
|
| 923 |
+
raise RuntimeError(f"No se pudo descargar el video {idx}/{total_clips}")
|
| 924 |
+
|
| 925 |
+
# Medir duración exacta con ffprobe para recortar los últimos segundos (ej: 16s de Betano)
|
| 926 |
+
clip_dur = 0.0
|
| 927 |
+
try:
|
| 928 |
+
pr = subprocess.run(
|
| 929 |
+
[ffprobe_bin, "-v", "error", "-show_entries", "format=duration", "-of", "default=noprint_wrappers=1:nokey=1", raw_clip_path],
|
| 930 |
+
capture_output=True, text=True, timeout=15
|
| 931 |
+
)
|
| 932 |
+
if pr.returncode == 0 and pr.stdout.strip():
|
| 933 |
+
clip_dur = float(pr.stdout.strip())
|
| 934 |
+
except Exception:
|
| 935 |
+
clip_dur = 0.0
|
| 936 |
+
|
| 937 |
+
trim_args = []
|
| 938 |
+
if trim_end_sec > 0 and clip_dur > (trim_end_sec + 4.0):
|
| 939 |
+
keep_dur = max(1.0, clip_dur - trim_end_sec)
|
| 940 |
+
trim_args = ["-t", f"{keep_dur:.2f}"]
|
| 941 |
+
|
| 942 |
+
if vertical_to_horiz:
|
| 943 |
+
if remove_subtitles:
|
| 944 |
+
# Corta justo por encima de los subtítulos (ih*0.54 desde ih*0.12) y elimina logo superior
|
| 945 |
+
fg_crop = "crop=iw:ih*0.54:0:ih*0.12,scale=640:720:flags=lanczos,setsar=1"
|
| 946 |
+
else:
|
| 947 |
+
# Mantiene los subtítulos inferiores (V3 600x720)
|
| 948 |
+
fg_crop = "crop=iw:ih*0.68:0:ih*0.12,scale=600:720:flags=lanczos,setsar=1"
|
| 949 |
+
|
| 950 |
+
vf_str = (
|
| 951 |
+
"[0:v]split[bg][fg];"
|
| 952 |
+
"[bg]scale=1280:720:force_original_aspect_ratio=increase,crop=1280:720,boxblur=30:8,eq=brightness=-0.10:saturation=1.15[bg_blur];"
|
| 953 |
+
f"[fg]{fg_crop}[fg_wide];"
|
| 954 |
+
"[bg_blur][fg_wide]overlay=(W-w)/2:0,fps=25,setsar=1,setdar=16/9"
|
| 955 |
+
)
|
| 956 |
+
job["status"] = f"🎬 Convirtiendo a Horizontal TV ({idx}/{total_clips}){' sin subtítulos ni publicidad' if (remove_subtitles and trim_end_sec > 0) else ''}..."
|
| 957 |
+
else:
|
| 958 |
+
vf_str = "scale=1280:720:force_original_aspect_ratio=decrease,pad=1280:720:(ow-iw)/2:(oh-ih)/2,fps=25,setsar=1,setdar=16/9"
|
| 959 |
+
job["status"] = f"🎬 Procesando video ({idx}/{total_clips})..."
|
| 960 |
+
|
| 961 |
+
seg_ts = os.path.join(job_dir, f"seg_{idx:03d}.ts")
|
| 962 |
+
cmd_seg = [
|
| 963 |
+
ffmpeg_bin, "-y", "-i", raw_clip_path,
|
| 964 |
+
*trim_args,
|
| 965 |
+
"-vf", vf_str,
|
| 966 |
+
"-c:v", "libx264", "-preset", "veryfast", "-crf", "22",
|
| 967 |
+
"-c:a", "aac", "-ar", "44100", "-ac", "2", "-b:a", "128k",
|
| 968 |
+
"-f", "mpegts", seg_ts
|
| 969 |
+
]
|
| 970 |
+
res_seg = subprocess.run(cmd_seg, capture_output=True, text=True)
|
| 971 |
+
try:
|
| 972 |
+
os.remove(raw_clip_path)
|
| 973 |
+
except Exception:
|
| 974 |
+
pass
|
| 975 |
+
|
| 976 |
+
if res_seg.returncode != 0 or not os.path.exists(seg_ts):
|
| 977 |
+
raise RuntimeError(f"Error procesando video {idx}: {(res_seg.stderr or '')[-160:]}")
|
| 978 |
+
|
| 979 |
+
ts_segments.append(seg_ts)
|
| 980 |
+
|
| 981 |
+
job["progress"] = 70
|
| 982 |
+
job["status"] = f"🔗 Uniendo {len(ts_segments)} capítulo(s) en 1 solo MP4 continuo..."
|
| 983 |
+
concat_txt = os.path.join(job_dir, "concat_list.txt")
|
| 984 |
+
with open(concat_txt, "w", encoding="utf-8") as f_cat:
|
| 985 |
+
for seg_p in ts_segments:
|
| 986 |
+
safe_p = seg_p.replace("\\", "/")
|
| 987 |
+
f_cat.write(f"file '{safe_p}'\n")
|
| 988 |
+
|
| 989 |
+
final_mp4 = os.path.join(job_dir, "vertical_merged_tv.mp4")
|
| 990 |
+
cmd_join = [
|
| 991 |
+
ffmpeg_bin, "-y", "-f", "concat", "-safe", "0",
|
| 992 |
+
"-i", concat_txt,
|
| 993 |
+
"-c", "copy",
|
| 994 |
+
"-bsf:a", "aac_adtstoasc",
|
| 995 |
+
"-movflags", "+faststart",
|
| 996 |
+
final_mp4
|
| 997 |
+
]
|
| 998 |
+
res_join = subprocess.run(cmd_join, capture_output=True, text=True)
|
| 999 |
+
for seg_p in ts_segments:
|
| 1000 |
+
try:
|
| 1001 |
+
os.remove(seg_p)
|
| 1002 |
+
except Exception:
|
| 1003 |
+
pass
|
| 1004 |
+
|
| 1005 |
+
if res_join.returncode != 0 or not os.path.exists(final_mp4):
|
| 1006 |
+
raise RuntimeError(f"Error uniendo capítulos: {(res_join.stderr or '')[-160:]}")
|
| 1007 |
+
|
| 1008 |
+
return remux_video_to_latino_mp4(final_mp4, job_dir, job)
|
| 1009 |
+
|
| 1010 |
+
|
| 1011 |
def remux_video_to_latino_mp4(video_path, job_dir, job):
|
| 1012 |
ext = os.path.splitext(video_path)[1].lower()
|
| 1013 |
orig_size = os.path.getsize(video_path)
|
|
|
|
| 1129 |
if p_info:
|
| 1130 |
# Ruta A: Descarga desde PelixPlay (16 hilos HLS + limpieza PNG + remux MP4)
|
| 1131 |
target_video_path = download_pelixplay_to_mp4(job, p_info, job_dir)
|
| 1132 |
+
elif (
|
| 1133 |
+
is_ytdlp_url(job["source_url"])
|
| 1134 |
+
or job.get("vertical_to_horiz")
|
| 1135 |
+
or job.get("merge_clips")
|
| 1136 |
+
or float(job.get("trim_end_sec") or 0) > 0
|
| 1137 |
+
):
|
| 1138 |
+
# Ruta C: Series Verticales / YouTube / Microseries (16:9 TV + sin subtítulos + corte de últimos seg + unión en 1 archivo)
|
| 1139 |
+
target_video_path = download_and_process_vertical_or_ytdlp(job, job_dir)
|
| 1140 |
else:
|
| 1141 |
# Ruta B: Descarga desde MediaFire / LatinoMegaHD / Directo (.rar, .part1.rar, .zip, .mkv, .mp4)
|
| 1142 |
source_urls = job.get("source_urls") or [job["source_url"]]
|
|
|
|
| 1457 |
except Exception as e:
|
| 1458 |
return jsonify({"success": False, "message": str(e)})
|
| 1459 |
|
| 1460 |
+
if is_ytdlp_url(url):
|
| 1461 |
+
try:
|
| 1462 |
+
yt_info = extract_ytdlp_info(url)
|
| 1463 |
+
return jsonify({"success": True, "source": "youtube", **yt_info})
|
| 1464 |
+
except Exception as e:
|
| 1465 |
+
return jsonify({"success": False, "message": str(e)})
|
| 1466 |
+
|
| 1467 |
p_info = parse_pelixplay_url(url)
|
| 1468 |
if not p_info:
|
| 1469 |
return jsonify({"success": False})
|
|
|
|
| 1485 |
episode_start = (data.get("episode_name") or "Capitulo 01").strip()
|
| 1486 |
dataset_repo = (data.get("dataset_repo") or CATALOG.get("dataset_repo") or DEFAULT_DATASET_REPO).strip()
|
| 1487 |
|
| 1488 |
+
vertical_to_horiz = bool(data.get("vertical_to_horiz"))
|
| 1489 |
+
remove_subtitles = bool(data.get("remove_subtitles", True))
|
| 1490 |
+
merge_clips = bool(data.get("merge_clips"))
|
| 1491 |
+
trim_end_raw = str(data.get("trim_end_sec") or "").strip().replace(",", ".")
|
| 1492 |
+
try:
|
| 1493 |
+
trim_end_sec = max(0.0, float(trim_end_raw)) if trim_end_raw else 0.0
|
| 1494 |
+
except Exception:
|
| 1495 |
+
trim_end_sec = 0.0
|
| 1496 |
+
|
| 1497 |
urls = extract_urls_from_text(raw_urls)
|
| 1498 |
if not urls:
|
| 1499 |
return jsonify({"success": False, "message": "Pegá al menos un enlace válido."}), 400
|
| 1500 |
|
| 1501 |
+
# Si es una Playlist o video de YouTube / Serie Vertical, extraer lista de capítulos y metadatos
|
| 1502 |
+
if is_ytdlp_url(urls[0]):
|
| 1503 |
+
try:
|
| 1504 |
+
if len(urls) == 1:
|
| 1505 |
+
yt_info = extract_ytdlp_info(urls[0])
|
| 1506 |
+
if not title and yt_info.get("title"):
|
| 1507 |
+
title = yt_info["title"]
|
| 1508 |
+
if not poster_url and yt_info.get("poster"):
|
| 1509 |
+
poster_url = yt_info["poster"]
|
| 1510 |
+
if yt_info.get("video_urls") and len(yt_info["video_urls"]) > 1:
|
| 1511 |
+
urls = yt_info["video_urls"]
|
| 1512 |
+
except Exception as e:
|
| 1513 |
+
print(f"Aviso leyendo YouTube meta: {e}")
|
| 1514 |
+
|
| 1515 |
# Si es un enlace de LatinoMegaHD, extraer automáticamente los enlaces MediaFire internos y metadatos
|
| 1516 |
is_lmhd = is_latinomegahd_url(urls[0])
|
| 1517 |
lm_movie_multipart = False
|
|
|
|
| 1576 |
if hits:
|
| 1577 |
poster_url = hits[0]["poster"]
|
| 1578 |
|
| 1579 |
+
# Si tildaron "Unir todos los capítulos en 1 solo video continuo" (ej: Microseries verticales), agrupar todo en 1 único Job
|
| 1580 |
+
if merge_clips and len(urls) > 1:
|
| 1581 |
+
ep_label = episode_start if content_type == "serie" else ""
|
| 1582 |
+
if content_type == "serie" and re.match(r"^\d+\s*-\s*\d+$", ep_label):
|
| 1583 |
+
ep_label = "Capitulo 01 (Temporada Completa)"
|
| 1584 |
+
job = {
|
| 1585 |
+
"id": str(uuid.uuid4())[:8],
|
| 1586 |
+
"content_type": content_type,
|
| 1587 |
+
"source_url": urls[0],
|
| 1588 |
+
"source_urls": urls,
|
| 1589 |
+
"title": title,
|
| 1590 |
+
"display_label": f"{title} ({len(urls)} caps unidos en 1 video continuo)",
|
| 1591 |
+
"poster_url": poster_url,
|
| 1592 |
+
"rar_password": rar_password,
|
| 1593 |
+
"season_name": season_name,
|
| 1594 |
+
"episode_name": ep_label or "Capitulo 01 (Temporada Completa)",
|
| 1595 |
+
"dataset_repo": dataset_repo,
|
| 1596 |
+
"vertical_to_horiz": vertical_to_horiz,
|
| 1597 |
+
"remove_subtitles": remove_subtitles,
|
| 1598 |
+
"merge_clips": True,
|
| 1599 |
+
"trim_end_sec": trim_end_sec,
|
| 1600 |
+
"state": "queued",
|
| 1601 |
+
"status": f"En cola ({len(urls)} capítulos para unir en 1 solo video)...",
|
| 1602 |
+
"progress": 0,
|
| 1603 |
+
"created_at": time.strftime("%H:%M:%S")
|
| 1604 |
+
}
|
| 1605 |
+
with STATE_LOCK:
|
| 1606 |
+
JOBS.insert(0, job)
|
| 1607 |
+
start_worker_if_needed()
|
| 1608 |
+
return jsonify({"success": True, "jobs": [job]})
|
| 1609 |
+
|
| 1610 |
# Si es Película y pegaron varias partes (.part1.rar, .part2.rar) o viene de LatinoMegaHD, agrupar en 1 solo Job
|
| 1611 |
if content_type == "movie" and len(urls) > 1 and (lm_movie_multipart or any(".part" in u.lower() for u in urls)):
|
| 1612 |
job = {
|
|
|
|
| 1621 |
"season_name": season_name,
|
| 1622 |
"episode_name": "",
|
| 1623 |
"dataset_repo": dataset_repo,
|
| 1624 |
+
"vertical_to_horiz": vertical_to_horiz,
|
| 1625 |
+
"remove_subtitles": remove_subtitles,
|
| 1626 |
+
"merge_clips": merge_clips,
|
| 1627 |
+
"trim_end_sec": trim_end_sec,
|
| 1628 |
"state": "queued",
|
| 1629 |
"status": f"En cola ({len(urls)} partes MediaFire)...",
|
| 1630 |
"progress": 0,
|
|
|
|
| 1680 |
"season_name": season_name,
|
| 1681 |
"episode_name": ep_label,
|
| 1682 |
"dataset_repo": dataset_repo,
|
| 1683 |
+
"vertical_to_horiz": vertical_to_horiz,
|
| 1684 |
+
"remove_subtitles": remove_subtitles,
|
| 1685 |
+
"merge_clips": merge_clips,
|
| 1686 |
+
"trim_end_sec": trim_end_sec,
|
| 1687 |
"state": "queued",
|
| 1688 |
"status": "En cola esperando turno...",
|
| 1689 |
"progress": 0,
|
|
|
|
| 2257 |
</div>
|
| 2258 |
</div>
|
| 2259 |
|
| 2260 |
+
<!-- Barra Especial para Series Verticales / Microseries / YouTube -->
|
| 2261 |
+
<div style="margin-top:16px; background:rgba(15, 23, 42, 0.75); border:1px solid #334155; border-radius:10px; padding:12px 16px; display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:14px;">
|
| 2262 |
+
<div style="display:flex; flex-wrap:wrap; align-items:center; gap:18px;">
|
| 2263 |
+
<span style="font-size:12.5px; font-weight:700; color:#a855f7;"><i class="fa-solid fa-mobile-screen-button"></i> Series Verticales / Microseries:</span>
|
| 2264 |
+
<label style="display:flex; align-items:center; gap:7px; font-size:12.5px; cursor:pointer;">
|
| 2265 |
+
<input type="checkbox" id="verticalToHoriz" style="width:16px; height:16px; accent-color:#a855f7;">
|
| 2266 |
+
<span>Convertir Vertical a Horizontal TV (16:9)</span>
|
| 2267 |
+
</label>
|
| 2268 |
+
<label style="display:flex; align-items:center; gap:7px; font-size:12.5px; cursor:pointer;">
|
| 2269 |
+
<input type="checkbox" id="removeSubtitles" checked style="width:16px; height:16px; accent-color:#a855f7;">
|
| 2270 |
+
<span>Quitar Subtítulos inferiores</span>
|
| 2271 |
+
</label>
|
| 2272 |
+
<label style="display:flex; align-items:center; gap:7px; font-size:12.5px; cursor:pointer;">
|
| 2273 |
+
<input type="checkbox" id="mergeClips" style="width:16px; height:16px; accent-color:#10b981;">
|
| 2274 |
+
<span style="color:#34d399; font-weight:600;">Unir todos los capítulos en 1 solo video continuo</span>
|
| 2275 |
+
</label>
|
| 2276 |
+
</div>
|
| 2277 |
+
<div style="display:flex; align-items:center; gap:8px;">
|
| 2278 |
+
<label for="trimEndSec" style="font-size:12px; color:#cbd5e1; white-space:nowrap;"><i class="fa-solid fa-scissors" style="color:#f43f5e;"></i> Cortar últimos seg. (Opcional):</label>
|
| 2279 |
+
<input type="number" id="trimEndSec" class="form-control" style="width:130px; padding:6px 10px; font-size:12.5px;" min="0" max="120" step="0.5" placeholder="Vacío = 0">
|
| 2280 |
+
</div>
|
| 2281 |
+
</div>
|
| 2282 |
+
|
| 2283 |
<!-- Barra de Póster Seleccionado -->
|
| 2284 |
<div class="selected-poster-bar" id="selectedPosterBar">
|
| 2285 |
<img id="posterPreviewImg" src="" alt="Poster">
|
|
|
|
| 2400 |
|
| 2401 |
async function onUrlInputChanged() {
|
| 2402 |
const val = document.getElementById('downloadUrls').value.trim();
|
| 2403 |
+
const isYt = val.includes('youtube.com/') || val.includes('youtu.be/') || val.includes('tiktok.com/');
|
| 2404 |
+
if ((val.includes('pelixplay.app') || val.includes('latinomegahd.') || isYt) && val !== lastDetectedPelixUrl) {
|
| 2405 |
lastDetectedPelixUrl = val;
|
| 2406 |
const badge = document.getElementById('autoFillBadge');
|
| 2407 |
if (badge) {
|
|
|
|
| 2417 |
badge.style.display = 'inline';
|
| 2418 |
if (data.source === 'latinomegahd') {
|
| 2419 |
badge.textContent = `(✨ LatinoMegaHD: ${data.mf_count || 1} link(s) MediaFire listos sin publicidad)`;
|
| 2420 |
+
} else if (data.source === 'youtube') {
|
| 2421 |
+
badge.textContent = `(✨ Serie Vertical detectada: ${data.ep_count || 1} capítulo(s) listos para unir en 16:9)`;
|
| 2422 |
} else {
|
| 2423 |
badge.textContent = '(✨ Autocompletado de PelixPlay)';
|
| 2424 |
}
|
|
|
|
| 2436 |
document.getElementById('contentType').value = data.content_type;
|
| 2437 |
toggleTypeFields();
|
| 2438 |
}
|
| 2439 |
+
if (data.vertical_to_horiz !== undefined) {
|
| 2440 |
+
document.getElementById('verticalToHoriz').checked = !!data.vertical_to_horiz;
|
| 2441 |
+
}
|
| 2442 |
+
if (data.remove_subtitles !== undefined) {
|
| 2443 |
+
document.getElementById('removeSubtitles').checked = !!data.remove_subtitles;
|
| 2444 |
+
}
|
| 2445 |
+
if (data.merge_clips !== undefined) {
|
| 2446 |
+
document.getElementById('mergeClips').checked = !!data.merge_clips;
|
| 2447 |
+
}
|
| 2448 |
+
if (data.trim_end_sec !== undefined) {
|
| 2449 |
+
document.getElementById('trimEndSec').value = data.trim_end_sec;
|
| 2450 |
+
}
|
| 2451 |
if (data.poster) {
|
| 2452 |
selectPoster(data.poster, data.title, true);
|
| 2453 |
}
|
|
|
|
| 2515 |
const season_name = document.getElementById('seasonName').value.trim();
|
| 2516 |
const episode_name = document.getElementById('episodeName').value.trim();
|
| 2517 |
const dataset_repo = document.getElementById('datasetRepoInput').value.trim();
|
| 2518 |
+
const vertical_to_horiz = document.getElementById('verticalToHoriz').checked;
|
| 2519 |
+
const remove_subtitles = document.getElementById('removeSubtitles').checked;
|
| 2520 |
+
const merge_clips = document.getElementById('mergeClips').checked;
|
| 2521 |
+
const trim_end_sec = document.getElementById('trimEndSec').value.trim();
|
| 2522 |
|
| 2523 |
if (!urls) {
|
| 2524 |
+
alert('Pegá el enlace de PelixPlay, LatinoMegaHD, YouTube o MediaFire.');
|
| 2525 |
return;
|
| 2526 |
}
|
| 2527 |
|
|
|
|
| 2530 |
headers: {'Content-Type': 'application/json'},
|
| 2531 |
body: JSON.stringify({
|
| 2532 |
content_type, urls, title, poster_url,
|
| 2533 |
+
rar_password, season_name, episode_name, dataset_repo,
|
| 2534 |
+
vertical_to_horiz, remove_subtitles, merge_clips, trim_end_sec
|
| 2535 |
})
|
| 2536 |
});
|
| 2537 |
const data = await res.json();
|