Upload 5 files
Browse files- .gitattributes +3 -0
- videos/converter_gui.py +972 -0
- videos/ffmpeg.exe +3 -0
- videos/ffplay.exe +3 -0
- videos/ffprobe.exe +3 -0
- videos/video_converter_gui_linux.py +619 -0
.gitattributes
CHANGED
|
@@ -156,3 +156,6 @@ videos/162236/162236_audio_1.mp4 filter=lfs diff=lfs merge=lfs -text
|
|
| 156 |
videos/201383/201383_all_audio.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 157 |
videos/201383/201383_audio_1.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 158 |
videos/vlc-3.0.23-win64.exe filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
videos/201383/201383_all_audio.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 157 |
videos/201383/201383_audio_1.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 158 |
videos/vlc-3.0.23-win64.exe filter=lfs diff=lfs merge=lfs -text
|
| 159 |
+
videos/ffmpeg.exe filter=lfs diff=lfs merge=lfs -text
|
| 160 |
+
videos/ffplay.exe filter=lfs diff=lfs merge=lfs -text
|
| 161 |
+
videos/ffprobe.exe filter=lfs diff=lfs merge=lfs -text
|
videos/converter_gui.py
ADDED
|
@@ -0,0 +1,972 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import re
|
| 4 |
+
import json
|
| 5 |
+
import shutil
|
| 6 |
+
import subprocess
|
| 7 |
+
import tempfile
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from urllib.parse import urlparse, unquote
|
| 10 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
from PyQt6.QtWidgets import (
|
| 14 |
+
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
| 15 |
+
QLabel, QLineEdit, QTextEdit, QPushButton, QFileDialog, QComboBox,
|
| 16 |
+
QCheckBox, QSpinBox, QSlider, QGroupBox, QRadioButton, QButtonGroup,
|
| 17 |
+
QSplitter, QFrame, QScrollArea, QProgressBar, QTabWidget, QSizePolicy
|
| 18 |
+
)
|
| 19 |
+
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QObject
|
| 20 |
+
from PyQt6.QtGui import QFont, QColor, QPalette, QIcon, QTextCursor
|
| 21 |
+
PYQT_VERSION = 6
|
| 22 |
+
except ImportError:
|
| 23 |
+
try:
|
| 24 |
+
from PyQt5.QtWidgets import (
|
| 25 |
+
QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
|
| 26 |
+
QLabel, QLineEdit, QTextEdit, QPushButton, QFileDialog, QComboBox,
|
| 27 |
+
QCheckBox, QSpinBox, QSlider, QGroupBox, QRadioButton, QButtonGroup,
|
| 28 |
+
QSplitter, QFrame, QScrollArea, QProgressBar, QTabWidget, QSizePolicy
|
| 29 |
+
)
|
| 30 |
+
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QObject
|
| 31 |
+
from PyQt5.QtGui import QFont, QColor, QPalette, QIcon, QTextCursor
|
| 32 |
+
PYQT_VERSION = 5
|
| 33 |
+
except ImportError:
|
| 34 |
+
print("Error: Instala PyQt6 o PyQt5: pip install PyQt6")
|
| 35 |
+
sys.exit(1)
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
import requests
|
| 39 |
+
except ImportError:
|
| 40 |
+
print("Error: Instala requests: pip install requests")
|
| 41 |
+
sys.exit(1)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
# ─── Configuración RAM Disk y CPU ────────────────────────────────────────────
|
| 45 |
+
|
| 46 |
+
def setup_ramdisk():
|
| 47 |
+
try:
|
| 48 |
+
p = Path("/dev/shm/video_processing")
|
| 49 |
+
p.mkdir(exist_ok=True, parents=True)
|
| 50 |
+
return p
|
| 51 |
+
except Exception:
|
| 52 |
+
p = Path("/tmp/video_processing")
|
| 53 |
+
p.mkdir(exist_ok=True)
|
| 54 |
+
return p
|
| 55 |
+
|
| 56 |
+
def get_optimal_threads():
|
| 57 |
+
try:
|
| 58 |
+
return max(len(os.sched_getaffinity(0)) - 1, 1)
|
| 59 |
+
except Exception:
|
| 60 |
+
return max((os.cpu_count() or 4) - 1, 1)
|
| 61 |
+
|
| 62 |
+
RAMDISK_PATH = setup_ramdisk()
|
| 63 |
+
OPTIMAL_THREADS = get_optimal_threads()
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# ─── Utilidades FFmpeg / Git ──────────────────────────────────────────────────
|
| 67 |
+
|
| 68 |
+
def is_live_stream(url: str) -> bool:
|
| 69 |
+
if not url.startswith(("http://", "https://")):
|
| 70 |
+
return False
|
| 71 |
+
low = url.lower()
|
| 72 |
+
if any(low.endswith(e) for e in [".mp4", ".mkv", ".avi", ".mov", ".wmv", ".flv", ".webm", ".ts"]):
|
| 73 |
+
return False
|
| 74 |
+
return any(p in low for p in ["/live/", "/stream/", ".m3u8", ".mpd", "/hls/", "/dash/"])
|
| 75 |
+
|
| 76 |
+
def get_input_args(source: str) -> list:
|
| 77 |
+
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64)"
|
| 78 |
+
if source.startswith(("http://", "https://")):
|
| 79 |
+
if is_live_stream(source):
|
| 80 |
+
return ["-user_agent", ua, "-timeout", "10000000",
|
| 81 |
+
"-reconnect", "1", "-reconnect_streamed", "1",
|
| 82 |
+
"-reconnect_delay_max", "5", "-multiple_requests", "1",
|
| 83 |
+
"-fflags", "+fastseek+genpts", "-probesize", "50M", "-analyzeduration", "20M"]
|
| 84 |
+
return ["-user_agent", ua, "-timeout", "30000000",
|
| 85 |
+
"-reconnect", "1", "-reconnect_streamed", "1",
|
| 86 |
+
"-reconnect_delay_max", "5", "-analyzeduration", "200000000",
|
| 87 |
+
"-probesize", "200000000", "-fflags", "+genpts+igndts",
|
| 88 |
+
"-err_detect", "ignore_err", "-max_delay", "5000000", "-rw_timeout", "30000000"]
|
| 89 |
+
return ["-analyzeduration", "100000000", "-probesize", "100000000", "-fflags", "+genpts+igndts"]
|
| 90 |
+
|
| 91 |
+
def get_copy_args() -> list:
|
| 92 |
+
return ["-max_muxing_queue_size", "9999", "-avoid_negative_ts", "make_zero",
|
| 93 |
+
"-fflags", "+genpts+igndts+flush_packets", "-copytb", "1",
|
| 94 |
+
"-start_at_zero", "-threads", str(OPTIMAL_THREADS), "-thread_queue_size", "4096"]
|
| 95 |
+
|
| 96 |
+
def get_render_args() -> list:
|
| 97 |
+
return ["-threads", str(OPTIMAL_THREADS), "-thread_type", "slice+frame",
|
| 98 |
+
"-slices", str(OPTIMAL_THREADS), "-max_muxing_queue_size", "9999",
|
| 99 |
+
"-thread_queue_size", "4096"]
|
| 100 |
+
|
| 101 |
+
def clean_folder(name: str) -> str:
|
| 102 |
+
return re.sub(r'[<>:"/\\|?*]', "_", name).strip()[:200]
|
| 103 |
+
|
| 104 |
+
def clean_repo(name: str) -> str:
|
| 105 |
+
name = re.sub(r"[^a-zA-Z0-9_-]", "-", name)
|
| 106 |
+
return re.sub(r"-+", "-", name).strip("-")[:100]
|
| 107 |
+
|
| 108 |
+
def build_name(content_type, movie_name, serie_name, season, ep_start, ep_index):
|
| 109 |
+
if content_type == "movie":
|
| 110 |
+
base = movie_name.strip() or "Pelicula"
|
| 111 |
+
return clean_folder(base), clean_repo(base)
|
| 112 |
+
name = serie_name.strip() or "Serie"
|
| 113 |
+
try: season_n = int(season)
|
| 114 |
+
except: season_n = 1
|
| 115 |
+
try: ep_num = int(ep_start) + ep_index
|
| 116 |
+
except: ep_num = ep_index + 1
|
| 117 |
+
label = f"{name}_Temporada{season_n}_Ep{ep_num}"
|
| 118 |
+
return clean_folder(label), clean_repo(label)
|
| 119 |
+
|
| 120 |
+
def detect_duration(source, input_args):
|
| 121 |
+
cmd = ["ffprobe", "-v", "error"] + input_args + [
|
| 122 |
+
"-show_entries", "format=duration", "-of", "json", "-i", source]
|
| 123 |
+
try:
|
| 124 |
+
r = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
| 125 |
+
d = json.loads(r.stdout).get("format", {}).get("duration")
|
| 126 |
+
return float(d) if d and d != "N/A" else None
|
| 127 |
+
except Exception:
|
| 128 |
+
return None
|
| 129 |
+
|
| 130 |
+
def detect_audio_streams(source, input_args):
|
| 131 |
+
cmd = ["ffprobe", "-v", "error"] + input_args + [
|
| 132 |
+
"-select_streams", "a",
|
| 133 |
+
"-show_entries", "stream=index,codec_name:stream_tags=language,title",
|
| 134 |
+
"-of", "json", "-i", source]
|
| 135 |
+
try:
|
| 136 |
+
r = subprocess.run(cmd, capture_output=True, text=True, timeout=120)
|
| 137 |
+
tracks = []
|
| 138 |
+
for s in json.loads(r.stdout).get("streams", []):
|
| 139 |
+
tags = s.get("tags", {})
|
| 140 |
+
tracks.append({"index": s.get("index", 0),
|
| 141 |
+
"language": tags.get("language", "und").lower(),
|
| 142 |
+
"title": tags.get("title", f"Audio {s.get('index',0)}"),
|
| 143 |
+
"codec": s.get("codec_name", "unknown")})
|
| 144 |
+
return tracks
|
| 145 |
+
except Exception:
|
| 146 |
+
return []
|
| 147 |
+
|
| 148 |
+
def prioritize_audio(tracks):
|
| 149 |
+
pri = ["spa", "es", "spanish", "español", "latino", "lat", "es-mx", "es-419"]
|
| 150 |
+
def key(t):
|
| 151 |
+
lang, title = t["language"].lower(), t["title"].lower()
|
| 152 |
+
for p in pri:
|
| 153 |
+
if p in lang or p in title:
|
| 154 |
+
return 0
|
| 155 |
+
return 1 if lang == "und" else 2
|
| 156 |
+
return sorted(tracks, key=key)
|
| 157 |
+
|
| 158 |
+
def create_master_m3u8(output_dir, video_streams, audio_playlists):
|
| 159 |
+
lines = ["#EXTM3U", "#EXT-X-VERSION:7", ""]
|
| 160 |
+
for a in audio_playlists:
|
| 161 |
+
d = "YES" if a["is_default"] else "NO"
|
| 162 |
+
lines.append(f'#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",NAME="{a["title"]}",'
|
| 163 |
+
f'LANGUAGE="{a["language"]}",DEFAULT={d},AUTOSELECT={d},URI="{a["file"]}"')
|
| 164 |
+
lines.append("")
|
| 165 |
+
for v in video_streams:
|
| 166 |
+
lines.append(f'#EXT-X-STREAM-INF:BANDWIDTH={v["bandwidth"]},'
|
| 167 |
+
f'RESOLUTION={v["resolution"]},CODECS="{v["codecs"]}",AUDIO="audio"')
|
| 168 |
+
lines.append(v["file"])
|
| 169 |
+
(output_dir / "master.m3u8").write_text("\n".join(lines))
|
| 170 |
+
|
| 171 |
+
def clone_m3u8(src: Path, dst: Path):
|
| 172 |
+
dst.write_text(src.read_text())
|
| 173 |
+
|
| 174 |
+
def process_audio_track(args):
|
| 175 |
+
track, i, total, source, output_dir, input_args = args
|
| 176 |
+
temp = RAMDISK_PATH / f"audio_{os.getpid()}_{i}"
|
| 177 |
+
temp.mkdir(exist_ok=True)
|
| 178 |
+
audio_m3u8 = temp / f"audio_{i}.m3u8"
|
| 179 |
+
seg = temp / f"audio_{i}_%03d.ts"
|
| 180 |
+
cmd = (["ffmpeg", "-hide_banner", "-threads", str(OPTIMAL_THREADS)]
|
| 181 |
+
+ input_args
|
| 182 |
+
+ ["-i", source, "-map", f"0:{track['index']}",
|
| 183 |
+
"-c:a", "libmp3lame", "-b:a", "192k", "-ar", "48000", "-ac", "2",
|
| 184 |
+
"-compression_level", "0",
|
| 185 |
+
"-threads", str(OPTIMAL_THREADS), "-max_muxing_queue_size", "9999",
|
| 186 |
+
"-thread_queue_size", "4096",
|
| 187 |
+
"-hls_time", "5", "-hls_list_size", "0",
|
| 188 |
+
"-hls_segment_filename", str(seg),
|
| 189 |
+
"-hls_flags", "independent_segments+append_list+temp_file",
|
| 190 |
+
"-hls_playlist_type", "vod", "-hls_segment_type", "mpegts",
|
| 191 |
+
str(audio_m3u8), "-y", "-loglevel", "warning"])
|
| 192 |
+
try:
|
| 193 |
+
r = subprocess.run(cmd, capture_output=True, text=True, timeout=7200)
|
| 194 |
+
if r.returncode != 0 or not audio_m3u8.exists():
|
| 195 |
+
shutil.rmtree(temp, ignore_errors=True)
|
| 196 |
+
return {"success": False, "index": i, "error": r.stderr[-500:], "track": track}
|
| 197 |
+
ts_files = list(temp.glob(f"audio_{i}_*.ts"))
|
| 198 |
+
if not ts_files:
|
| 199 |
+
shutil.rmtree(temp, ignore_errors=True)
|
| 200 |
+
return {"success": False, "index": i, "error": "Sin segmentos TS", "track": track}
|
| 201 |
+
shutil.move(str(audio_m3u8), str(output_dir / f"audio_{i}.m3u8"))
|
| 202 |
+
for ts in ts_files:
|
| 203 |
+
shutil.move(str(ts), str(output_dir / ts.name))
|
| 204 |
+
shutil.rmtree(temp, ignore_errors=True)
|
| 205 |
+
return {"success": True, "index": i, "track": track, "segments": len(ts_files),
|
| 206 |
+
"playlist": {"file": f"audio_{i}.m3u8", "language": track["language"],
|
| 207 |
+
"title": track["title"], "is_default": i == 0}}
|
| 208 |
+
except Exception as e:
|
| 209 |
+
shutil.rmtree(temp, ignore_errors=True)
|
| 210 |
+
return {"success": False, "index": i, "error": str(e), "track": track}
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
# ─── Worker thread ────────────────────────────────────────────────────────────
|
| 214 |
+
|
| 215 |
+
class ConvertWorker(QObject):
|
| 216 |
+
log = pyqtSignal(str)
|
| 217 |
+
link = pyqtSignal(str)
|
| 218 |
+
done = pyqtSignal()
|
| 219 |
+
error = pyqtSignal(str)
|
| 220 |
+
progress = pyqtSignal(int)
|
| 221 |
+
|
| 222 |
+
def __init__(self, params: dict):
|
| 223 |
+
super().__init__()
|
| 224 |
+
self.params = params
|
| 225 |
+
self._abort = False
|
| 226 |
+
|
| 227 |
+
def abort(self):
|
| 228 |
+
self._abort = True
|
| 229 |
+
|
| 230 |
+
def run(self):
|
| 231 |
+
p = self.params
|
| 232 |
+
token = p["token"]
|
| 233 |
+
sources = p["sources"]
|
| 234 |
+
conv_option = p["conv_option"]
|
| 235 |
+
stream_fmt = p["stream_fmt"]
|
| 236 |
+
batch_size = p["batch_size"]
|
| 237 |
+
delete_local = p["delete_local"]
|
| 238 |
+
max_workers = p["max_workers"]
|
| 239 |
+
content_type = p["content_type"]
|
| 240 |
+
movie_name = p["movie_name"]
|
| 241 |
+
serie_name = p["serie_name"]
|
| 242 |
+
season = p["season"]
|
| 243 |
+
ep_start = p["ep_start"]
|
| 244 |
+
|
| 245 |
+
self.log.emit(f"🚀 Iniciando v4.5-FIXED | CPU: {OPTIMAL_THREADS} hilos | RAM: {RAMDISK_PATH}")
|
| 246 |
+
|
| 247 |
+
try:
|
| 248 |
+
if not token:
|
| 249 |
+
raise Exception("Se requiere un Token de GitHub.")
|
| 250 |
+
if not sources:
|
| 251 |
+
raise Exception("Agrega archivos o URLs.")
|
| 252 |
+
|
| 253 |
+
total = len(sources)
|
| 254 |
+
all_links = []
|
| 255 |
+
|
| 256 |
+
for idx, source in enumerate(sources):
|
| 257 |
+
if self._abort:
|
| 258 |
+
self.log.emit("⛔ Proceso cancelado.")
|
| 259 |
+
break
|
| 260 |
+
|
| 261 |
+
src_type = source["type"]
|
| 262 |
+
src_val = source["value"]
|
| 263 |
+
folder_name, repo_name = build_name(
|
| 264 |
+
content_type, movie_name, serie_name, season, ep_start, idx)
|
| 265 |
+
|
| 266 |
+
self.log.emit(f"\n📦 [{idx+1}/{total}] {folder_name}")
|
| 267 |
+
self.log.emit(f" Tipo: {'📁 Archivo' if src_type=='file' else '🌐 URL'}")
|
| 268 |
+
|
| 269 |
+
input_args = get_input_args(src_val)
|
| 270 |
+
|
| 271 |
+
# Duración
|
| 272 |
+
dur = detect_duration(src_val, input_args)
|
| 273 |
+
if dur:
|
| 274 |
+
h, m, s = int(dur//3600), int((dur%3600)//60), int(dur%60)
|
| 275 |
+
self.log.emit(f" ✅ Duración: {h:02d}:{m:02d}:{s:02d}")
|
| 276 |
+
else:
|
| 277 |
+
self.log.emit(" ⚠️ No se detectó duración")
|
| 278 |
+
|
| 279 |
+
base_dir = Path(src_val).parent if src_type == "file" else Path.cwd()
|
| 280 |
+
output_dir = base_dir / folder_name
|
| 281 |
+
output_dir.mkdir(exist_ok=True)
|
| 282 |
+
|
| 283 |
+
# Audio
|
| 284 |
+
tracks = detect_audio_streams(src_val, input_args)
|
| 285 |
+
if not tracks:
|
| 286 |
+
tracks = [{"index": 0, "language": "und", "title": "Audio", "codec": "unknown"}]
|
| 287 |
+
tracks = prioritize_audio(tracks)
|
| 288 |
+
self.log.emit(f" 🎵 {len(tracks)} audio stream(s) detectados")
|
| 289 |
+
|
| 290 |
+
manifest_file = ""
|
| 291 |
+
|
| 292 |
+
# ── HLS ──────────────────────────────────────────────────────
|
| 293 |
+
if stream_fmt == "HLS (M3U8)":
|
| 294 |
+
self.log.emit(" 🎵 Procesando audios en paralelo (MP3 192k)...")
|
| 295 |
+
audio_args = [
|
| 296 |
+
(t, i, len(tracks), src_val, output_dir, input_args)
|
| 297 |
+
for i, t in enumerate(tracks)
|
| 298 |
+
]
|
| 299 |
+
audio_playlists = []
|
| 300 |
+
with ThreadPoolExecutor(max_workers=max_workers) as ex:
|
| 301 |
+
futures = {ex.submit(process_audio_track, a): a for a in audio_args}
|
| 302 |
+
for fut in as_completed(futures):
|
| 303 |
+
res = fut.result()
|
| 304 |
+
if res["success"]:
|
| 305 |
+
audio_playlists.append(res["playlist"])
|
| 306 |
+
self.log.emit(f" ✅ Audio {res['index']+1}: {res['track']['title']} ({res['segments']} segs)")
|
| 307 |
+
else:
|
| 308 |
+
self.log.emit(f" ❌ Audio {res['index']+1} error: {res.get('error','?')[:80]}")
|
| 309 |
+
|
| 310 |
+
audio_playlists.sort(key=lambda x: int(x["file"].split("_")[1].split(".")[0]))
|
| 311 |
+
if not audio_playlists:
|
| 312 |
+
raise Exception("No se procesó ningún audio.")
|
| 313 |
+
|
| 314 |
+
video_streams = []
|
| 315 |
+
|
| 316 |
+
if conv_option in ("copy1", "copy2"):
|
| 317 |
+
self.log.emit(" ⚡ Copy video (ultra rápido)...")
|
| 318 |
+
tmp = RAMDISK_PATH / f"video_{idx}"
|
| 319 |
+
tmp.mkdir(exist_ok=True)
|
| 320 |
+
v_m3u8 = tmp / "video_1080p.m3u8"
|
| 321 |
+
v_seg = tmp / "video_1080p_%03d.ts"
|
| 322 |
+
cmd = (["ffmpeg", "-hide_banner", "-threads", str(OPTIMAL_THREADS)]
|
| 323 |
+
+ input_args
|
| 324 |
+
+ ["-i", src_val, "-map", "0:v:0", "-c:v", "copy", "-an"]
|
| 325 |
+
+ get_copy_args()
|
| 326 |
+
+ ["-hls_time", "5", "-hls_list_size", "0",
|
| 327 |
+
"-hls_segment_filename", str(v_seg),
|
| 328 |
+
"-hls_flags", "independent_segments+append_list+temp_file",
|
| 329 |
+
"-hls_playlist_type", "vod", "-hls_segment_type", "mpegts",
|
| 330 |
+
str(v_m3u8), "-y", "-loglevel", "error"])
|
| 331 |
+
r = subprocess.run(cmd, capture_output=True, text=True, timeout=7200)
|
| 332 |
+
if r.returncode != 0:
|
| 333 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 334 |
+
raise Exception(f"FFmpeg copy error: {r.stderr[-400:]}")
|
| 335 |
+
final_1080 = output_dir / "video_1080p.m3u8"
|
| 336 |
+
shutil.move(str(v_m3u8), str(final_1080))
|
| 337 |
+
for ts in tmp.glob("video_1080p_*.ts"):
|
| 338 |
+
shutil.move(str(ts), str(output_dir / ts.name))
|
| 339 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 340 |
+
clone_m3u8(final_1080, output_dir / "video_720p.m3u8")
|
| 341 |
+
video_streams = [
|
| 342 |
+
{"file": "video_1080p.m3u8", "resolution": "1920x1080",
|
| 343 |
+
"bandwidth": 5000000, "codecs": "avc1.640028"},
|
| 344 |
+
{"file": "video_720p.m3u8", "resolution": "1280x720",
|
| 345 |
+
"bandwidth": 3000000, "codecs": "avc1.640028"},
|
| 346 |
+
]
|
| 347 |
+
self.log.emit(" ✅ Copy video OK")
|
| 348 |
+
|
| 349 |
+
elif conv_option in ("multi1080", "multi4k"):
|
| 350 |
+
res_list = (
|
| 351 |
+
[{"label": "1080p", "scale": "scale=-2:1080",
|
| 352 |
+
"bitrate": "5000k", "bufsize": "10000k", "res": "1920x1080"},
|
| 353 |
+
{"label": "720p", "scale": "scale=-2:720",
|
| 354 |
+
"bitrate": "2800k", "bufsize": "5600k", "res": "1280x720"}]
|
| 355 |
+
if conv_option == "multi1080" else
|
| 356 |
+
[{"label": "4K", "scale": "scale=-2:2160",
|
| 357 |
+
"bitrate": "15000k", "bufsize": "30000k", "res": "3840x2160"},
|
| 358 |
+
{"label": "1080p", "scale": "scale=-2:1080",
|
| 359 |
+
"bitrate": "5000k", "bufsize": "10000k", "res": "1920x1080"},
|
| 360 |
+
{"label": "720p", "scale": "scale=-2:720",
|
| 361 |
+
"bitrate": "2800k", "bufsize": "5600k", "res": "1280x720"}]
|
| 362 |
+
)
|
| 363 |
+
for rc in res_list:
|
| 364 |
+
self.log.emit(f" 🔄 Renderizando {rc['label']}...")
|
| 365 |
+
tmp = RAMDISK_PATH / f"render_{rc['label']}"
|
| 366 |
+
tmp.mkdir(exist_ok=True)
|
| 367 |
+
vf = tmp / f"video_{rc['label']}.m3u8"
|
| 368 |
+
vseg = tmp / f"video_{rc['label']}_%03d.ts"
|
| 369 |
+
cmd = (["ffmpeg", "-hide_banner", "-threads", str(OPTIMAL_THREADS)]
|
| 370 |
+
+ input_args
|
| 371 |
+
+ ["-i", src_val, "-map", "0:v:0", "-an",
|
| 372 |
+
"-c:v", "libx264", "-preset", "ultrafast", "-crf", "23",
|
| 373 |
+
"-vf", rc["scale"],
|
| 374 |
+
"-b:v", rc["bitrate"], "-maxrate", rc["bitrate"],
|
| 375 |
+
"-bufsize", rc["bufsize"], "-pix_fmt", "yuv420p"]
|
| 376 |
+
+ get_render_args()
|
| 377 |
+
+ ["-hls_time", "5", "-hls_list_size", "0",
|
| 378 |
+
"-hls_segment_filename", str(vseg),
|
| 379 |
+
"-hls_flags", "independent_segments+append_list+temp_file",
|
| 380 |
+
"-hls_playlist_type", "vod", "-hls_segment_type", "mpegts",
|
| 381 |
+
str(vf), "-y", "-loglevel", "error"])
|
| 382 |
+
r = subprocess.run(cmd, capture_output=True, text=True, timeout=14400)
|
| 383 |
+
if r.returncode != 0:
|
| 384 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 385 |
+
self.log.emit(f" ⚠️ Error {rc['label']}")
|
| 386 |
+
continue
|
| 387 |
+
fm = output_dir / f"video_{rc['label']}.m3u8"
|
| 388 |
+
shutil.move(str(vf), str(fm))
|
| 389 |
+
for ts in tmp.glob(f"video_{rc['label']}_*.ts"):
|
| 390 |
+
shutil.move(str(ts), str(output_dir / ts.name))
|
| 391 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 392 |
+
video_streams.append({
|
| 393 |
+
"file": f"video_{rc['label']}.m3u8",
|
| 394 |
+
"resolution": rc["res"],
|
| 395 |
+
"bandwidth": int(rc["bitrate"].replace("k","000")) + 192000,
|
| 396 |
+
"codecs": "avc1.640028"
|
| 397 |
+
})
|
| 398 |
+
self.log.emit(f" ✅ {rc['label']} OK")
|
| 399 |
+
|
| 400 |
+
if not video_streams:
|
| 401 |
+
raise Exception("No se generó video.")
|
| 402 |
+
create_master_m3u8(output_dir, video_streams, audio_playlists)
|
| 403 |
+
manifest_file = "master.m3u8"
|
| 404 |
+
|
| 405 |
+
# ── DASH ─────────────────────────────────────────────────────
|
| 406 |
+
else:
|
| 407 |
+
self.log.emit(" 🎬 Generando DASH en RAM...")
|
| 408 |
+
tmp_dash = RAMDISK_PATH / f"dash_{idx}"
|
| 409 |
+
tmp_dash.mkdir(exist_ok=True)
|
| 410 |
+
cmd = (["ffmpeg", "-hide_banner", "-threads", str(OPTIMAL_THREADS)]
|
| 411 |
+
+ input_args + ["-i", src_val])
|
| 412 |
+
is_copy = conv_option in ("copy1", "copy2")
|
| 413 |
+
extra = get_copy_args() if is_copy else get_render_args()
|
| 414 |
+
|
| 415 |
+
if is_copy:
|
| 416 |
+
cmd += ["-map", "0:v:0", "-c:v:0", "copy"]
|
| 417 |
+
elif conv_option in ("multi1080", "multi4k"):
|
| 418 |
+
rl = ([{"idx":0,"scale":"scale=-2:1080","br":"5000k"},
|
| 419 |
+
{"idx":1,"scale":"scale=-2:720", "br":"2800k"}]
|
| 420 |
+
if conv_option == "multi1080" else
|
| 421 |
+
[{"idx":0,"scale":"scale=-2:2160","br":"15000k"},
|
| 422 |
+
{"idx":1,"scale":"scale=-2:1080","br":"5000k"},
|
| 423 |
+
{"idx":2,"scale":"scale=-2:720", "br":"2800k"}])
|
| 424 |
+
for rc in rl:
|
| 425 |
+
cmd += ["-map", "0:v:0",
|
| 426 |
+
f"-c:v:{rc['idx']}", "libx264",
|
| 427 |
+
"-preset", "ultrafast", "-crf", "23",
|
| 428 |
+
f"-vf:v:{rc['idx']}", rc["scale"],
|
| 429 |
+
f"-b:v:{rc['idx']}", rc["br"],
|
| 430 |
+
"-maxrate", rc["br"]]
|
| 431 |
+
else:
|
| 432 |
+
cmd += ["-map", "0:v:0", "-c:v:0", "copy"]
|
| 433 |
+
|
| 434 |
+
for i, t in enumerate(tracks):
|
| 435 |
+
cmd += ["-map", f"0:{t['index']}",
|
| 436 |
+
f"-c:a:{i}", "aac", f"-b:a:{i}", "192k",
|
| 437 |
+
f"-ar:a:{i}", "48000", f"-ac:a:{i}", "2"]
|
| 438 |
+
|
| 439 |
+
mpd = tmp_dash / "manifest.mpd"
|
| 440 |
+
cmd += extra + [
|
| 441 |
+
"-f", "dash", "-seg_duration", "5",
|
| 442 |
+
"-use_template", "1", "-use_timeline", "0",
|
| 443 |
+
"-init_seg_name", "init-$RepresentationID$.m4s",
|
| 444 |
+
"-media_seg_name", "chunk-$RepresentationID$-$Number%05d$.m4s",
|
| 445 |
+
str(mpd), "-y", "-loglevel", "error"]
|
| 446 |
+
|
| 447 |
+
r = subprocess.run(cmd, capture_output=True, text=True, timeout=14400)
|
| 448 |
+
if r.returncode != 0:
|
| 449 |
+
shutil.rmtree(tmp_dash, ignore_errors=True)
|
| 450 |
+
raise Exception(f"DASH error: {r.stderr[-400:]}")
|
| 451 |
+
shutil.move(str(mpd), str(output_dir / "manifest.mpd"))
|
| 452 |
+
for m4s in tmp_dash.glob("*.m4s"):
|
| 453 |
+
shutil.move(str(m4s), str(output_dir / m4s.name))
|
| 454 |
+
shutil.rmtree(tmp_dash, ignore_errors=True)
|
| 455 |
+
self.log.emit(" ✅ DASH OK")
|
| 456 |
+
manifest_file = "manifest.mpd"
|
| 457 |
+
|
| 458 |
+
# ── GitHub upload ─────────────────────────────────────────────
|
| 459 |
+
self.log.emit(f" ☁️ Subiendo a GitHub: {repo_name}")
|
| 460 |
+
headers = {"Authorization": f"token {token}"}
|
| 461 |
+
resp = requests.post("https://api.github.com/user/repos",
|
| 462 |
+
headers=headers,
|
| 463 |
+
json={"name": repo_name, "private": True},
|
| 464 |
+
timeout=30)
|
| 465 |
+
if resp.status_code == 422:
|
| 466 |
+
u = requests.get("https://api.github.com/user", headers=headers)
|
| 467 |
+
username = u.json()["login"]
|
| 468 |
+
html_url = f"https://github.com/{username}/{repo_name}"
|
| 469 |
+
else:
|
| 470 |
+
html_url = resp.json()["html_url"]
|
| 471 |
+
|
| 472 |
+
repo_url = html_url.replace("https://", f"https://{token}@") + ".git"
|
| 473 |
+
git_dir = str(output_dir)
|
| 474 |
+
|
| 475 |
+
for gcmd in [
|
| 476 |
+
["git", "init"],
|
| 477 |
+
["git", "checkout", "-b", "main"],
|
| 478 |
+
["git", "remote", "add", "origin", repo_url],
|
| 479 |
+
["git", "config", "http.postBuffer", "524288000"],
|
| 480 |
+
["git", "config", "core.compression", "0"],
|
| 481 |
+
]:
|
| 482 |
+
subprocess.run(gcmd, cwd=git_dir, check=True,
|
| 483 |
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 484 |
+
|
| 485 |
+
files = os.listdir(git_dir)
|
| 486 |
+
ext_seg = ".m4s" if stream_fmt == "DASH (MPD)" else ".ts"
|
| 487 |
+
ext_man = ".mpd" if stream_fmt == "DASH (MPD)" else ".m3u8"
|
| 488 |
+
seg_files = [f for f in files if f.endswith(ext_seg)]
|
| 489 |
+
man_files = [f for f in files if f.endswith(ext_man)]
|
| 490 |
+
|
| 491 |
+
subprocess.run(["git", "add"] + man_files, cwd=git_dir,
|
| 492 |
+
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 493 |
+
subprocess.run(["git", "commit", "-m", f"Add {folder_name}"],
|
| 494 |
+
cwd=git_dir, check=True,
|
| 495 |
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 496 |
+
|
| 497 |
+
def push(cwd, force=False):
|
| 498 |
+
cmd_ = ["git", "push", "-u", "origin", "main"]
|
| 499 |
+
if force:
|
| 500 |
+
cmd_ = ["git", "push", "-f", "origin", "main"]
|
| 501 |
+
for _ in range(3):
|
| 502 |
+
try:
|
| 503 |
+
subprocess.run(cmd_, cwd=cwd, check=True,
|
| 504 |
+
stdout=subprocess.DEVNULL,
|
| 505 |
+
stderr=subprocess.PIPE, timeout=600)
|
| 506 |
+
return
|
| 507 |
+
except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
|
| 508 |
+
pass
|
| 509 |
+
raise Exception("Error al hacer push a GitHub")
|
| 510 |
+
|
| 511 |
+
push(git_dir)
|
| 512 |
+
|
| 513 |
+
total_segs = len(seg_files)
|
| 514 |
+
for bi, i in enumerate(range(0, total_segs, batch_size)):
|
| 515 |
+
batch = seg_files[i:i+batch_size]
|
| 516 |
+
subprocess.run(["git", "add"] + batch, cwd=git_dir,
|
| 517 |
+
check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 518 |
+
subprocess.run(["git", "commit", "-m", f"Batch {i}-{i+len(batch)}"],
|
| 519 |
+
cwd=git_dir, check=True,
|
| 520 |
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 521 |
+
for attempt in range(3):
|
| 522 |
+
try:
|
| 523 |
+
subprocess.run(["git", "push", "origin", "main"],
|
| 524 |
+
cwd=git_dir, check=True,
|
| 525 |
+
stdout=subprocess.DEVNULL,
|
| 526 |
+
stderr=subprocess.PIPE, timeout=600)
|
| 527 |
+
break
|
| 528 |
+
except (subprocess.CalledProcessError, subprocess.TimeoutExpired):
|
| 529 |
+
if attempt == 2:
|
| 530 |
+
self.log.emit(f" ⚠️ Error batch {i}, continuando...")
|
| 531 |
+
|
| 532 |
+
pct = int((idx + (i / max(total_segs, 1))) / total * 100)
|
| 533 |
+
self.progress.emit(pct)
|
| 534 |
+
|
| 535 |
+
gooplay = (f"https://gooplay.xyz/gp/stream.php?"
|
| 536 |
+
f"repo={repo_name}&branch=main&file={manifest_file}")
|
| 537 |
+
github = f"{html_url}/blob/main/{manifest_file}"
|
| 538 |
+
link_text = (f"✅ {folder_name}\n"
|
| 539 |
+
f" 🔗 Gooplay: {gooplay}\n"
|
| 540 |
+
f" 📂 GitHub: {github}")
|
| 541 |
+
all_links.append(link_text)
|
| 542 |
+
self.link.emit(link_text)
|
| 543 |
+
self.log.emit(f" ✅ Subido OK: {folder_name}")
|
| 544 |
+
|
| 545 |
+
if delete_local:
|
| 546 |
+
shutil.rmtree(output_dir, ignore_errors=True)
|
| 547 |
+
|
| 548 |
+
self.progress.emit(100)
|
| 549 |
+
self.done.emit()
|
| 550 |
+
|
| 551 |
+
except Exception as exc:
|
| 552 |
+
import traceback
|
| 553 |
+
traceback.print_exc()
|
| 554 |
+
self.error.emit(str(exc))
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
# ─── Ventana principal ────────────────────────────────────────────────────────
|
| 558 |
+
|
| 559 |
+
STYLE = """
|
| 560 |
+
QMainWindow, QWidget { background: #1e1e2e; color: #cdd6f4; font-family: 'Segoe UI', Arial, sans-serif; }
|
| 561 |
+
QGroupBox {
|
| 562 |
+
border: 1px solid #45475a; border-radius: 8px; margin-top: 12px;
|
| 563 |
+
padding: 10px; font-weight: bold; color: #89b4fa;
|
| 564 |
+
}
|
| 565 |
+
QGroupBox::title { subcontrol-origin: margin; left: 10px; padding: 0 4px; }
|
| 566 |
+
QLineEdit, QTextEdit, QComboBox, QSpinBox {
|
| 567 |
+
background: #313244; border: 1px solid #45475a; border-radius: 6px;
|
| 568 |
+
padding: 6px 8px; color: #cdd6f4; selection-background-color: #89b4fa;
|
| 569 |
+
}
|
| 570 |
+
QLineEdit:focus, QTextEdit:focus, QComboBox:focus, QSpinBox:focus {
|
| 571 |
+
border: 1px solid #89b4fa;
|
| 572 |
+
}
|
| 573 |
+
QPushButton {
|
| 574 |
+
background: #89b4fa; color: #1e1e2e; border: none; border-radius: 8px;
|
| 575 |
+
padding: 10px 20px; font-weight: bold; font-size: 13px;
|
| 576 |
+
}
|
| 577 |
+
QPushButton:hover { background: #b4befe; }
|
| 578 |
+
QPushButton:pressed { background: #74c7ec; }
|
| 579 |
+
QPushButton:disabled { background: #45475a; color: #6c7086; }
|
| 580 |
+
QPushButton#danger { background: #f38ba8; }
|
| 581 |
+
QPushButton#danger:hover { background: #eba0ac; }
|
| 582 |
+
QPushButton#secondary {
|
| 583 |
+
background: #313244; color: #89b4fa;
|
| 584 |
+
border: 1px solid #89b4fa;
|
| 585 |
+
}
|
| 586 |
+
QPushButton#secondary:hover { background: #45475a; }
|
| 587 |
+
QRadioButton { color: #cdd6f4; spacing: 6px; }
|
| 588 |
+
QRadioButton::indicator { width: 16px; height: 16px; }
|
| 589 |
+
QCheckBox { color: #cdd6f4; spacing: 6px; }
|
| 590 |
+
QSlider::groove:horizontal { height: 6px; background: #45475a; border-radius: 3px; }
|
| 591 |
+
QSlider::handle:horizontal {
|
| 592 |
+
background: #89b4fa; width: 16px; height: 16px; margin: -5px 0;
|
| 593 |
+
border-radius: 8px;
|
| 594 |
+
}
|
| 595 |
+
QProgressBar {
|
| 596 |
+
background: #313244; border: none; border-radius: 6px;
|
| 597 |
+
text-align: center; color: #cdd6f4; height: 20px;
|
| 598 |
+
}
|
| 599 |
+
QProgressBar::chunk { background: #89b4fa; border-radius: 6px; }
|
| 600 |
+
QScrollBar:vertical {
|
| 601 |
+
background: #1e1e2e; width: 10px; border-radius: 5px;
|
| 602 |
+
}
|
| 603 |
+
QScrollBar::handle:vertical { background: #45475a; border-radius: 5px; min-height: 30px; }
|
| 604 |
+
QScrollBar::handle:vertical:hover { background: #89b4fa; }
|
| 605 |
+
QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { height: 0; }
|
| 606 |
+
QLabel#title { font-size: 20px; font-weight: bold; color: #89b4fa; }
|
| 607 |
+
QLabel#subtitle { font-size: 12px; color: #a6adc8; }
|
| 608 |
+
QLabel#info { color: #a6e3a1; font-size: 11px; }
|
| 609 |
+
"""
|
| 610 |
+
|
| 611 |
+
|
| 612 |
+
class MainWindow(QMainWindow):
|
| 613 |
+
def __init__(self):
|
| 614 |
+
super().__init__()
|
| 615 |
+
self.setWindowTitle("⚡ HLS/DASH Converter EXTREME v4.5")
|
| 616 |
+
self.setMinimumSize(1100, 750)
|
| 617 |
+
self.resize(1280, 820)
|
| 618 |
+
self.setStyleSheet(STYLE)
|
| 619 |
+
|
| 620 |
+
self.worker = None
|
| 621 |
+
self.thread = None
|
| 622 |
+
self.uploaded_files = []
|
| 623 |
+
|
| 624 |
+
self._build_ui()
|
| 625 |
+
|
| 626 |
+
# ── UI construction ───────────────────────────────────────────────────────
|
| 627 |
+
|
| 628 |
+
def _build_ui(self):
|
| 629 |
+
central = QWidget()
|
| 630 |
+
self.setCentralWidget(central)
|
| 631 |
+
root = QVBoxLayout(central)
|
| 632 |
+
root.setContentsMargins(16, 12, 16, 12)
|
| 633 |
+
root.setSpacing(10)
|
| 634 |
+
|
| 635 |
+
# Header
|
| 636 |
+
hdr = QHBoxLayout()
|
| 637 |
+
t = QLabel("⚡ HLS/DASH Converter EXTREME v4.5-FIXED")
|
| 638 |
+
t.setObjectName("title")
|
| 639 |
+
hdr.addWidget(t)
|
| 640 |
+
hdr.addStretch()
|
| 641 |
+
info = QLabel(f"🔥 CPU: {OPTIMAL_THREADS} threads | 💾 RAM: {RAMDISK_PATH}")
|
| 642 |
+
info.setObjectName("info")
|
| 643 |
+
hdr.addWidget(info)
|
| 644 |
+
root.addLayout(hdr)
|
| 645 |
+
|
| 646 |
+
fix_lbl = QLabel("🔧 Audio SIEMPRE renderizado a MP3 192k — Never copy")
|
| 647 |
+
fix_lbl.setObjectName("subtitle")
|
| 648 |
+
root.addWidget(fix_lbl)
|
| 649 |
+
|
| 650 |
+
# Splitter main
|
| 651 |
+
splitter = QSplitter(Qt.Orientation.Horizontal if PYQT_VERSION == 6
|
| 652 |
+
else Qt.Horizontal)
|
| 653 |
+
splitter.setHandleWidth(4)
|
| 654 |
+
root.addWidget(splitter, stretch=1)
|
| 655 |
+
|
| 656 |
+
# ── Left panel ────────────────────────────────────────────────────────
|
| 657 |
+
left = QWidget()
|
| 658 |
+
left.setMaximumWidth(440)
|
| 659 |
+
left_layout = QVBoxLayout(left)
|
| 660 |
+
left_layout.setSpacing(10)
|
| 661 |
+
left_layout.setContentsMargins(0, 0, 8, 0)
|
| 662 |
+
|
| 663 |
+
# GitHub token
|
| 664 |
+
grp_gh = QGroupBox("🔑 GitHub")
|
| 665 |
+
gl = QVBoxLayout(grp_gh)
|
| 666 |
+
self.token_edit = QLineEdit()
|
| 667 |
+
self.token_edit.setPlaceholderText("ghp_xxxxxxxxxxxxxxxxxxxx")
|
| 668 |
+
self.token_edit.setEchoMode(QLineEdit.EchoMode.Password if PYQT_VERSION == 6
|
| 669 |
+
else QLineEdit.Password)
|
| 670 |
+
gl.addWidget(QLabel("Token de GitHub:"))
|
| 671 |
+
gl.addWidget(self.token_edit)
|
| 672 |
+
left_layout.addWidget(grp_gh)
|
| 673 |
+
|
| 674 |
+
# Input sources
|
| 675 |
+
grp_in = QGroupBox("📥 Fuentes")
|
| 676 |
+
il = QVBoxLayout(grp_in)
|
| 677 |
+
|
| 678 |
+
il.addWidget(QLabel("Archivos locales:"))
|
| 679 |
+
file_row = QHBoxLayout()
|
| 680 |
+
self.file_label = QLabel("Sin archivos seleccionados")
|
| 681 |
+
self.file_label.setWordWrap(True)
|
| 682 |
+
self.file_label.setObjectName("subtitle")
|
| 683 |
+
file_row.addWidget(self.file_label, stretch=1)
|
| 684 |
+
btn_browse = QPushButton("📂 Examinar")
|
| 685 |
+
btn_browse.setObjectName("secondary")
|
| 686 |
+
btn_browse.setFixedWidth(110)
|
| 687 |
+
btn_browse.clicked.connect(self._browse_files)
|
| 688 |
+
file_row.addWidget(btn_browse)
|
| 689 |
+
il.addLayout(file_row)
|
| 690 |
+
|
| 691 |
+
il.addWidget(QLabel("URLs (una por línea):"))
|
| 692 |
+
self.urls_edit = QTextEdit()
|
| 693 |
+
self.urls_edit.setPlaceholderText("https://example.com/video.mp4\nhttps://...")
|
| 694 |
+
self.urls_edit.setMaximumHeight(90)
|
| 695 |
+
il.addWidget(self.urls_edit)
|
| 696 |
+
left_layout.addWidget(grp_in)
|
| 697 |
+
|
| 698 |
+
# Conversion options
|
| 699 |
+
grp_conv = QGroupBox("⚙️ Conversión")
|
| 700 |
+
cl = QVBoxLayout(grp_conv)
|
| 701 |
+
|
| 702 |
+
cl.addWidget(QLabel("Modo:"))
|
| 703 |
+
self.conv_combo = QComboBox()
|
| 704 |
+
self.conv_combo.addItems([
|
| 705 |
+
"Opción 1: Copy Video + Copy Audio",
|
| 706 |
+
"Opción 2: Copy Video + MP3 Audio",
|
| 707 |
+
"Opción 3: Multi-Res (1080p + 720p) H.264",
|
| 708 |
+
"Opción 4: Multi-Res (4K + 1080p + 720p) H.264",
|
| 709 |
+
])
|
| 710 |
+
cl.addWidget(self.conv_combo)
|
| 711 |
+
|
| 712 |
+
cl.addWidget(QLabel("Formato de salida:"))
|
| 713 |
+
self.fmt_combo = QComboBox()
|
| 714 |
+
self.fmt_combo.addItems(["HLS (M3U8)", "DASH (MPD)"])
|
| 715 |
+
cl.addWidget(self.fmt_combo)
|
| 716 |
+
|
| 717 |
+
row_opts = QHBoxLayout()
|
| 718 |
+
batch_col = QVBoxLayout()
|
| 719 |
+
batch_col.addWidget(QLabel("Batch Git:"))
|
| 720 |
+
self.batch_spin = QSpinBox()
|
| 721 |
+
self.batch_spin.setRange(5, 200)
|
| 722 |
+
self.batch_spin.setValue(30)
|
| 723 |
+
batch_col.addWidget(self.batch_spin)
|
| 724 |
+
row_opts.addLayout(batch_col)
|
| 725 |
+
|
| 726 |
+
workers_col = QVBoxLayout()
|
| 727 |
+
workers_col.addWidget(QLabel("Workers Audio:"))
|
| 728 |
+
self.workers_slider = QSlider(Qt.Orientation.Horizontal if PYQT_VERSION == 6
|
| 729 |
+
else Qt.Horizontal)
|
| 730 |
+
self.workers_slider.setRange(1, 8)
|
| 731 |
+
self.workers_slider.setValue(4)
|
| 732 |
+
self.workers_label = QLabel("4")
|
| 733 |
+
self.workers_slider.valueChanged.connect(
|
| 734 |
+
lambda v: self.workers_label.setText(str(v)))
|
| 735 |
+
w_row = QHBoxLayout()
|
| 736 |
+
w_row.addWidget(self.workers_slider)
|
| 737 |
+
w_row.addWidget(self.workers_label)
|
| 738 |
+
workers_col.addLayout(w_row)
|
| 739 |
+
row_opts.addLayout(workers_col)
|
| 740 |
+
cl.addLayout(row_opts)
|
| 741 |
+
|
| 742 |
+
self.delete_chk = QCheckBox("Borrar archivos locales al terminar")
|
| 743 |
+
self.delete_chk.setChecked(True)
|
| 744 |
+
cl.addWidget(self.delete_chk)
|
| 745 |
+
left_layout.addWidget(grp_conv)
|
| 746 |
+
|
| 747 |
+
# Content naming
|
| 748 |
+
grp_name = QGroupBox("🎬 Nombre del contenido")
|
| 749 |
+
nl = QVBoxLayout(grp_name)
|
| 750 |
+
|
| 751 |
+
type_row = QHBoxLayout()
|
| 752 |
+
self.radio_movie = QRadioButton("🎬 Película")
|
| 753 |
+
self.radio_serie = QRadioButton("📺 Serie")
|
| 754 |
+
self.radio_movie.setChecked(True)
|
| 755 |
+
type_row.addWidget(self.radio_movie)
|
| 756 |
+
type_row.addWidget(self.radio_serie)
|
| 757 |
+
type_row.addStretch()
|
| 758 |
+
nl.addLayout(type_row)
|
| 759 |
+
|
| 760 |
+
self.movie_group = QWidget()
|
| 761 |
+
mg = QVBoxLayout(self.movie_group)
|
| 762 |
+
mg.setContentsMargins(0, 0, 0, 0)
|
| 763 |
+
mg.addWidget(QLabel("Nombre de la película:"))
|
| 764 |
+
self.movie_name = QLineEdit()
|
| 765 |
+
self.movie_name.setPlaceholderText("Ej: El Padrino")
|
| 766 |
+
mg.addWidget(self.movie_name)
|
| 767 |
+
nl.addWidget(self.movie_group)
|
| 768 |
+
|
| 769 |
+
self.serie_group = QWidget()
|
| 770 |
+
sg = QVBoxLayout(self.serie_group)
|
| 771 |
+
sg.setContentsMargins(0, 0, 0, 0)
|
| 772 |
+
sg.addWidget(QLabel("Nombre de la serie:"))
|
| 773 |
+
self.serie_name = QLineEdit()
|
| 774 |
+
self.serie_name.setPlaceholderText("Ej: Breaking Bad")
|
| 775 |
+
sg.addWidget(self.serie_name)
|
| 776 |
+
ep_row = QHBoxLayout()
|
| 777 |
+
season_col = QVBoxLayout()
|
| 778 |
+
season_col.addWidget(QLabel("Temporada:"))
|
| 779 |
+
self.season_spin = QSpinBox()
|
| 780 |
+
self.season_spin.setRange(1, 99)
|
| 781 |
+
self.season_spin.setValue(1)
|
| 782 |
+
season_col.addWidget(self.season_spin)
|
| 783 |
+
ep_col = QVBoxLayout()
|
| 784 |
+
ep_col.addWidget(QLabel("Ep. inicial:"))
|
| 785 |
+
self.ep_spin = QSpinBox()
|
| 786 |
+
self.ep_spin.setRange(1, 999)
|
| 787 |
+
self.ep_spin.setValue(1)
|
| 788 |
+
ep_col.addWidget(self.ep_spin)
|
| 789 |
+
ep_row.addLayout(season_col)
|
| 790 |
+
ep_row.addLayout(ep_col)
|
| 791 |
+
sg.addLayout(ep_row)
|
| 792 |
+
self.serie_group.hide()
|
| 793 |
+
nl.addWidget(self.serie_group)
|
| 794 |
+
|
| 795 |
+
self.radio_movie.toggled.connect(self._toggle_content)
|
| 796 |
+
left_layout.addWidget(grp_name)
|
| 797 |
+
left_layout.addStretch()
|
| 798 |
+
|
| 799 |
+
# Action buttons
|
| 800 |
+
self.btn_start = QPushButton("🚀 PROCESAR")
|
| 801 |
+
self.btn_start.setMinimumHeight(48)
|
| 802 |
+
self.btn_start.clicked.connect(self._start)
|
| 803 |
+
left_layout.addWidget(self.btn_start)
|
| 804 |
+
|
| 805 |
+
self.btn_cancel = QPushButton("⛔ Cancelar")
|
| 806 |
+
self.btn_cancel.setObjectName("danger")
|
| 807 |
+
self.btn_cancel.setMinimumHeight(36)
|
| 808 |
+
self.btn_cancel.clicked.connect(self._cancel)
|
| 809 |
+
self.btn_cancel.setEnabled(False)
|
| 810 |
+
left_layout.addWidget(self.btn_cancel)
|
| 811 |
+
|
| 812 |
+
splitter.addWidget(left)
|
| 813 |
+
|
| 814 |
+
# ── Right panel ───────────────────────────────────────────────────────
|
| 815 |
+
right = QWidget()
|
| 816 |
+
rl = QVBoxLayout(right)
|
| 817 |
+
rl.setContentsMargins(8, 0, 0, 0)
|
| 818 |
+
rl.setSpacing(8)
|
| 819 |
+
|
| 820 |
+
rl.addWidget(QLabel("📋 Logs en tiempo real:"))
|
| 821 |
+
self.log_box = QTextEdit()
|
| 822 |
+
self.log_box.setReadOnly(True)
|
| 823 |
+
self.log_box.setFont(QFont("Consolas", 10))
|
| 824 |
+
self.log_box.setStyleSheet("background:#0f0f1a; color:#a6e3a1; border-radius:8px; padding:8px;")
|
| 825 |
+
rl.addWidget(self.log_box, stretch=3)
|
| 826 |
+
|
| 827 |
+
rl.addWidget(QLabel("🔗 Links generados:"))
|
| 828 |
+
self.links_box = QTextEdit()
|
| 829 |
+
self.links_box.setReadOnly(True)
|
| 830 |
+
self.links_box.setFont(QFont("Consolas", 10))
|
| 831 |
+
self.links_box.setStyleSheet("background:#0f0f1a; color:#89dceb; border-radius:8px; padding:8px;")
|
| 832 |
+
self.links_box.setMaximumHeight(180)
|
| 833 |
+
rl.addWidget(self.links_box)
|
| 834 |
+
|
| 835 |
+
self.progress_bar = QProgressBar()
|
| 836 |
+
self.progress_bar.setValue(0)
|
| 837 |
+
rl.addWidget(self.progress_bar)
|
| 838 |
+
|
| 839 |
+
btn_row = QHBoxLayout()
|
| 840 |
+
btn_clear_log = QPushButton("🗑 Limpiar logs")
|
| 841 |
+
btn_clear_log.setObjectName("secondary")
|
| 842 |
+
btn_clear_log.clicked.connect(self.log_box.clear)
|
| 843 |
+
btn_copy_links = QPushButton("📋 Copiar links")
|
| 844 |
+
btn_copy_links.setObjectName("secondary")
|
| 845 |
+
btn_copy_links.clicked.connect(self._copy_links)
|
| 846 |
+
btn_row.addWidget(btn_clear_log)
|
| 847 |
+
btn_row.addWidget(btn_copy_links)
|
| 848 |
+
btn_row.addStretch()
|
| 849 |
+
rl.addLayout(btn_row)
|
| 850 |
+
|
| 851 |
+
splitter.addWidget(right)
|
| 852 |
+
splitter.setSizes([420, 700])
|
| 853 |
+
|
| 854 |
+
# ── Slots ─────────────────────────────────────────────────────────────────
|
| 855 |
+
|
| 856 |
+
def _toggle_content(self, movie_checked):
|
| 857 |
+
self.movie_group.setVisible(movie_checked)
|
| 858 |
+
self.serie_group.setVisible(not movie_checked)
|
| 859 |
+
|
| 860 |
+
def _browse_files(self):
|
| 861 |
+
files, _ = QFileDialog.getOpenFileNames(
|
| 862 |
+
self, "Seleccionar archivos de video", "",
|
| 863 |
+
"Videos (*.mp4 *.mkv *.avi *.mov *.wmv *.flv *.webm *.ts);;Todos (*)")
|
| 864 |
+
if files:
|
| 865 |
+
self.uploaded_files = files
|
| 866 |
+
names = ", ".join(Path(f).name for f in files)
|
| 867 |
+
self.file_label.setText(names)
|
| 868 |
+
|
| 869 |
+
def _log(self, msg: str):
|
| 870 |
+
self.log_box.append(msg)
|
| 871 |
+
self.log_box.moveCursor(QTextCursor.MoveOperation.End if PYQT_VERSION == 6
|
| 872 |
+
else QTextCursor.End)
|
| 873 |
+
|
| 874 |
+
def _add_link(self, txt: str):
|
| 875 |
+
self.links_box.append(txt + "\n")
|
| 876 |
+
|
| 877 |
+
def _copy_links(self):
|
| 878 |
+
QApplication.clipboard().setText(self.links_box.toPlainText())
|
| 879 |
+
|
| 880 |
+
def _on_done(self):
|
| 881 |
+
self._log("\n🎉 ¡Proceso completado!")
|
| 882 |
+
self.btn_start.setEnabled(True)
|
| 883 |
+
self.btn_cancel.setEnabled(False)
|
| 884 |
+
self.progress_bar.setValue(100)
|
| 885 |
+
|
| 886 |
+
def _on_error(self, msg: str):
|
| 887 |
+
self._log(f"\n❌ ERROR: {msg}")
|
| 888 |
+
self.btn_start.setEnabled(True)
|
| 889 |
+
self.btn_cancel.setEnabled(False)
|
| 890 |
+
|
| 891 |
+
def _cancel(self):
|
| 892 |
+
if self.worker:
|
| 893 |
+
self.worker.abort()
|
| 894 |
+
self._log("⛔ Cancelando...")
|
| 895 |
+
self.btn_cancel.setEnabled(False)
|
| 896 |
+
|
| 897 |
+
def _start(self):
|
| 898 |
+
sources = []
|
| 899 |
+
for f in self.uploaded_files:
|
| 900 |
+
sources.append({"type": "file", "value": f})
|
| 901 |
+
for line in self.urls_edit.toPlainText().splitlines():
|
| 902 |
+
url = line.strip()
|
| 903 |
+
if url:
|
| 904 |
+
sources.append({"type": "url", "value": url})
|
| 905 |
+
|
| 906 |
+
if not sources:
|
| 907 |
+
self._log("⚠️ Agrega archivos o URLs primero.")
|
| 908 |
+
return
|
| 909 |
+
|
| 910 |
+
conv_map = {0: "copy1", 1: "copy2", 2: "multi1080", 3: "multi4k"}
|
| 911 |
+
conv_option = conv_map.get(self.conv_combo.currentIndex(), "copy1")
|
| 912 |
+
|
| 913 |
+
params = {
|
| 914 |
+
"token": self.token_edit.text().strip(),
|
| 915 |
+
"sources": sources,
|
| 916 |
+
"conv_option": conv_option,
|
| 917 |
+
"stream_fmt": self.fmt_combo.currentText(),
|
| 918 |
+
"batch_size": self.batch_spin.value(),
|
| 919 |
+
"delete_local": self.delete_chk.isChecked(),
|
| 920 |
+
"max_workers": self.workers_slider.value(),
|
| 921 |
+
"content_type": "movie" if self.radio_movie.isChecked() else "serie",
|
| 922 |
+
"movie_name": self.movie_name.text(),
|
| 923 |
+
"serie_name": self.serie_name.text(),
|
| 924 |
+
"season": self.season_spin.value(),
|
| 925 |
+
"ep_start": self.ep_spin.value(),
|
| 926 |
+
}
|
| 927 |
+
|
| 928 |
+
self.log_box.clear()
|
| 929 |
+
self.links_box.clear()
|
| 930 |
+
self.progress_bar.setValue(0)
|
| 931 |
+
self.btn_start.setEnabled(False)
|
| 932 |
+
self.btn_cancel.setEnabled(True)
|
| 933 |
+
|
| 934 |
+
self.thread = QThread()
|
| 935 |
+
self.worker = ConvertWorker(params)
|
| 936 |
+
self.worker.moveToThread(self.thread)
|
| 937 |
+
|
| 938 |
+
self.thread.started.connect(self.worker.run)
|
| 939 |
+
self.worker.log.connect(self._log)
|
| 940 |
+
self.worker.link.connect(self._add_link)
|
| 941 |
+
self.worker.progress.connect(self.progress_bar.setValue)
|
| 942 |
+
self.worker.done.connect(self._on_done)
|
| 943 |
+
self.worker.done.connect(self.thread.quit)
|
| 944 |
+
self.worker.error.connect(self._on_error)
|
| 945 |
+
self.worker.error.connect(self.thread.quit)
|
| 946 |
+
self.thread.finished.connect(self.thread.deleteLater)
|
| 947 |
+
|
| 948 |
+
self.thread.start()
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
# ─── Entry point ──────────────────────────────────────────────────────────────
|
| 952 |
+
|
| 953 |
+
def main():
|
| 954 |
+
# Configurar git global
|
| 955 |
+
for cmd in [
|
| 956 |
+
["git", "config", "--global", "user.email", "actions@github.com"],
|
| 957 |
+
["git", "config", "--global", "user.name", "Converter GUI"],
|
| 958 |
+
["git", "config", "--global", "core.compression", "0"],
|
| 959 |
+
["git", "config", "--global", "pack.threads", str(OPTIMAL_THREADS)],
|
| 960 |
+
]:
|
| 961 |
+
subprocess.run(cmd, check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 962 |
+
|
| 963 |
+
app = QApplication(sys.argv)
|
| 964 |
+
app.setApplicationName("HLS/DASH Converter EXTREME")
|
| 965 |
+
|
| 966 |
+
win = MainWindow()
|
| 967 |
+
win.show()
|
| 968 |
+
sys.exit(app.exec())
|
| 969 |
+
|
| 970 |
+
|
| 971 |
+
if __name__ == "__main__":
|
| 972 |
+
main()
|
videos/ffmpeg.exe
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:233fe2e772918fbd35adbf3ba3ae36274983a2a47e3e5bc65fcf4b9a18baea7d
|
| 3 |
+
size 100849152
|
videos/ffplay.exe
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:774c50ae763688d021a6ba838120c8cc9877e81ca7379eff65a52f2bf5ce4f6a
|
| 3 |
+
size 102323712
|
videos/ffprobe.exe
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:40d299fa8a7aeba4fc34cd0e3ddb8d332ec061d4edd983342b8b6c7a8d7d2ad4
|
| 3 |
+
size 100642816
|
videos/video_converter_gui_linux.py
ADDED
|
@@ -0,0 +1,619 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
| 2 |
+
"""
|
| 3 |
+
Video Converter Pro - Linux GUI Version
|
| 4 |
+
Interfaz gráfica para convertir videos con múltiples audios
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import sys
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
import re
|
| 11 |
+
import json
|
| 12 |
+
import tempfile
|
| 13 |
+
import threading
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
from typing import Optional, List, Tuple
|
| 16 |
+
import tkinter as tk
|
| 17 |
+
from tkinter import ttk, filedialog, messagebox, scrolledtext
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
from huggingface_hub import HfApi, list_models
|
| 21 |
+
HF_AVAILABLE = True
|
| 22 |
+
except ImportError:
|
| 23 |
+
HF_AVAILABLE = False
|
| 24 |
+
|
| 25 |
+
# ============================================================================
|
| 26 |
+
# CLASES DE BACKEND (igual que antes)
|
| 27 |
+
# ============================================================================
|
| 28 |
+
|
| 29 |
+
class AudioTrack:
|
| 30 |
+
def __init__(self, index, stream_index, codec, language, channels, title=""):
|
| 31 |
+
self.index = index
|
| 32 |
+
self.stream_index = stream_index
|
| 33 |
+
self.codec = codec
|
| 34 |
+
self.language = language
|
| 35 |
+
self.channels = channels
|
| 36 |
+
self.title = title
|
| 37 |
+
|
| 38 |
+
def display_name(self):
|
| 39 |
+
lang = self.language if self.language != "und" else "Unknown"
|
| 40 |
+
ch = f"{self.channels}ch" if self.channels else ""
|
| 41 |
+
title_part = f" - {self.title}" if self.title else ""
|
| 42 |
+
return f"[{self.index}] {lang} | {self.codec} {ch}{title_part}"
|
| 43 |
+
|
| 44 |
+
class SubtitleTrack:
|
| 45 |
+
def __init__(self, index, stream_index, codec, language, title="", forced=False):
|
| 46 |
+
self.index = index
|
| 47 |
+
self.stream_index = stream_index
|
| 48 |
+
self.codec = codec
|
| 49 |
+
self.language = language
|
| 50 |
+
self.title = title
|
| 51 |
+
self.forced = forced
|
| 52 |
+
|
| 53 |
+
def display_name(self):
|
| 54 |
+
lang = self.language if self.language != "und" else "Unknown"
|
| 55 |
+
forced_tag = " (Forced)" if self.forced else ""
|
| 56 |
+
title_part = f" - {self.title}" if self.title else ""
|
| 57 |
+
return f"[{self.index}] {lang} | {self.codec}{forced_tag}{title_part}"
|
| 58 |
+
|
| 59 |
+
class MediaInfo:
|
| 60 |
+
def __init__(self, path):
|
| 61 |
+
self.path = path
|
| 62 |
+
self.audio_tracks: List[AudioTrack] = []
|
| 63 |
+
self.subtitle_tracks: List[SubtitleTrack] = []
|
| 64 |
+
self.duration = 0.0
|
| 65 |
+
self.title: Optional[str] = None
|
| 66 |
+
|
| 67 |
+
class MediaAnalyzer:
|
| 68 |
+
@staticmethod
|
| 69 |
+
def get_media_info(source: str) -> MediaInfo:
|
| 70 |
+
info = MediaInfo(path=source)
|
| 71 |
+
try:
|
| 72 |
+
cmd = ["ffprobe", "-v", "quiet", "-print_format", "json",
|
| 73 |
+
"-show_format", "-show_streams", source]
|
| 74 |
+
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
|
| 75 |
+
if result.returncode != 0:
|
| 76 |
+
return info
|
| 77 |
+
|
| 78 |
+
data = json.loads(result.stdout)
|
| 79 |
+
format_tags = data.get("format", {}).get("tags", {})
|
| 80 |
+
info.title = format_tags.get("title") or format_tags.get("TITLE")
|
| 81 |
+
if info.title:
|
| 82 |
+
info.title = info.title.strip()
|
| 83 |
+
|
| 84 |
+
if "format" in data and "duration" in data["format"]:
|
| 85 |
+
info.duration = float(data["format"]["duration"])
|
| 86 |
+
|
| 87 |
+
audio_idx, sub_idx = 0, 0
|
| 88 |
+
for stream in data.get("streams", []):
|
| 89 |
+
codec_type = stream.get("codec_type", "")
|
| 90 |
+
tags = stream.get("tags", {})
|
| 91 |
+
|
| 92 |
+
if codec_type == "audio":
|
| 93 |
+
track = AudioTrack(
|
| 94 |
+
audio_idx,
|
| 95 |
+
stream.get("index", 0),
|
| 96 |
+
stream.get("codec_name", "unknown"),
|
| 97 |
+
tags.get("language", "und"),
|
| 98 |
+
stream.get("channels", 2),
|
| 99 |
+
tags.get("title", "")
|
| 100 |
+
)
|
| 101 |
+
info.audio_tracks.append(track)
|
| 102 |
+
audio_idx += 1
|
| 103 |
+
|
| 104 |
+
elif codec_type == "subtitle":
|
| 105 |
+
disposition = stream.get("disposition", {})
|
| 106 |
+
track = SubtitleTrack(
|
| 107 |
+
sub_idx,
|
| 108 |
+
stream.get("index", 0),
|
| 109 |
+
stream.get("codec_name", "unknown"),
|
| 110 |
+
tags.get("language", "und"),
|
| 111 |
+
tags.get("title", ""),
|
| 112 |
+
disposition.get("forced", 0) == 1
|
| 113 |
+
)
|
| 114 |
+
info.subtitle_tracks.append(track)
|
| 115 |
+
sub_idx += 1
|
| 116 |
+
|
| 117 |
+
except Exception as e:
|
| 118 |
+
print(f"Error analizando: {e}")
|
| 119 |
+
return info
|
| 120 |
+
|
| 121 |
+
class VideoConverter:
|
| 122 |
+
def __init__(self, progress_callback=None):
|
| 123 |
+
self.progress_callback = progress_callback
|
| 124 |
+
self.current_process = None
|
| 125 |
+
self.cancelled = False
|
| 126 |
+
|
| 127 |
+
def log(self, message):
|
| 128 |
+
if self.progress_callback:
|
| 129 |
+
self.progress_callback(message)
|
| 130 |
+
|
| 131 |
+
def cancel(self):
|
| 132 |
+
self.cancelled = True
|
| 133 |
+
if self.current_process:
|
| 134 |
+
self.current_process.terminate()
|
| 135 |
+
|
| 136 |
+
def run_ffmpeg(self, cmd: list, duration: float, description: str = "") -> Tuple[bool, str]:
|
| 137 |
+
try:
|
| 138 |
+
self.log(f"🎬 {description}...")
|
| 139 |
+
|
| 140 |
+
self.current_process = subprocess.Popen(
|
| 141 |
+
cmd,
|
| 142 |
+
stdout=subprocess.PIPE,
|
| 143 |
+
stderr=subprocess.PIPE,
|
| 144 |
+
universal_newlines=True
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
pattern = re.compile(r"time=(\d{2}):(\d{2}):(\d{2})\.(\d{2})")
|
| 148 |
+
last_percent = -1
|
| 149 |
+
|
| 150 |
+
for line in self.current_process.stderr:
|
| 151 |
+
if self.cancelled:
|
| 152 |
+
self.current_process.terminate()
|
| 153 |
+
return False, "Cancelado"
|
| 154 |
+
|
| 155 |
+
match = pattern.search(line)
|
| 156 |
+
if match and duration > 0:
|
| 157 |
+
h, m, s, ms = map(int, match.groups())
|
| 158 |
+
current = h * 3600 + m * 60 + s + ms / 100
|
| 159 |
+
percent = min(100, int((current / duration) * 100))
|
| 160 |
+
|
| 161 |
+
if percent > last_percent:
|
| 162 |
+
self.log(f"⚡ {description}: {percent}%")
|
| 163 |
+
last_percent = percent
|
| 164 |
+
|
| 165 |
+
self.current_process.wait()
|
| 166 |
+
return self.current_process.returncode == 0, "OK"
|
| 167 |
+
|
| 168 |
+
except Exception as e:
|
| 169 |
+
return False, str(e)
|
| 170 |
+
|
| 171 |
+
def convert(self, source: str, is_url: bool, mode: str, output_dir: str,
|
| 172 |
+
selected_audio: int, generate_single: bool, extract_sub: bool,
|
| 173 |
+
sub_index: int) -> Tuple[bool, str, Optional[str]]:
|
| 174 |
+
|
| 175 |
+
try:
|
| 176 |
+
if self.cancelled:
|
| 177 |
+
return False, "Cancelado", None
|
| 178 |
+
|
| 179 |
+
extra_input_options = []
|
| 180 |
+
if is_url:
|
| 181 |
+
extra_input_options = [
|
| 182 |
+
"-user_agent", "Mozilla/5.0",
|
| 183 |
+
"-headers", "Referer: https://google.com\r\n"
|
| 184 |
+
]
|
| 185 |
+
|
| 186 |
+
self.log("📊 Analizando video...")
|
| 187 |
+
info = MediaAnalyzer.get_media_info(source)
|
| 188 |
+
duration = info.duration if info.duration > 0 else 1
|
| 189 |
+
|
| 190 |
+
self.log(f"ℹ️ Duración: {duration:.1f}s")
|
| 191 |
+
self.log(f"ℹ️ Pistas de audio: {len(info.audio_tracks)}")
|
| 192 |
+
self.log(f"ℹ️ Subtítulos: {len(info.subtitle_tracks)}")
|
| 193 |
+
|
| 194 |
+
base_name = info.title if info.title else Path(source).stem
|
| 195 |
+
if not base_name or base_name.strip() == "":
|
| 196 |
+
base_name = "video_sin_nombre"
|
| 197 |
+
|
| 198 |
+
folder_name = re.sub(r'[<>:"/\\|?*]', '_', base_name)
|
| 199 |
+
folder_name = re.sub(r'\s+', ' ', folder_name).strip().replace(' ', '_')
|
| 200 |
+
folder_name = folder_name[:150]
|
| 201 |
+
|
| 202 |
+
if output_dir:
|
| 203 |
+
out_folder = os.path.join(output_dir, folder_name)
|
| 204 |
+
else:
|
| 205 |
+
temp_folder = tempfile.mkdtemp(prefix="video_conv_")
|
| 206 |
+
out_folder = os.path.join(temp_folder, folder_name)
|
| 207 |
+
|
| 208 |
+
os.makedirs(out_folder, exist_ok=True)
|
| 209 |
+
self.log(f"✅ Carpeta: {out_folder}")
|
| 210 |
+
|
| 211 |
+
# VIDEO PRINCIPAL
|
| 212 |
+
self.log("🎬 Renderizando video principal...")
|
| 213 |
+
|
| 214 |
+
all_audio_path = os.path.join(out_folder, f"{folder_name}_all_audio.mp4")
|
| 215 |
+
|
| 216 |
+
cmd = ["ffmpeg", "-y"] + extra_input_options + ["-i", source]
|
| 217 |
+
cmd.extend(["-map", "0:v:0"])
|
| 218 |
+
|
| 219 |
+
for i in range(len(info.audio_tracks)):
|
| 220 |
+
cmd.extend(["-map", f"0:a:{i}"])
|
| 221 |
+
|
| 222 |
+
cmd.extend(["-c:v", "copy"])
|
| 223 |
+
|
| 224 |
+
if mode == "mp3":
|
| 225 |
+
for i in range(len(info.audio_tracks)):
|
| 226 |
+
cmd.extend([
|
| 227 |
+
f"-c:a:{i}", "libmp3lame",
|
| 228 |
+
f"-b:a:{i}", "320k",
|
| 229 |
+
f"-ar:a:{i}", "48000"
|
| 230 |
+
])
|
| 231 |
+
self.log("🎵 Codec: MP3 320k @ 48kHz")
|
| 232 |
+
|
| 233 |
+
elif mode == "flac":
|
| 234 |
+
for i in range(len(info.audio_tracks)):
|
| 235 |
+
cmd.extend([
|
| 236 |
+
f"-c:a:{i}", "flac",
|
| 237 |
+
f"-compression_level:a:{i}", "0"
|
| 238 |
+
])
|
| 239 |
+
self.log("🎵 Codec: FLAC")
|
| 240 |
+
|
| 241 |
+
else: # h264
|
| 242 |
+
cmd = ["ffmpeg", "-y"] + extra_input_options + ["-i", source]
|
| 243 |
+
cmd.extend(["-map", "0:v:0"])
|
| 244 |
+
for i in range(len(info.audio_tracks)):
|
| 245 |
+
cmd.extend(["-map", f"0:a:{i}"])
|
| 246 |
+
|
| 247 |
+
cmd.extend([
|
| 248 |
+
"-c:v", "libx264",
|
| 249 |
+
"-vf", "scale=-2:1080",
|
| 250 |
+
"-preset", "slow",
|
| 251 |
+
"-crf", "18"
|
| 252 |
+
])
|
| 253 |
+
|
| 254 |
+
for i in range(len(info.audio_tracks)):
|
| 255 |
+
cmd.extend([
|
| 256 |
+
f"-c:a:{i}", "libmp3lame",
|
| 257 |
+
f"-b:a:{i}", "320k",
|
| 258 |
+
f"-ar:a:{i}", "48000"
|
| 259 |
+
])
|
| 260 |
+
self.log("🎥 Video: H.264 1080p CRF18")
|
| 261 |
+
|
| 262 |
+
cmd.extend([
|
| 263 |
+
"-map_metadata", "0",
|
| 264 |
+
"-metadata", "copyright=Power Prods",
|
| 265 |
+
all_audio_path
|
| 266 |
+
])
|
| 267 |
+
|
| 268 |
+
success, msg = self.run_ffmpeg(cmd, duration, "Renderizado principal")
|
| 269 |
+
|
| 270 |
+
if not success:
|
| 271 |
+
return False, f"Error: {msg}", None
|
| 272 |
+
|
| 273 |
+
self.log("✅ Video principal completado")
|
| 274 |
+
|
| 275 |
+
# VIDEO INDIVIDUAL
|
| 276 |
+
if generate_single and selected_audio < len(info.audio_tracks):
|
| 277 |
+
self.log("🎵 Extrayendo audio individual...")
|
| 278 |
+
|
| 279 |
+
single_path = os.path.join(out_folder, f"{folder_name}_audio_{selected_audio}.mp4")
|
| 280 |
+
|
| 281 |
+
single_cmd = [
|
| 282 |
+
"ffmpeg", "-y",
|
| 283 |
+
"-i", all_audio_path,
|
| 284 |
+
"-map", "0:v:0",
|
| 285 |
+
"-map", f"0:a:{selected_audio}",
|
| 286 |
+
"-c", "copy",
|
| 287 |
+
"-map_metadata", "0",
|
| 288 |
+
single_path
|
| 289 |
+
]
|
| 290 |
+
|
| 291 |
+
success_single, msg_single = self.run_ffmpeg(
|
| 292 |
+
single_cmd, duration, "Extracción individual"
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
if success_single:
|
| 296 |
+
self.log("✅ Video individual creado")
|
| 297 |
+
|
| 298 |
+
# SUBTÍTULOS
|
| 299 |
+
if extract_sub and info.subtitle_tracks and sub_index < len(info.subtitle_tracks):
|
| 300 |
+
self.log("📝 Extrayendo subtítulos...")
|
| 301 |
+
|
| 302 |
+
vtt_path = os.path.join(out_folder, f"{folder_name}_sub_{sub_index}.vtt")
|
| 303 |
+
sub_cmd = ["ffmpeg", "-y"] + extra_input_options + [
|
| 304 |
+
"-i", source,
|
| 305 |
+
"-map", f"0:s:{sub_index}",
|
| 306 |
+
"-c:s", "webvtt",
|
| 307 |
+
vtt_path
|
| 308 |
+
]
|
| 309 |
+
|
| 310 |
+
try:
|
| 311 |
+
subprocess.run(sub_cmd, capture_output=True, check=True, timeout=120)
|
| 312 |
+
self.log("✅ Subtítulo extraído")
|
| 313 |
+
except Exception as e:
|
| 314 |
+
self.log(f"⚠️ Error: {e}")
|
| 315 |
+
|
| 316 |
+
self.log("🎉 ¡PROCESO COMPLETADO!")
|
| 317 |
+
self.log(f"📂 Archivos en: {out_folder}")
|
| 318 |
+
|
| 319 |
+
return True, "Conversión completada", out_folder
|
| 320 |
+
|
| 321 |
+
except Exception as e:
|
| 322 |
+
return False, f"Error crítico: {e}", None
|
| 323 |
+
|
| 324 |
+
# ============================================================================
|
| 325 |
+
# INTERFAZ GRÁFICA
|
| 326 |
+
# ============================================================================
|
| 327 |
+
|
| 328 |
+
class VideoConverterGUI:
|
| 329 |
+
def __init__(self, root):
|
| 330 |
+
self.root = root
|
| 331 |
+
self.root.title("Video Converter Pro - Linux")
|
| 332 |
+
self.root.geometry("900x700")
|
| 333 |
+
self.root.configure(bg="#2b2b2b")
|
| 334 |
+
|
| 335 |
+
self.converter = None
|
| 336 |
+
self.media_info = None
|
| 337 |
+
self.output_folder = None
|
| 338 |
+
|
| 339 |
+
self.create_widgets()
|
| 340 |
+
|
| 341 |
+
def create_widgets(self):
|
| 342 |
+
# Estilo
|
| 343 |
+
style = ttk.Style()
|
| 344 |
+
style.theme_use('clam')
|
| 345 |
+
style.configure('TFrame', background='#2b2b2b')
|
| 346 |
+
style.configure('TLabel', background='#2b2b2b', foreground='white')
|
| 347 |
+
style.configure('TButton', background='#4a4a4a', foreground='white')
|
| 348 |
+
style.configure('Title.TLabel', font=('Arial', 16, 'bold'), foreground='#00d4ff')
|
| 349 |
+
|
| 350 |
+
# Header
|
| 351 |
+
header = ttk.Frame(self.root)
|
| 352 |
+
header.pack(fill='x', padx=10, pady=10)
|
| 353 |
+
|
| 354 |
+
title = ttk.Label(header, text="🎬 Video Converter Pro", style='Title.TLabel')
|
| 355 |
+
title.pack()
|
| 356 |
+
|
| 357 |
+
# Fuente del video
|
| 358 |
+
source_frame = ttk.LabelFrame(self.root, text="📂 Fuente del Video", padding=10)
|
| 359 |
+
source_frame.pack(fill='x', padx=10, pady=5)
|
| 360 |
+
|
| 361 |
+
self.source_var = tk.StringVar()
|
| 362 |
+
source_entry = ttk.Entry(source_frame, textvariable=self.source_var, width=60)
|
| 363 |
+
source_entry.pack(side='left', padx=5)
|
| 364 |
+
|
| 365 |
+
btn_browse = ttk.Button(source_frame, text="Explorar", command=self.browse_file)
|
| 366 |
+
btn_browse.pack(side='left', padx=5)
|
| 367 |
+
|
| 368 |
+
btn_analyze = ttk.Button(source_frame, text="Analizar", command=self.analyze_video)
|
| 369 |
+
btn_analyze.pack(side='left', padx=5)
|
| 370 |
+
|
| 371 |
+
# Info del video
|
| 372 |
+
info_frame = ttk.LabelFrame(self.root, text="📊 Información del Video", padding=10)
|
| 373 |
+
info_frame.pack(fill='both', expand=True, padx=10, pady=5)
|
| 374 |
+
|
| 375 |
+
self.info_text = scrolledtext.ScrolledText(
|
| 376 |
+
info_frame,
|
| 377 |
+
height=8,
|
| 378 |
+
bg='#1e1e1e',
|
| 379 |
+
fg='white',
|
| 380 |
+
font=('Courier', 10)
|
| 381 |
+
)
|
| 382 |
+
self.info_text.pack(fill='both', expand=True)
|
| 383 |
+
|
| 384 |
+
# Opciones de conversión
|
| 385 |
+
options_frame = ttk.LabelFrame(self.root, text="⚙️ Opciones de Conversión", padding=10)
|
| 386 |
+
options_frame.pack(fill='x', padx=10, pady=5)
|
| 387 |
+
|
| 388 |
+
# Modo
|
| 389 |
+
mode_frame = ttk.Frame(options_frame)
|
| 390 |
+
mode_frame.pack(fill='x', pady=5)
|
| 391 |
+
|
| 392 |
+
ttk.Label(mode_frame, text="Modo:").pack(side='left', padx=5)
|
| 393 |
+
|
| 394 |
+
self.mode_var = tk.StringVar(value="mp3")
|
| 395 |
+
modes = [
|
| 396 |
+
("Video Copy + MP3 320k", "mp3"),
|
| 397 |
+
("Video Copy + FLAC", "flac"),
|
| 398 |
+
("Video H264 1080p + MP3", "h264")
|
| 399 |
+
]
|
| 400 |
+
|
| 401 |
+
for text, value in modes:
|
| 402 |
+
rb = ttk.Radiobutton(mode_frame, text=text, variable=self.mode_var, value=value)
|
| 403 |
+
rb.pack(side='left', padx=10)
|
| 404 |
+
|
| 405 |
+
# Audio individual
|
| 406 |
+
audio_frame = ttk.Frame(options_frame)
|
| 407 |
+
audio_frame.pack(fill='x', pady=5)
|
| 408 |
+
|
| 409 |
+
self.gen_single_var = tk.BooleanVar()
|
| 410 |
+
chk_single = ttk.Checkbutton(
|
| 411 |
+
audio_frame,
|
| 412 |
+
text="Generar video con audio individual",
|
| 413 |
+
variable=self.gen_single_var
|
| 414 |
+
)
|
| 415 |
+
chk_single.pack(side='left', padx=5)
|
| 416 |
+
|
| 417 |
+
ttk.Label(audio_frame, text="Índice:").pack(side='left', padx=5)
|
| 418 |
+
self.audio_index_var = tk.IntVar(value=0)
|
| 419 |
+
spin_audio = ttk.Spinbox(audio_frame, from_=0, to=10, textvariable=self.audio_index_var, width=5)
|
| 420 |
+
spin_audio.pack(side='left', padx=5)
|
| 421 |
+
|
| 422 |
+
# Subtítulos
|
| 423 |
+
sub_frame = ttk.Frame(options_frame)
|
| 424 |
+
sub_frame.pack(fill='x', pady=5)
|
| 425 |
+
|
| 426 |
+
self.extract_sub_var = tk.BooleanVar()
|
| 427 |
+
chk_sub = ttk.Checkbutton(
|
| 428 |
+
sub_frame,
|
| 429 |
+
text="Extraer subtítulos",
|
| 430 |
+
variable=self.extract_sub_var
|
| 431 |
+
)
|
| 432 |
+
chk_sub.pack(side='left', padx=5)
|
| 433 |
+
|
| 434 |
+
ttk.Label(sub_frame, text="Índice:").pack(side='left', padx=5)
|
| 435 |
+
self.sub_index_var = tk.IntVar(value=0)
|
| 436 |
+
spin_sub = ttk.Spinbox(sub_frame, from_=0, to=10, textvariable=self.sub_index_var, width=5)
|
| 437 |
+
spin_sub.pack(side='left', padx=5)
|
| 438 |
+
|
| 439 |
+
# Directorio de salida
|
| 440 |
+
output_frame = ttk.Frame(options_frame)
|
| 441 |
+
output_frame.pack(fill='x', pady=5)
|
| 442 |
+
|
| 443 |
+
ttk.Label(output_frame, text="Salida:").pack(side='left', padx=5)
|
| 444 |
+
self.output_var = tk.StringVar()
|
| 445 |
+
output_entry = ttk.Entry(output_frame, textvariable=self.output_var, width=40)
|
| 446 |
+
output_entry.pack(side='left', padx=5)
|
| 447 |
+
|
| 448 |
+
btn_output = ttk.Button(output_frame, text="Elegir", command=self.browse_output)
|
| 449 |
+
btn_output.pack(side='left', padx=5)
|
| 450 |
+
|
| 451 |
+
# Progreso
|
| 452 |
+
progress_frame = ttk.LabelFrame(self.root, text="📊 Progreso", padding=10)
|
| 453 |
+
progress_frame.pack(fill='both', expand=True, padx=10, pady=5)
|
| 454 |
+
|
| 455 |
+
self.progress_text = scrolledtext.ScrolledText(
|
| 456 |
+
progress_frame,
|
| 457 |
+
height=10,
|
| 458 |
+
bg='#1e1e1e',
|
| 459 |
+
fg='#00ff00',
|
| 460 |
+
font=('Courier', 9)
|
| 461 |
+
)
|
| 462 |
+
self.progress_text.pack(fill='both', expand=True)
|
| 463 |
+
|
| 464 |
+
# Botones de acción
|
| 465 |
+
action_frame = ttk.Frame(self.root)
|
| 466 |
+
action_frame.pack(fill='x', padx=10, pady=10)
|
| 467 |
+
|
| 468 |
+
self.btn_convert = ttk.Button(
|
| 469 |
+
action_frame,
|
| 470 |
+
text="🚀 Convertir",
|
| 471 |
+
command=self.start_conversion
|
| 472 |
+
)
|
| 473 |
+
self.btn_convert.pack(side='left', padx=5)
|
| 474 |
+
|
| 475 |
+
self.btn_cancel = ttk.Button(
|
| 476 |
+
action_frame,
|
| 477 |
+
text="⛔ Cancelar",
|
| 478 |
+
command=self.cancel_conversion,
|
| 479 |
+
state='disabled'
|
| 480 |
+
)
|
| 481 |
+
self.btn_cancel.pack(side='left', padx=5)
|
| 482 |
+
|
| 483 |
+
btn_open = ttk.Button(
|
| 484 |
+
action_frame,
|
| 485 |
+
text="📂 Abrir Carpeta",
|
| 486 |
+
command=self.open_output_folder
|
| 487 |
+
)
|
| 488 |
+
btn_open.pack(side='left', padx=5)
|
| 489 |
+
|
| 490 |
+
btn_clear = ttk.Button(
|
| 491 |
+
action_frame,
|
| 492 |
+
text="🗑️ Limpiar Log",
|
| 493 |
+
command=self.clear_log
|
| 494 |
+
)
|
| 495 |
+
btn_clear.pack(side='left', padx=5)
|
| 496 |
+
|
| 497 |
+
def browse_file(self):
|
| 498 |
+
filename = filedialog.askopenfilename(
|
| 499 |
+
title="Seleccionar video",
|
| 500 |
+
filetypes=[
|
| 501 |
+
("Videos", "*.mp4 *.mkv *.avi *.mov *.flv *.wmv *.webm"),
|
| 502 |
+
("Todos los archivos", "*.*")
|
| 503 |
+
]
|
| 504 |
+
)
|
| 505 |
+
if filename:
|
| 506 |
+
self.source_var.set(filename)
|
| 507 |
+
|
| 508 |
+
def browse_output(self):
|
| 509 |
+
directory = filedialog.askdirectory(title="Seleccionar carpeta de salida")
|
| 510 |
+
if directory:
|
| 511 |
+
self.output_var.set(directory)
|
| 512 |
+
|
| 513 |
+
def analyze_video(self):
|
| 514 |
+
source = self.source_var.get()
|
| 515 |
+
if not source:
|
| 516 |
+
messagebox.showwarning("Advertencia", "Selecciona un archivo de video primero")
|
| 517 |
+
return
|
| 518 |
+
|
| 519 |
+
if not os.path.exists(source):
|
| 520 |
+
messagebox.showerror("Error", "El archivo no existe")
|
| 521 |
+
return
|
| 522 |
+
|
| 523 |
+
self.info_text.delete('1.0', tk.END)
|
| 524 |
+
self.info_text.insert(tk.END, "🔍 Analizando video...\n\n")
|
| 525 |
+
self.root.update()
|
| 526 |
+
|
| 527 |
+
self.media_info = MediaAnalyzer.get_media_info(source)
|
| 528 |
+
|
| 529 |
+
info = f"📹 Título: {self.media_info.title or 'Sin título'}\n"
|
| 530 |
+
info += f"⏱️ Duración: {self.media_info.duration:.1f}s\n\n"
|
| 531 |
+
|
| 532 |
+
info += f"🎵 Pistas de Audio ({len(self.media_info.audio_tracks)}):\n"
|
| 533 |
+
for track in self.media_info.audio_tracks:
|
| 534 |
+
info += f" {track.display_name()}\n"
|
| 535 |
+
|
| 536 |
+
info += f"\n📝 Subtítulos ({len(self.media_info.subtitle_tracks)}):\n"
|
| 537 |
+
for track in self.media_info.subtitle_tracks:
|
| 538 |
+
info += f" {track.display_name()}\n"
|
| 539 |
+
|
| 540 |
+
self.info_text.delete('1.0', tk.END)
|
| 541 |
+
self.info_text.insert(tk.END, info)
|
| 542 |
+
|
| 543 |
+
def log_progress(self, message):
|
| 544 |
+
self.progress_text.insert(tk.END, message + "\n")
|
| 545 |
+
self.progress_text.see(tk.END)
|
| 546 |
+
self.root.update()
|
| 547 |
+
|
| 548 |
+
def start_conversion(self):
|
| 549 |
+
source = self.source_var.get()
|
| 550 |
+
if not source or not os.path.exists(source):
|
| 551 |
+
messagebox.showerror("Error", "Selecciona un archivo válido")
|
| 552 |
+
return
|
| 553 |
+
|
| 554 |
+
self.btn_convert.config(state='disabled')
|
| 555 |
+
self.btn_cancel.config(state='normal')
|
| 556 |
+
self.progress_text.delete('1.0', tk.END)
|
| 557 |
+
|
| 558 |
+
def convert_thread():
|
| 559 |
+
self.converter = VideoConverter(progress_callback=self.log_progress)
|
| 560 |
+
|
| 561 |
+
success, msg, folder = self.converter.convert(
|
| 562 |
+
source=source,
|
| 563 |
+
is_url=False,
|
| 564 |
+
mode=self.mode_var.get(),
|
| 565 |
+
output_dir=self.output_var.get(),
|
| 566 |
+
selected_audio=self.audio_index_var.get(),
|
| 567 |
+
generate_single=self.gen_single_var.get(),
|
| 568 |
+
extract_sub=self.extract_sub_var.get(),
|
| 569 |
+
sub_index=self.sub_index_var.get()
|
| 570 |
+
)
|
| 571 |
+
|
| 572 |
+
self.output_folder = folder
|
| 573 |
+
|
| 574 |
+
self.root.after(0, lambda: self.conversion_completed(success, msg))
|
| 575 |
+
|
| 576 |
+
thread = threading.Thread(target=convert_thread, daemon=True)
|
| 577 |
+
thread.start()
|
| 578 |
+
|
| 579 |
+
def cancel_conversion(self):
|
| 580 |
+
if self.converter:
|
| 581 |
+
self.converter.cancel()
|
| 582 |
+
self.log_progress("⛔ Cancelando...")
|
| 583 |
+
|
| 584 |
+
def conversion_completed(self, success, message):
|
| 585 |
+
self.btn_convert.config(state='normal')
|
| 586 |
+
self.btn_cancel.config(state='disabled')
|
| 587 |
+
|
| 588 |
+
if success:
|
| 589 |
+
messagebox.showinfo("Éxito", "Conversión completada exitosamente")
|
| 590 |
+
else:
|
| 591 |
+
messagebox.showerror("Error", f"Error en conversión: {message}")
|
| 592 |
+
|
| 593 |
+
def open_output_folder(self):
|
| 594 |
+
if self.output_folder and os.path.exists(self.output_folder):
|
| 595 |
+
subprocess.Popen(['xdg-open', self.output_folder])
|
| 596 |
+
else:
|
| 597 |
+
messagebox.showwarning("Advertencia", "No hay carpeta de salida")
|
| 598 |
+
|
| 599 |
+
def clear_log(self):
|
| 600 |
+
self.progress_text.delete('1.0', tk.END)
|
| 601 |
+
|
| 602 |
+
# ============================================================================
|
| 603 |
+
# MAIN
|
| 604 |
+
# ============================================================================
|
| 605 |
+
|
| 606 |
+
def main():
|
| 607 |
+
# Verificar FFmpeg
|
| 608 |
+
try:
|
| 609 |
+
subprocess.run(["ffmpeg", "-version"], capture_output=True, check=True)
|
| 610 |
+
except:
|
| 611 |
+
messagebox.showerror("Error", "FFmpeg no encontrado.\n\nInstala con: sudo apt install ffmpeg")
|
| 612 |
+
sys.exit(1)
|
| 613 |
+
|
| 614 |
+
root = tk.Tk()
|
| 615 |
+
app = VideoConverterGUI(root)
|
| 616 |
+
root.mainloop()
|
| 617 |
+
|
| 618 |
+
if __name__ == "__main__":
|
| 619 |
+
main()
|