Update hug.py
Browse files
hug.py
CHANGED
|
@@ -1,31 +1,20 @@
|
|
| 1 |
import os
|
| 2 |
-
import ctypes
|
| 3 |
import subprocess
|
| 4 |
import threading
|
| 5 |
import shutil
|
| 6 |
import re
|
| 7 |
import json
|
| 8 |
import uuid
|
|
|
|
|
|
|
| 9 |
import urllib.request
|
| 10 |
import urllib.parse
|
|
|
|
| 11 |
import tkinter as tk
|
| 12 |
from tkinter import ttk, filedialog, messagebox
|
| 13 |
from pathlib import Path
|
| 14 |
|
| 15 |
-
# βββ
|
| 16 |
-
def is_admin():
|
| 17 |
-
try:
|
| 18 |
-
return ctypes.windll.shell32.IsUserAnAdmin()
|
| 19 |
-
except:
|
| 20 |
-
return False
|
| 21 |
-
|
| 22 |
-
def elevate():
|
| 23 |
-
if not is_admin():
|
| 24 |
-
import sys
|
| 25 |
-
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
|
| 26 |
-
sys.exit()
|
| 27 |
-
|
| 28 |
-
# βββ HUGGINGFACE βββββββββββββββββββββββββββββββββββββββββββββ
|
| 29 |
HF_OK = False
|
| 30 |
try:
|
| 31 |
from huggingface_hub import HfApi
|
|
@@ -33,26 +22,252 @@ try:
|
|
| 33 |
except ImportError:
|
| 34 |
pass
|
| 35 |
|
| 36 |
-
# βββ
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
def safe_name(s, maxlen=120):
|
| 57 |
if not s: return "video"
|
| 58 |
return re.sub(r'[<>:"/\\|?*\x00-\x1f]', '_', s).strip()[:maxlen]
|
|
@@ -66,10 +281,21 @@ def fmt_dur(secs):
|
|
| 66 |
s = int(secs)
|
| 67 |
return f"{s//3600:02d}:{(s%3600)//60:02d}:{s%60:02d}"
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
def fetch_tmdb(url):
|
| 70 |
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
| 71 |
-
with urllib.request.urlopen(req, timeout=10) as
|
| 72 |
-
return json.loads(
|
| 73 |
|
| 74 |
def probe(source):
|
| 75 |
info = {"audio": [], "subs": [], "duration": 0.0, "title": ""}
|
|
@@ -79,25 +305,23 @@ def probe(source):
|
|
| 79 |
"-show_format", "-show_streams", source],
|
| 80 |
capture_output=True, text=True, timeout=90
|
| 81 |
)
|
| 82 |
-
if r.returncode != 0:
|
| 83 |
-
return info
|
| 84 |
data = json.loads(r.stdout)
|
| 85 |
tags = data.get("format", {}).get("tags", {})
|
| 86 |
-
info["title"]
|
| 87 |
info["duration"] = float(data.get("format", {}).get("duration", 0) or 0)
|
| 88 |
ai = si = 0
|
| 89 |
for s in data.get("streams", []):
|
| 90 |
-
t = s.get("tags", {})
|
| 91 |
-
ct = s.get("codec_type", "")
|
| 92 |
if ct == "audio":
|
| 93 |
-
info["audio"].append({"idx": ai, "codec": s.get("codec_name",
|
| 94 |
-
"lang": t.get("language",
|
| 95 |
-
"title": t.get("title",
|
| 96 |
ai += 1
|
| 97 |
elif ct == "subtitle":
|
| 98 |
-
info["subs"].append({"idx": si, "codec": s.get("codec_name",
|
| 99 |
-
"lang": t.get("language",
|
| 100 |
-
"forced": s.get("disposition",
|
| 101 |
si += 1
|
| 102 |
except Exception:
|
| 103 |
pass
|
|
@@ -107,15 +331,18 @@ NET_ARGS = [
|
|
| 107 |
"-user_agent", "Mozilla/5.0",
|
| 108 |
"-headers", "Referer: https://google.com\r\n",
|
| 109 |
"-timeout", "180000000",
|
| 110 |
-
"-reconnect", "1", "-reconnect_streamed", "1",
|
| 111 |
-
"-
|
| 112 |
-
"-
|
| 113 |
]
|
| 114 |
|
| 115 |
def run_ffmpeg(cmd, total, log_cb, progress_cb, label):
|
| 116 |
try:
|
| 117 |
-
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
| 119 |
pat = re.compile(r"time=(\d+):(\d+):(\d+)\.(\d+)")
|
| 120 |
for line in proc.stderr:
|
| 121 |
m = pat.search(line)
|
|
@@ -130,69 +357,147 @@ def run_ffmpeg(cmd, total, log_cb, progress_cb, label):
|
|
| 130 |
log_cb(f"[ERR] ffmpeg: {e}")
|
| 131 |
return False
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 136 |
try:
|
| 137 |
import sys
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
info = probe(source)
|
| 141 |
-
dur = info["duration"] if info["duration"] > 0 else 1
|
| 142 |
-
|
| 143 |
-
script_dir = Path(sys.argv[0]).parent.resolve()
|
| 144 |
-
output_root = script_dir / "Videos_Procesados"
|
| 145 |
output_root.mkdir(exist_ok=True)
|
| 146 |
-
|
| 147 |
uid = str(uuid.uuid4())[:8]
|
| 148 |
tmp = output_root / f"temp_{uid}"
|
| 149 |
tmp.mkdir(exist_ok=True, parents=True)
|
| 150 |
-
out_mp4 = tmp / f"{file_name}.mp4"
|
| 151 |
-
|
| 152 |
-
cmd = ["ffmpeg", "-y"] + extra + ["-i", source, "-map", "0:v:0"]
|
| 153 |
-
for i in range(len(info["audio"])):
|
| 154 |
-
cmd.extend(["-map", f"0:a:{i}"])
|
| 155 |
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
for i in range(len(info["audio"])):
|
| 167 |
-
cmd
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
run_ffmpeg(
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
log_cb(f"[
|
| 194 |
if HF_OK:
|
| 195 |
-
api
|
| 196 |
files = [f for f in tmp.iterdir() if f.is_file()]
|
| 197 |
for i, f in enumerate(files):
|
| 198 |
rpath = f"videos/{folder_name}/{f.name}"
|
|
@@ -200,66 +505,48 @@ def process_video(token, repo_id, source, is_url, mode,
|
|
| 200 |
progress_cb(int((i / len(files)) * 100), f"Subiendo {i+1}/{len(files)}")
|
| 201 |
try:
|
| 202 |
api.upload_file(
|
| 203 |
-
path_or_fileobj=str(f),
|
| 204 |
-
|
| 205 |
-
repo_id=repo_id,
|
| 206 |
-
repo_type="model",
|
| 207 |
-
token=token
|
| 208 |
)
|
| 209 |
except Exception as e:
|
| 210 |
-
log_cb(f" [
|
| 211 |
progress_cb(100, "Subida completa")
|
| 212 |
-
else:
|
| 213 |
-
log_cb("[β] huggingface_hub no disponible. Instala: pip install huggingface_hub")
|
| 214 |
|
| 215 |
if delete_local:
|
| 216 |
shutil.rmtree(tmp, ignore_errors=True)
|
| 217 |
-
log_cb("[
|
| 218 |
else:
|
| 219 |
final_dir = output_root / folder_name
|
| 220 |
final_dir.mkdir(exist_ok=True)
|
| 221 |
for f in tmp.iterdir():
|
| 222 |
shutil.move(str(f), str(final_dir / f.name))
|
| 223 |
shutil.rmtree(tmp, ignore_errors=True)
|
| 224 |
-
log_cb(f"[
|
| 225 |
|
| 226 |
done_cb(True)
|
| 227 |
|
| 228 |
except Exception as e:
|
| 229 |
import traceback
|
| 230 |
-
log_cb(f"[
|
| 231 |
done_cb(False)
|
| 232 |
|
| 233 |
-
|
| 234 |
-
# βββ WIDGETS CUSTOM ββββββββββββββββββββββββββββββββββββββββββ
|
| 235 |
class Spinner(tk.Canvas):
|
| 236 |
-
"""Minimal spinning loader"""
|
| 237 |
def __init__(self, parent, size=16, color=BLUE, **kwargs):
|
| 238 |
super().__init__(parent, width=size, height=size,
|
| 239 |
bg=kwargs.pop("bg", BG2), highlightthickness=0, **kwargs)
|
| 240 |
-
self.
|
| 241 |
-
self._color = color
|
| 242 |
-
self._angle = 0
|
| 243 |
self._running = False
|
| 244 |
-
self._arc
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
def start(self):
|
| 249 |
-
self._running = True
|
| 250 |
-
self._spin()
|
| 251 |
-
|
| 252 |
-
def stop(self):
|
| 253 |
-
self._running = False
|
| 254 |
-
|
| 255 |
def _spin(self):
|
| 256 |
-
if not self._running:
|
| 257 |
-
return
|
| 258 |
self._angle = (self._angle + 12) % 360
|
| 259 |
self.itemconfig(self._arc, start=self._angle)
|
| 260 |
self.after(30, self._spin)
|
| 261 |
|
| 262 |
-
|
| 263 |
class FlatEntry(tk.Entry):
|
| 264 |
def __init__(self, parent, **kwargs):
|
| 265 |
kwargs.setdefault("bg", BG3)
|
|
@@ -272,25 +559,19 @@ class FlatEntry(tk.Entry):
|
|
| 272 |
kwargs.setdefault("highlightbackground", BORDER)
|
| 273 |
super().__init__(parent, **kwargs)
|
| 274 |
|
| 275 |
-
|
| 276 |
class FlatButton(tk.Button):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
def __init__(self, parent, variant="default", **kwargs):
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
kwargs.setdefault("activeforeground", "white")
|
| 283 |
-
elif variant == "ghost":
|
| 284 |
-
kwargs.setdefault("bg", BG3)
|
| 285 |
-
kwargs.setdefault("fg", FG2)
|
| 286 |
-
kwargs.setdefault("activebackground", BORDER)
|
| 287 |
-
kwargs.setdefault("activeforeground", FG)
|
| 288 |
-
else:
|
| 289 |
-
kwargs.setdefault("bg", BG2)
|
| 290 |
-
kwargs.setdefault("fg", FG2)
|
| 291 |
-
kwargs.setdefault("activebackground", BG3)
|
| 292 |
-
kwargs.setdefault("activeforeground", FG)
|
| 293 |
-
|
| 294 |
kwargs.setdefault("relief", "flat")
|
| 295 |
kwargs.setdefault("font", FONT)
|
| 296 |
kwargs.setdefault("cursor", "hand2")
|
|
@@ -299,7 +580,6 @@ class FlatButton(tk.Button):
|
|
| 299 |
kwargs.setdefault("bd", 0)
|
| 300 |
super().__init__(parent, **kwargs)
|
| 301 |
|
| 302 |
-
|
| 303 |
class Section(tk.Frame):
|
| 304 |
def __init__(self, parent, title="", **kwargs):
|
| 305 |
kwargs.setdefault("bg", BG2)
|
|
@@ -307,32 +587,96 @@ class Section(tk.Frame):
|
|
| 307 |
if title:
|
| 308 |
hdr = tk.Frame(self, bg=BG2)
|
| 309 |
hdr.pack(fill="x", pady=(0, 8))
|
| 310 |
-
tk.Label(hdr, text=title.upper(), bg=BG2, fg=FG3,
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
class App(tk.Tk):
|
| 318 |
def __init__(self):
|
| 319 |
super().__init__()
|
| 320 |
self.title("vcpro")
|
| 321 |
-
self.geometry("
|
| 322 |
self.configure(bg=BG)
|
| 323 |
self.resizable(True, True)
|
| 324 |
-
|
| 325 |
self._queue = []
|
| 326 |
self._total_queue = 0
|
| 327 |
self._current_idx = 0
|
| 328 |
-
self.
|
| 329 |
-
|
|
|
|
| 330 |
self._build_ui()
|
| 331 |
self._update_hf_status()
|
|
|
|
|
|
|
| 332 |
|
| 333 |
-
# βββ BUILD βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 334 |
def _build_ui(self):
|
| 335 |
-
# ttk styles
|
| 336 |
s = ttk.Style(self)
|
| 337 |
s.theme_use("clam")
|
| 338 |
s.configure(".", background=BG, foreground=FG, font=FONT, borderwidth=0)
|
|
@@ -342,246 +686,286 @@ class App(tk.Tk):
|
|
| 342 |
s.map("TCheckbutton", background=[("active", BG2)], foreground=[("active", FG)])
|
| 343 |
s.configure("TRadiobutton", background=BG2, foreground=FG2, font=FONT)
|
| 344 |
s.map("TRadiobutton", background=[("active", BG2)])
|
| 345 |
-
s.configure("TCombobox", fieldbackground=BG3, background=BG3,
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
s.
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
troughcolor=BG3, background=BLUE, thickness=2, borderwidth=0)
|
| 352 |
-
|
| 353 |
-
# ββ TOPBAR ββββββββββββββββββββββββββββββββββββββββββ
|
| 354 |
top = tk.Frame(self, bg=BG, pady=14, padx=20)
|
| 355 |
top.pack(fill="x")
|
| 356 |
-
|
| 357 |
tk.Label(top, text="vcpro", bg=BG, fg=FG, font=FONT_XL).pack(side="left")
|
| 358 |
tk.Label(top, text="video converter", bg=BG, fg=FG3, font=FONT).pack(side="left", padx=(10, 0))
|
| 359 |
-
|
| 360 |
-
|
|
|
|
|
|
|
| 361 |
self._hf_dot = tk.Label(top, text="β", bg=BG, fg=FG3, font=FONT)
|
| 362 |
self._hf_dot.pack(side="right")
|
| 363 |
-
self._hf_lbl = tk.Label(top, text="hf:
|
| 364 |
-
self._hf_lbl.pack(side="right", padx=(0,
|
| 365 |
-
|
| 366 |
-
# separator
|
| 367 |
tk.Frame(self, bg=BORDER, height=1).pack(fill="x")
|
| 368 |
|
| 369 |
-
# ββ BODY βββββββββββββββββββββββββββββββββββββββββββββ
|
| 370 |
body = tk.Frame(self, bg=BG)
|
| 371 |
body.pack(fill="both", expand=True, padx=20, pady=16)
|
| 372 |
body.columnconfigure(0, weight=4, uniform="col")
|
| 373 |
body.columnconfigure(1, weight=5, uniform="col")
|
| 374 |
body.rowconfigure(0, weight=1)
|
| 375 |
-
|
| 376 |
left = tk.Frame(body, bg=BG)
|
| 377 |
right = tk.Frame(body, bg=BG)
|
| 378 |
left.grid(row=0, column=0, sticky="nsew", padx=(0, 10))
|
| 379 |
right.grid(row=0, column=1, sticky="nsew")
|
| 380 |
-
|
| 381 |
self._build_left(left)
|
| 382 |
self._build_right(right)
|
| 383 |
|
| 384 |
def _build_left(self, parent):
|
| 385 |
-
# ββ HuggingFace βββββββββββββββββββββββββββββββββββββ
|
| 386 |
-
hf = Section(parent, title="HuggingFace")
|
| 387 |
-
hf.pack(fill="x", pady=(0, 14))
|
| 388 |
-
|
| 389 |
tk.Label(hf, text="Token", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
|
|
|
| 390 |
self._hf_token = tk.StringVar()
|
| 391 |
-
tok_row =
|
| 392 |
-
tok_row.pack(fill="x", pady=(2, 8))
|
| 393 |
-
FlatEntry(tok_row, textvariable=self._hf_token, show="β’").pack(side="left", fill="x", expand=True, ipady=5)
|
| 394 |
self._btn_connect = FlatButton(tok_row, text="conectar", command=self._connect_hf)
|
| 395 |
self._btn_connect.pack(side="right", padx=(6, 0))
|
| 396 |
-
self._spinner_hf = Spinner(tok_row, bg=BG2)
|
| 397 |
-
self._spinner_hf.pack(side="right", padx=(4, 0))
|
| 398 |
-
|
| 399 |
tk.Label(hf, text="Repositorio", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
| 400 |
-
repo_row = tk.Frame(hf, bg=BG2)
|
| 401 |
-
repo_row.pack(fill="x", pady=(2, 0))
|
| 402 |
self._repo_cb = ttk.Combobox(repo_row, state="normal", font=FONT)
|
| 403 |
self._repo_cb.pack(side="left", fill="x", expand=True)
|
| 404 |
-
FlatButton(repo_row, text="
|
| 405 |
-
|
| 406 |
-
# ββ TMDb ββββββββββββββββββββββββββββββββββββββββββββ
|
| 407 |
-
td = Section(parent, title="TMDb Metadatos")
|
| 408 |
-
td.pack(fill="x", pady=(0, 14))
|
| 409 |
|
|
|
|
|
|
|
| 410 |
self._use_tmdb = tk.BooleanVar(value=False)
|
| 411 |
ttk.Checkbutton(td, text="Usar TMDb para nombres", variable=self._use_tmdb).pack(anchor="w", pady=(0, 6))
|
| 412 |
-
|
| 413 |
-
tk.
|
| 414 |
-
self._tmdb_key = tk.StringVar()
|
| 415 |
-
FlatEntry(td, textvariable=self._tmdb_key, show="β’").pack(fill="x", ipady=4, pady=(2, 8))
|
| 416 |
-
|
| 417 |
-
search_row = tk.Frame(td, bg=BG2)
|
| 418 |
-
search_row.pack(fill="x", pady=(0, 6))
|
| 419 |
self._tmdb_type = tk.StringVar(value="serie")
|
| 420 |
-
ttk.Radiobutton(search_row, text="Serie", variable=self._tmdb_type, value="serie",
|
| 421 |
-
|
|
|
|
|
|
|
| 422 |
self._tmdb_query = tk.StringVar()
|
| 423 |
FlatEntry(search_row, textvariable=self._tmdb_query).pack(side="left", fill="x", expand=True, ipady=3)
|
| 424 |
-
self._spinner_tmdb = Spinner(search_row, bg=BG2)
|
| 425 |
-
self._spinner_tmdb.pack(side="right", padx=4)
|
| 426 |
FlatButton(search_row, text="buscar", command=self._search_tmdb).pack(side="right")
|
| 427 |
-
|
| 428 |
self._tmdb_res_cb = ttk.Combobox(td, state="readonly", font=FONT)
|
| 429 |
self._tmdb_res_cb.pack(fill="x", pady=(0, 6))
|
| 430 |
self._tmdb_res_cb.bind("<<ComboboxSelected>>", self._on_tmdb_res_select)
|
| 431 |
-
|
| 432 |
-
ep_row = tk.Frame(td, bg=BG2)
|
| 433 |
-
ep_row.pack(fill="x")
|
| 434 |
self._tmdb_season_cb = ttk.Combobox(ep_row, state="disabled", font=FONT, width=14)
|
| 435 |
self._tmdb_season_cb.pack(side="left", padx=(0, 6))
|
| 436 |
self._tmdb_season_cb.bind("<<ComboboxSelected>>", self._on_tmdb_season_select)
|
| 437 |
self._tmdb_ep_cb = ttk.Combobox(ep_row, state="disabled", font=FONT)
|
| 438 |
self._tmdb_ep_cb.pack(side="left", fill="x", expand=True)
|
| 439 |
-
|
| 440 |
self._tmdb_id_map = {}
|
| 441 |
self._tmdb_episodes = []
|
| 442 |
|
| 443 |
-
# ββ Opciones βββββββββββββββββββββββββββββββββββββββββ
|
| 444 |
-
opt = Section(parent, title="Opciones")
|
| 445 |
-
opt.pack(fill="x", pady=(0, 14))
|
| 446 |
-
|
| 447 |
tk.Label(opt, text="Nombre manual", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
| 448 |
self._manual_name = tk.StringVar()
|
| 449 |
FlatEntry(opt, textvariable=self._manual_name).pack(fill="x", ipady=4, pady=(2, 10))
|
| 450 |
-
|
| 451 |
-
tk.
|
| 452 |
-
mode_row = tk.Frame(opt, bg=BG2)
|
| 453 |
-
mode_row.pack(fill="x", pady=(2, 10))
|
| 454 |
self._mode = tk.StringVar(value="Copy + MP3")
|
| 455 |
for m in ["Copy + MP3", "Copy + FLAC", "H264 1080p"]:
|
| 456 |
ttk.Radiobutton(mode_row, text=m, variable=self._mode, value=m).pack(side="left", padx=(0, 10))
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 460 |
self._gen_single = tk.BooleanVar(value=False)
|
| 461 |
self._ext_sub = tk.BooleanVar(value=False)
|
| 462 |
self._del_local = tk.BooleanVar(value=True)
|
| 463 |
-
ttk.Checkbutton(chk_row, text="Extraer audio",
|
| 464 |
-
ttk.Checkbutton(chk_row, text="Extraer
|
| 465 |
-
ttk.Checkbutton(chk_row, text="Borrar locales",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 466 |
|
| 467 |
def _build_right(self, parent):
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
src.pack(fill="x", pady=(0, 10))
|
| 471 |
-
|
| 472 |
-
tab_row = tk.Frame(src, bg=BG2)
|
| 473 |
-
tab_row.pack(fill="x", pady=(0, 8))
|
| 474 |
self._src_mode = tk.StringVar(value="url")
|
| 475 |
-
self._btn_tab_url
|
| 476 |
-
|
|
|
|
|
|
|
| 477 |
self._btn_tab_url.pack(side="left")
|
| 478 |
self._btn_tab_file.pack(side="left", padx=(4, 0))
|
| 479 |
|
| 480 |
-
|
|
|
|
|
|
|
| 481 |
self._file_frame = tk.Frame(src, bg=BG2)
|
| 482 |
self._file_var = tk.StringVar()
|
|
|
|
| 483 |
FlatEntry(self._file_frame, textvariable=self._file_var).pack(side="left", fill="x", expand=True, ipady=4)
|
| 484 |
FlatButton(self._file_frame, text="examinar", command=self._browse).pack(side="right", padx=(6, 0))
|
|
|
|
| 485 |
|
| 486 |
-
# url box
|
| 487 |
self._url_frame = tk.Frame(src, bg=BG2)
|
| 488 |
url_inner = tk.Frame(self._url_frame, bg=BG3, highlightthickness=1, highlightbackground=BORDER)
|
| 489 |
url_inner.pack(fill="x")
|
| 490 |
self._url_text = tk.Text(url_inner, bg=BG3, fg=FG, insertbackground=FG,
|
| 491 |
-
|
| 492 |
-
|
| 493 |
sb = ttk.Scrollbar(url_inner, command=self._url_text.yview)
|
| 494 |
self._url_text.configure(yscrollcommand=sb.set)
|
| 495 |
self._url_text.pack(side="left", fill="both", expand=True)
|
| 496 |
sb.pack(side="right", fill="y")
|
| 497 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
self._switch_src("url")
|
| 499 |
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
info_row.pack(fill="x")
|
| 503 |
-
self._spinner_probe = Spinner(info_row, bg=BG2)
|
| 504 |
-
self._spinner_probe.pack(side="left")
|
| 505 |
self._lbl_info = tk.Label(info_row, text="sin analizar", bg=BG2, fg=FG3, font=FONT_SM, anchor="w")
|
| 506 |
self._lbl_info.pack(side="left", padx=(6, 0))
|
| 507 |
FlatButton(info_row, text="analizar", command=self._do_analyze).pack(side="right")
|
| 508 |
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
tr_row = tk.Frame(tr, bg=BG2)
|
| 513 |
-
tr_row.pack(fill="x")
|
| 514 |
-
tk.Label(tr_row, text="Audio", bg=BG2, fg=FG3, font=FONT_SM, width=5, anchor="w").pack(side="left")
|
| 515 |
-
self._aud_cb = ttk.Combobox(tr_row, state="readonly", font=FONT)
|
| 516 |
-
self._aud_cb.pack(side="left", fill="x", expand=True, padx=(4, 14))
|
| 517 |
-
tk.Label(tr_row, text="Sub", bg=BG2, fg=FG3, font=FONT_SM, width=4, anchor="w").pack(side="left")
|
| 518 |
-
self._sub_cb = ttk.Combobox(tr_row, state="readonly", font=FONT)
|
| 519 |
-
self._sub_cb.pack(side="left", fill="x", expand=True, padx=(4, 0))
|
| 520 |
-
|
| 521 |
-
# ββ Progreso + Log βββββββββββββββββββββββββββββββββββ
|
| 522 |
-
pg = Section(parent, title="Progreso")
|
| 523 |
-
pg.pack(fill="both", expand=True, pady=(0, 0))
|
| 524 |
-
|
| 525 |
-
prog_row = tk.Frame(pg, bg=BG2)
|
| 526 |
-
prog_row.pack(fill="x", pady=(0, 4))
|
| 527 |
-
self._spinner_proc = Spinner(prog_row, bg=BG2)
|
| 528 |
-
self._spinner_proc.pack(side="left")
|
| 529 |
self._lbl_prog = tk.Label(prog_row, text="esperando", bg=BG2, fg=FG3, font=FONT_SM, anchor="w")
|
| 530 |
self._lbl_prog.pack(side="left", padx=(6, 0))
|
| 531 |
self._lbl_queue = tk.Label(prog_row, text="", bg=BG2, fg=FG3, font=FONT_SM)
|
| 532 |
self._lbl_queue.pack(side="right")
|
| 533 |
-
|
| 534 |
self._pbar = ttk.Progressbar(pg, mode="determinate", style="Horizontal.TProgressbar")
|
| 535 |
self._pbar.pack(fill="x", pady=(0, 8))
|
| 536 |
-
|
| 537 |
log_wrap = tk.Frame(pg, bg=BG3, highlightthickness=1, highlightbackground=BORDER)
|
| 538 |
log_wrap.pack(fill="both", expand=True)
|
| 539 |
-
self._log_txt = tk.Text(log_wrap, bg=BG3, fg="#4ade80",
|
| 540 |
-
|
| 541 |
-
state="disabled", padx=10, pady=8,
|
| 542 |
-
cursor="arrow")
|
| 543 |
sb2 = ttk.Scrollbar(log_wrap, command=self._log_txt.yview)
|
| 544 |
self._log_txt.configure(yscrollcommand=sb2.set)
|
| 545 |
sb2.pack(side="right", fill="y")
|
| 546 |
self._log_txt.pack(fill="both", expand=True)
|
| 547 |
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
|
| 556 |
-
# βββ HF ββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 557 |
def _update_hf_status(self):
|
| 558 |
if HF_OK:
|
| 559 |
self._hf_dot.configure(fg=GREEN)
|
| 560 |
-
self._hf_lbl.configure(text="hf:
|
| 561 |
else:
|
| 562 |
self._hf_dot.configure(fg=RED)
|
| 563 |
-
self._hf_lbl.configure(text="hf:
|
| 564 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
def _connect_hf(self):
|
| 566 |
t = self._hf_token.get().strip()
|
| 567 |
-
if not t:
|
| 568 |
-
self._log("[!] Ingresa un token primero")
|
| 569 |
-
return
|
| 570 |
self._spinner_hf.start()
|
| 571 |
self._btn_connect.configure(state="disabled")
|
| 572 |
-
self._log("[
|
| 573 |
-
|
| 574 |
def _go():
|
| 575 |
try:
|
| 576 |
-
if not HF_OK:
|
| 577 |
-
raise ImportError("huggingface_hub no instalado")
|
| 578 |
api = HfApi()
|
| 579 |
info = api.whoami(token=t)
|
| 580 |
-
|
| 581 |
-
self.after(0, lambda: self._log(f"[β] Conectado como: {user}"))
|
| 582 |
self.after(0, self._load_repos)
|
| 583 |
except Exception as e:
|
| 584 |
-
self.after(0, lambda: self._log(f"[
|
| 585 |
finally:
|
| 586 |
self.after(0, self._spinner_hf.stop)
|
| 587 |
self.after(0, lambda: self._btn_connect.configure(state="normal"))
|
|
@@ -589,37 +973,29 @@ class App(tk.Tk):
|
|
| 589 |
|
| 590 |
def _load_repos(self):
|
| 591 |
t = self._hf_token.get().strip()
|
| 592 |
-
if not t or not HF_OK:
|
| 593 |
-
self._log("[!] Token requerido y huggingface_hub instalado")
|
| 594 |
-
return
|
| 595 |
self._spinner_hf.start()
|
| 596 |
-
self._log("[
|
| 597 |
-
|
| 598 |
def _go():
|
| 599 |
try:
|
| 600 |
api = HfApi()
|
| 601 |
whoami = api.whoami(token=t)
|
| 602 |
author = whoami.get("name", "")
|
| 603 |
-
|
| 604 |
-
models = list(api.list_models(author=author, token=t))
|
| 605 |
-
repos = [m.modelId for m in models]
|
| 606 |
-
# TambiΓ©n datasets
|
| 607 |
try:
|
| 608 |
-
|
| 609 |
-
repos += [d.id for d in datasets]
|
| 610 |
except Exception:
|
| 611 |
pass
|
| 612 |
self.after(0, lambda: self._repo_cb.configure(values=repos))
|
| 613 |
-
if repos:
|
| 614 |
-
|
| 615 |
-
self.after(0, lambda: self._log(f"[β] {len(repos)} repositorios cargados"))
|
| 616 |
except Exception as e:
|
| 617 |
-
self.after(0, lambda: self._log(f"[
|
| 618 |
finally:
|
| 619 |
self.after(0, self._spinner_hf.stop)
|
| 620 |
threading.Thread(target=_go, daemon=True).start()
|
| 621 |
|
| 622 |
-
# ββ
|
| 623 |
def _tmdb_clear(self, *_):
|
| 624 |
self._tmdb_res_cb.set("")
|
| 625 |
self._tmdb_res_cb.configure(values=[])
|
|
@@ -629,25 +1005,21 @@ class App(tk.Tk):
|
|
| 629 |
self._tmdb_ep_cb.configure(state="disabled")
|
| 630 |
|
| 631 |
def _search_tmdb(self):
|
| 632 |
-
k = self._tmdb_key.get().strip()
|
| 633 |
q = self._tmdb_query.get().strip()
|
| 634 |
-
if not
|
| 635 |
-
self._log("[!] API Key y bΓΊsqueda requeridos")
|
| 636 |
-
return
|
| 637 |
t = "movie" if self._tmdb_type.get() == "pelicula" else "tv"
|
| 638 |
-
url = (f"https://api.themoviedb.org/3/search/{t}"
|
| 639 |
-
f"
|
| 640 |
self._spinner_tmdb.start()
|
| 641 |
-
|
| 642 |
def _go():
|
| 643 |
try:
|
| 644 |
data = fetch_tmdb(url)
|
| 645 |
res, self._tmdb_id_map = [], {}
|
| 646 |
for r in data.get("results", [])[:15]:
|
| 647 |
title = r.get("title") or r.get("name", "?")
|
| 648 |
-
dt
|
| 649 |
-
yr
|
| 650 |
-
lbl
|
| 651 |
res.append(lbl)
|
| 652 |
self._tmdb_id_map[lbl] = r.get("id")
|
| 653 |
self.after(0, lambda: self._tmdb_res_cb.configure(values=res))
|
|
@@ -655,7 +1027,7 @@ class App(tk.Tk):
|
|
| 655 |
self.after(0, lambda: self._tmdb_res_cb.set(res[0]))
|
| 656 |
self.after(0, self._on_tmdb_res_select)
|
| 657 |
except Exception as e:
|
| 658 |
-
self.after(0, lambda: self._log(f"[
|
| 659 |
finally:
|
| 660 |
self.after(0, self._spinner_tmdb.stop)
|
| 661 |
threading.Thread(target=_go, daemon=True).start()
|
|
@@ -666,54 +1038,49 @@ class App(tk.Tk):
|
|
| 666 |
self._tmdb_ep_cb.configure(state="disabled")
|
| 667 |
return
|
| 668 |
self._tmdb_season_cb.configure(state="readonly")
|
| 669 |
-
|
| 670 |
-
tid = self._tmdb_id_map.get(lbl)
|
| 671 |
if not tid: return
|
| 672 |
-
url =
|
| 673 |
-
f"?api_key={self._tmdb_key.get().strip()}&language=es-MX")
|
| 674 |
self._spinner_tmdb.start()
|
| 675 |
-
|
| 676 |
def _go():
|
| 677 |
try:
|
| 678 |
data = fetch_tmdb(url)
|
| 679 |
-
seasons = [f"Temporada {s['season_number']}"
|
| 680 |
-
for s in data.get("seasons", []) if s["season_number"] > 0]
|
| 681 |
self.after(0, lambda: self._tmdb_season_cb.configure(values=seasons))
|
| 682 |
if seasons:
|
| 683 |
self.after(0, lambda: self._tmdb_season_cb.set(seasons[0]))
|
| 684 |
self.after(0, self._on_tmdb_season_select)
|
| 685 |
except Exception as e:
|
| 686 |
-
self.after(0, lambda: self._log(f"[
|
| 687 |
finally:
|
| 688 |
self.after(0, self._spinner_tmdb.stop)
|
| 689 |
threading.Thread(target=_go, daemon=True).start()
|
| 690 |
|
| 691 |
def _on_tmdb_season_select(self, *_):
|
| 692 |
self._tmdb_ep_cb.configure(state="readonly")
|
| 693 |
-
tid
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
url = (f"https://api.themoviedb.org/3/tv/{tid}/season/{s_num}"
|
| 697 |
-
f"?api_key={self._tmdb_key.get().strip()}&language=es-MX")
|
| 698 |
self._spinner_tmdb.start()
|
| 699 |
-
|
| 700 |
def _go():
|
| 701 |
try:
|
| 702 |
data = fetch_tmdb(url)
|
| 703 |
-
self._tmdb_episodes = [{"num": e["episode_number"], "name": e["name"]}
|
| 704 |
-
for e in data.get("episodes", [])]
|
| 705 |
ep_strs = [f"Ep {e['num']:02d}: {e['name']}" for e in self._tmdb_episodes]
|
| 706 |
self.after(0, lambda: self._tmdb_ep_cb.configure(values=ep_strs))
|
| 707 |
if ep_strs: self.after(0, lambda: self._tmdb_ep_cb.set(ep_strs[0]))
|
| 708 |
except Exception as e:
|
| 709 |
-
self.after(0, lambda: self._log(f"[
|
| 710 |
finally:
|
| 711 |
self.after(0, self._spinner_tmdb.stop)
|
| 712 |
threading.Thread(target=_go, daemon=True).start()
|
| 713 |
|
| 714 |
-
# ββ
|
| 715 |
def _switch_src(self, mode):
|
| 716 |
self._src_mode.set(mode)
|
|
|
|
|
|
|
|
|
|
| 717 |
if mode == "file":
|
| 718 |
self._url_frame.pack_forget()
|
| 719 |
self._file_frame.pack(fill="x", pady=(0, 6))
|
|
@@ -727,71 +1094,215 @@ class App(tk.Tk):
|
|
| 727 |
|
| 728 |
def _browse(self):
|
| 729 |
p = filedialog.askopenfilename(
|
| 730 |
-
filetypes=[("Video", "*.mp4 *.mkv *.avi *.mov *.ts"), ("Todos", "*.*")])
|
| 731 |
-
if p:
|
| 732 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 733 |
|
| 734 |
def _get_sources(self):
|
| 735 |
if self._src_mode.get() == "file":
|
| 736 |
p = self._file_var.get().strip()
|
| 737 |
return ([p] if p else []), False
|
| 738 |
else:
|
| 739 |
-
|
| 740 |
-
return srcs, True
|
| 741 |
|
| 742 |
-
# ββ
|
| 743 |
def _log(self, msg):
|
| 744 |
self._log_txt.configure(state="normal")
|
| 745 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
self._log_txt.see("end")
|
| 747 |
self._log_txt.configure(state="disabled")
|
| 748 |
|
| 749 |
def _set_progress(self, pct, label=""):
|
| 750 |
self._pbar["value"] = pct
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
self._lbl_prog.configure(text=label)
|
| 752 |
self.update_idletasks()
|
| 753 |
|
| 754 |
-
# ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
def _do_analyze(self):
|
| 756 |
sources, _ = self._get_sources()
|
| 757 |
if not sources:
|
| 758 |
-
messagebox.showwarning("vcpro", "Selecciona
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 759 |
return
|
|
|
|
|
|
|
| 760 |
self._spinner_probe.start()
|
| 761 |
self._lbl_info.configure(text="analizando...", fg=FG3)
|
| 762 |
-
|
| 763 |
def _go():
|
| 764 |
-
info = probe(
|
| 765 |
-
ac = [f"[{t['idx']}] {t['lang']}
|
| 766 |
-
sc = [f"[{t['idx']}] {t['lang']}
|
| 767 |
self.after(0, lambda: self._aud_cb.configure(values=ac))
|
| 768 |
self.after(0, lambda: self._sub_cb.configure(values=sc))
|
| 769 |
if ac: self.after(0, lambda: self._aud_cb.set(ac[0]))
|
| 770 |
if sc: self.after(0, lambda: self._sub_cb.set(sc[0]))
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
else:
|
| 774 |
-
txt = (f"{info['title'] or 'sin tΓtulo'} Β· "
|
| 775 |
-
f"{fmt_dur(info['duration'])} Β· "
|
| 776 |
-
f"{len(ac)}aud Β· {len(sc)}sub")
|
| 777 |
self.after(0, lambda: self._lbl_info.configure(text=txt, fg=GREEN))
|
| 778 |
self.after(0, self._spinner_probe.stop)
|
| 779 |
threading.Thread(target=_go, daemon=True).start()
|
| 780 |
|
| 781 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
def _do_process(self):
|
| 783 |
-
tok = self._hf_token.get().strip()
|
| 784 |
-
rep = self._repo_cb.get().strip()
|
| 785 |
sources, is_url = self._get_sources()
|
| 786 |
if not tok or not rep or not sources:
|
| 787 |
-
messagebox.showwarning("vcpro", "Faltan
|
| 788 |
return
|
| 789 |
-
|
| 790 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 791 |
self._total_queue = len(self._queue)
|
| 792 |
self._current_idx = 0
|
| 793 |
-
|
| 794 |
self._btn_proc.configure(state="disabled", bg=FG3)
|
|
|
|
| 795 |
self._log_txt.configure(state="normal")
|
| 796 |
self._log_txt.delete("1.0", "end")
|
| 797 |
self._log_txt.configure(state="disabled")
|
|
@@ -799,174 +1310,138 @@ class App(tk.Tk):
|
|
| 799 |
self._process_next()
|
| 800 |
|
| 801 |
def _process_next(self):
|
| 802 |
-
if not self._queue:
|
| 803 |
self._btn_proc.configure(state="normal", bg=BLUE)
|
|
|
|
| 804 |
self._lbl_queue.configure(text="")
|
| 805 |
self._spinner_proc.stop()
|
| 806 |
-
self.
|
| 807 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
return
|
| 809 |
|
| 810 |
src = self._queue.pop(0)
|
| 811 |
self._current_idx += 1
|
| 812 |
-
self._lbl_queue.configure(
|
| 813 |
-
|
| 814 |
-
self._log(f"
|
|
|
|
| 815 |
|
| 816 |
-
# ββ Nombres TMDb / manual / auto βββββββββββββββββββββ
|
| 817 |
folder_name = "Bulk_Upload"
|
| 818 |
-
file_name
|
| 819 |
|
| 820 |
if self._use_tmdb.get() and self._tmdb_res_cb.get():
|
| 821 |
base = self._tmdb_res_cb.get().split(" (")[0]
|
| 822 |
if self._tmdb_type.get() == "pelicula":
|
| 823 |
folder_name = to_leet(base)
|
| 824 |
-
file_name
|
| 825 |
-
|
| 826 |
else:
|
| 827 |
-
|
| 828 |
-
s_num = s_raw.split(" ")[1] if s_raw else "1"
|
| 829 |
folder_name = to_leet(f"{base} S{int(s_num):02d}")
|
| 830 |
-
|
| 831 |
-
tgt = ep_idx + self._current_idx - 1
|
| 832 |
if tgt < len(self._tmdb_episodes):
|
| 833 |
ep = self._tmdb_episodes[tgt]
|
| 834 |
-
file_name = to_leet(
|
| 835 |
-
f"{base} S{int(s_num):02d}E{ep['num']:02d} {ep['name']}")
|
| 836 |
else:
|
| 837 |
file_name = to_leet(f"{base} S{int(s_num):02d}E{tgt+1:02d}")
|
| 838 |
else:
|
| 839 |
m = self._manual_name.get().strip()
|
| 840 |
if m:
|
| 841 |
folder_name = to_leet(m)
|
| 842 |
-
file_name
|
| 843 |
-
|
| 844 |
-
elif self._src_mode.get() == "file":
|
| 845 |
base = Path(src).stem
|
| 846 |
folder_name = to_leet(base)
|
| 847 |
-
file_name
|
| 848 |
|
| 849 |
-
|
| 850 |
-
|
| 851 |
-
if self._aud_cb.get(): ai = int(self._aud_cb.get().split("]")[0].strip("["))
|
| 852 |
-
if self._sub_cb.get(): si = int(self._sub_cb.get().split("]")[0].strip("["))
|
| 853 |
-
except Exception:
|
| 854 |
-
pass
|
| 855 |
|
| 856 |
_, is_url_chk = self._get_sources()
|
|
|
|
| 857 |
|
| 858 |
threading.Thread(
|
| 859 |
target=process_video,
|
| 860 |
args=(
|
| 861 |
self._hf_token.get().strip(),
|
| 862 |
self._repo_cb.get().strip(),
|
| 863 |
-
src, is_url_chk,
|
| 864 |
-
self._mode.get(),
|
| 865 |
ai, self._gen_single.get(),
|
| 866 |
self._ext_sub.get(), si,
|
| 867 |
self._del_local.get(),
|
| 868 |
-
folder_name, file_name,
|
| 869 |
lambda m: self.after(0, self._log, m),
|
| 870 |
lambda p, l: self.after(0, self._set_progress, p, l),
|
| 871 |
lambda ok: self.after(0, self._process_next),
|
|
|
|
| 872 |
),
|
| 873 |
daemon=True
|
| 874 |
).start()
|
| 875 |
|
| 876 |
-
|
| 877 |
-
# βββ SISTEMA DE AUTO-INSTALACIΓN Y REINICIO ββββββββββββββββ
|
| 878 |
def run_installer_and_restart():
|
| 879 |
-
|
| 880 |
-
Muestra una ventana de carga minimalista, instala las dependencias
|
| 881 |
-
faltantes mediante pip y luego reinicia el script automΓ‘ticamente.
|
| 882 |
-
"""
|
| 883 |
root = tk.Tk()
|
| 884 |
root.title("vcpro - Setup")
|
| 885 |
-
root.geometry("
|
| 886 |
root.configure(bg=BG)
|
| 887 |
root.resizable(False, False)
|
| 888 |
-
|
| 889 |
-
# Centrar en pantalla
|
| 890 |
root.update_idletasks()
|
| 891 |
-
x = (root.winfo_screenwidth() // 2) -
|
| 892 |
-
y = (root.winfo_screenheight() // 2) -
|
| 893 |
root.geometry(f"+{x}+{y}")
|
| 894 |
-
|
| 895 |
-
tk.Label(root, text="
|
| 896 |
-
|
| 897 |
-
|
| 898 |
-
|
| 899 |
-
|
| 900 |
-
|
| 901 |
-
spinner.pack(pady=15)
|
| 902 |
-
spinner.start()
|
| 903 |
-
|
| 904 |
-
def install_thread():
|
| 905 |
-
import sys
|
| 906 |
-
missing_packages = ["huggingface_hub"]
|
| 907 |
-
cmd = [sys.executable, "-m", "pip", "install"] + missing_packages
|
| 908 |
-
|
| 909 |
try:
|
| 910 |
-
|
| 911 |
-
|
| 912 |
-
|
| 913 |
-
stderr=subprocess.STDOUT,
|
| 914 |
-
|
| 915 |
-
creationflags=subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0
|
| 916 |
)
|
| 917 |
-
|
| 918 |
-
|
| 919 |
-
|
| 920 |
-
|
| 921 |
-
|
| 922 |
-
|
| 923 |
-
|
| 924 |
-
process.wait()
|
| 925 |
-
|
| 926 |
-
if process.returncode == 0:
|
| 927 |
-
root.after(0, lbl_status.configure, {"text": "InstalaciΓ³n completa. Reiniciando...", "fg": GREEN})
|
| 928 |
-
root.update()
|
| 929 |
-
import time
|
| 930 |
-
time.sleep(1.5) # Pausa para que el usuario lea el mensaje
|
| 931 |
-
|
| 932 |
-
# REINICIO AUTOMΓTICO DEL SCRIPT
|
| 933 |
os.execv(sys.executable, ['python'] + sys.argv)
|
| 934 |
else:
|
| 935 |
-
root.after(0,
|
| 936 |
-
root.after(0,
|
| 937 |
except Exception as e:
|
| 938 |
-
root.after(0,
|
| 939 |
-
root.after(0,
|
| 940 |
-
|
| 941 |
-
threading.Thread(target=install_thread, daemon=True).start()
|
| 942 |
root.mainloop()
|
| 943 |
-
sys.exit()
|
| 944 |
-
|
| 945 |
|
|
|
|
| 946 |
if __name__ == "__main__":
|
| 947 |
-
# 1. Verificar si faltan dependencias de Python
|
| 948 |
try:
|
| 949 |
import huggingface_hub
|
| 950 |
-
|
| 951 |
except ImportError:
|
| 952 |
-
|
| 953 |
|
| 954 |
-
|
| 955 |
-
if not DEPENDENCIES_OK:
|
| 956 |
run_installer_and_restart()
|
| 957 |
else:
|
| 958 |
-
# 3. Si todo estΓ‘ bien, verificar FFmpeg (opcional pero recomendado) y lanzar la App
|
| 959 |
-
if not shutil.which("ffmpeg"):
|
| 960 |
-
# Creamos la app para mostrar el warning, pero no bloqueamos el inicio si no quieren instalarlo aΓΊn
|
| 961 |
-
pass
|
| 962 |
-
|
| 963 |
-
# elevate() # Descomentar si se necesitan permisos admin
|
| 964 |
app = App()
|
| 965 |
-
|
| 966 |
-
# Aviso amistoso de FFmpeg (solo si no estΓ‘ en el sistema)
|
| 967 |
if not shutil.which("ffmpeg"):
|
| 968 |
-
app._log("[
|
| 969 |
-
|
| 970 |
-
app._log("[
|
| 971 |
-
|
|
|
|
| 972 |
app.mainloop()
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import subprocess
|
| 3 |
import threading
|
| 4 |
import shutil
|
| 5 |
import re
|
| 6 |
import json
|
| 7 |
import uuid
|
| 8 |
+
import time
|
| 9 |
+
import socket
|
| 10 |
import urllib.request
|
| 11 |
import urllib.parse
|
| 12 |
+
import urllib.error
|
| 13 |
import tkinter as tk
|
| 14 |
from tkinter import ttk, filedialog, messagebox
|
| 15 |
from pathlib import Path
|
| 16 |
|
| 17 |
+
# βββ HUGGINGFACE ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
HF_OK = False
|
| 19 |
try:
|
| 20 |
from huggingface_hub import HfApi
|
|
|
|
| 22 |
except ImportError:
|
| 23 |
pass
|
| 24 |
|
| 25 |
+
# βββ TMDB API KEY (HARDCODEADA) ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 26 |
+
TMDB_API_KEY = "3633a0416ea666f002ec317f40bdcf58"
|
| 27 |
+
|
| 28 |
+
# βββ ARIA2C (UNICO BACKEND PARA TORRENTS) ββββββββββββββββββββββββββββββββββββ
|
| 29 |
+
def get_aria2_path():
|
| 30 |
+
import sys
|
| 31 |
+
script_dir = Path(sys.argv[0]).parent.resolve()
|
| 32 |
+
for name in ["aria2c.exe", "aria2c"]:
|
| 33 |
+
local_path = script_dir / name
|
| 34 |
+
if local_path.exists():
|
| 35 |
+
return str(local_path)
|
| 36 |
+
aria2_folder = script_dir / "aria2"
|
| 37 |
+
if aria2_folder.exists():
|
| 38 |
+
for name in ["aria2c.exe", "aria2c"]:
|
| 39 |
+
local_path = aria2_folder / name
|
| 40 |
+
if local_path.exists():
|
| 41 |
+
return str(local_path)
|
| 42 |
+
if shutil.which("aria2c"):
|
| 43 |
+
return "aria2c"
|
| 44 |
+
return None
|
| 45 |
+
|
| 46 |
+
ARIA2_PATH = get_aria2_path()
|
| 47 |
+
ARIA2_OK = ARIA2_PATH is not None
|
| 48 |
+
|
| 49 |
+
def find_free_port():
|
| 50 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
| 51 |
+
s.bind(('127.0.0.1', 0))
|
| 52 |
+
return s.getsockname()[1]
|
| 53 |
+
|
| 54 |
+
def aria2_rpc_call(port, secret, method, params=None):
|
| 55 |
+
if params is None:
|
| 56 |
+
params = []
|
| 57 |
+
payload = {
|
| 58 |
+
"jsonrpc": "2.0",
|
| 59 |
+
"id": str(uuid.uuid4())[:8],
|
| 60 |
+
"method": f"aria2.{method}",
|
| 61 |
+
"params": [f"token:{secret}"] + params
|
| 62 |
+
}
|
| 63 |
+
try:
|
| 64 |
+
data = json.dumps(payload).encode()
|
| 65 |
+
req = urllib.request.Request(
|
| 66 |
+
f"http://127.0.0.1:{port}/jsonrpc",
|
| 67 |
+
data=data,
|
| 68 |
+
headers={"Content-Type": "application/json"},
|
| 69 |
+
method="POST"
|
| 70 |
+
)
|
| 71 |
+
with urllib.request.urlopen(req, timeout=10) as r:
|
| 72 |
+
return json.loads(r.read().decode())
|
| 73 |
+
except Exception as e:
|
| 74 |
+
return {"error": str(e)}
|
| 75 |
+
|
| 76 |
+
def get_magnet_info(magnet: str, log_cb, progress_cb, cancel_flag, timeout=120):
|
| 77 |
+
if not ARIA2_OK:
|
| 78 |
+
log_cb("[X] aria2c no encontrado")
|
| 79 |
+
return None
|
| 80 |
+
import sys
|
| 81 |
+
script_dir = Path(sys.argv[0]).parent.resolve()
|
| 82 |
+
tmp_dir = script_dir / "Videos_Procesados" / f"magnet_meta_{uuid.uuid4().hex[:8]}"
|
| 83 |
+
tmp_dir.mkdir(parents=True, exist_ok=True)
|
| 84 |
+
port = find_free_port()
|
| 85 |
+
secret = uuid.uuid4().hex[:12]
|
| 86 |
+
cmd = [
|
| 87 |
+
ARIA2_PATH,
|
| 88 |
+
f"--rpc-listen-port={port}",
|
| 89 |
+
f"--rpc-secret={secret}",
|
| 90 |
+
"--enable-rpc=true",
|
| 91 |
+
"--rpc-listen-all=false",
|
| 92 |
+
"--seed-time=0",
|
| 93 |
+
"--file-allocation=none",
|
| 94 |
+
"--bt-max-peers=50",
|
| 95 |
+
"--bt-tracker-connect-timeout=15",
|
| 96 |
+
"--bt-tracker-timeout=15",
|
| 97 |
+
"--dir", str(tmp_dir),
|
| 98 |
+
"--summary-interval=1",
|
| 99 |
+
"--console-log-level=warn",
|
| 100 |
+
magnet.strip()
|
| 101 |
+
]
|
| 102 |
+
log_cb("[aria2] Obteniendo metadata del magnet...")
|
| 103 |
+
log_cb(f"[aria2] Puerto RPC: {port}")
|
| 104 |
+
proc = None
|
| 105 |
+
try:
|
| 106 |
+
creationflags = subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0
|
| 107 |
+
proc = subprocess.Popen(
|
| 108 |
+
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 109 |
+
universal_newlines=True, bufsize=1, creationflags=creationflags
|
| 110 |
+
)
|
| 111 |
+
gid = None
|
| 112 |
+
start_time = time.time()
|
| 113 |
+
files_info = None
|
| 114 |
+
waited = 0
|
| 115 |
+
while time.time() - start_time < timeout:
|
| 116 |
+
if cancel_flag[0]:
|
| 117 |
+
log_cb("[!] Cancelado")
|
| 118 |
+
break
|
| 119 |
+
if proc.poll() is not None:
|
| 120 |
+
log_cb("[!] aria2 se cerro inesperadamente")
|
| 121 |
+
break
|
| 122 |
+
result = aria2_rpc_call(port, secret, "tellActive")
|
| 123 |
+
if "error" not in result and "result" in result:
|
| 124 |
+
active = result["result"]
|
| 125 |
+
if active:
|
| 126 |
+
gid = active[0].get("gid")
|
| 127 |
+
if gid:
|
| 128 |
+
result = aria2_rpc_call(port, secret, "tellStatus", [gid, ["files", "bittorrent", "status"]])
|
| 129 |
+
if "error" not in result and "result" in result:
|
| 130 |
+
status = result["result"]
|
| 131 |
+
bt = status.get("bittorrent", {})
|
| 132 |
+
info_dict = bt.get("info", {})
|
| 133 |
+
if info_dict and "name" in info_dict:
|
| 134 |
+
files = status.get("files", [])
|
| 135 |
+
files_info = {
|
| 136 |
+
"name": info_dict.get("name", ""),
|
| 137 |
+
"files": [
|
| 138 |
+
{
|
| 139 |
+
"index": f.get("index", 0),
|
| 140 |
+
"path": f.get("path", "").replace(str(tmp_dir) + "/", ""),
|
| 141 |
+
"length": int(f.get("length", 0)),
|
| 142 |
+
"selected": f.get("selected", "true") == "true"
|
| 143 |
+
}
|
| 144 |
+
for f in files
|
| 145 |
+
]
|
| 146 |
+
}
|
| 147 |
+
log_cb(f"[OK] Metadata: {info_dict.get('name')}")
|
| 148 |
+
log_cb(f"[OK] {len(files)} archivo(s) en el torrent")
|
| 149 |
+
for f in files_info["files"]:
|
| 150 |
+
log_cb(f" [{f['index']}] {f['path']} ({fmt_size(f['length'])})")
|
| 151 |
+
break
|
| 152 |
+
waited += 2
|
| 153 |
+
if waited % 10 == 0:
|
| 154 |
+
log_cb(f"[aria2] Esperando metadata... {waited}s")
|
| 155 |
+
progress_cb(min(90, int(waited / timeout * 100)), f"Obteniendo metadata... {waited}s")
|
| 156 |
+
time.sleep(2)
|
| 157 |
+
if proc.poll() is None:
|
| 158 |
+
if gid:
|
| 159 |
+
aria2_rpc_call(port, secret, "forcePause", [gid])
|
| 160 |
+
time.sleep(0.3)
|
| 161 |
+
aria2_rpc_call(port, secret, "remove", [gid])
|
| 162 |
+
time.sleep(0.3)
|
| 163 |
+
aria2_rpc_call(port, secret, "shutdown")
|
| 164 |
+
time.sleep(0.5)
|
| 165 |
+
proc.terminate()
|
| 166 |
+
try:
|
| 167 |
+
proc.wait(timeout=3)
|
| 168 |
+
except:
|
| 169 |
+
proc.kill()
|
| 170 |
+
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 171 |
+
return files_info
|
| 172 |
+
except Exception as e:
|
| 173 |
+
log_cb(f"[X] Error obteniendo metadata: {e}")
|
| 174 |
+
if proc and proc.poll() is None:
|
| 175 |
+
proc.terminate()
|
| 176 |
+
shutil.rmtree(tmp_dir, ignore_errors=True)
|
| 177 |
+
return None
|
| 178 |
+
|
| 179 |
+
def download_with_aria2(source: str, output_dir: Path, log_cb, progress_cb, cancel_flag,
|
| 180 |
+
selected_files=None) -> bool:
|
| 181 |
+
if not ARIA2_OK:
|
| 182 |
+
log_cb("[X] aria2c no encontrado. Coloca aria2c.exe en la carpeta del script")
|
| 183 |
+
return False
|
| 184 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 185 |
+
cmd = [
|
| 186 |
+
ARIA2_PATH,
|
| 187 |
+
"--seed-time=0",
|
| 188 |
+
"--file-allocation=none",
|
| 189 |
+
"--max-connection-per-server=16",
|
| 190 |
+
"--split=16",
|
| 191 |
+
"--min-split-size=1M",
|
| 192 |
+
"--bt-max-peers=100",
|
| 193 |
+
"--bt-request-peer-speed-limit=0",
|
| 194 |
+
"--bt-tracker-connect-timeout=10",
|
| 195 |
+
"--bt-tracker-timeout=10",
|
| 196 |
+
"--console-log-level=notice",
|
| 197 |
+
"--summary-interval=5",
|
| 198 |
+
"-d", str(output_dir),
|
| 199 |
+
]
|
| 200 |
+
if selected_files is not None:
|
| 201 |
+
indices = ",".join(str(i) for i in selected_files)
|
| 202 |
+
cmd.append(f"--select-file={indices}")
|
| 203 |
+
log_cb(f"[aria2] Descargando archivos seleccionados: {indices}")
|
| 204 |
+
cmd.append(source.strip())
|
| 205 |
+
log_cb("[aria2] Iniciando descarga...")
|
| 206 |
+
log_cb(f"[aria2] Destino: {output_dir}")
|
| 207 |
+
try:
|
| 208 |
+
creationflags = subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0
|
| 209 |
+
proc = subprocess.Popen(
|
| 210 |
+
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 211 |
+
universal_newlines=True, bufsize=1, creationflags=creationflags
|
| 212 |
+
)
|
| 213 |
+
progress_pattern = re.compile(r'\((\d+)%\)')
|
| 214 |
+
speed_pattern = re.compile(r'DL:([^\s\]]+)')
|
| 215 |
+
last_log = 0
|
| 216 |
+
for line in proc.stdout:
|
| 217 |
+
if cancel_flag[0]:
|
| 218 |
+
proc.terminate()
|
| 219 |
+
log_cb("[!] Descarga cancelada")
|
| 220 |
+
return False
|
| 221 |
+
line = line.strip()
|
| 222 |
+
if not line:
|
| 223 |
+
continue
|
| 224 |
+
pct_match = progress_pattern.search(line)
|
| 225 |
+
speed_match = speed_pattern.search(line)
|
| 226 |
+
if pct_match:
|
| 227 |
+
pct = int(pct_match.group(1))
|
| 228 |
+
speed = speed_match.group(1) if speed_match else "..."
|
| 229 |
+
progress_cb(pct, f"[aria2] {pct}% DL:{speed}")
|
| 230 |
+
now = time.time()
|
| 231 |
+
if now - last_log > 5:
|
| 232 |
+
log_cb(f"[aria2] {pct}% Velocidad: {speed}")
|
| 233 |
+
last_log = now
|
| 234 |
+
if "error" in line.lower() and "tracker" not in line.lower():
|
| 235 |
+
log_cb(f"[!] {line[:120]}")
|
| 236 |
+
proc.wait()
|
| 237 |
+
if proc.returncode == 0:
|
| 238 |
+
progress_cb(100, "[aria2] Descarga completa")
|
| 239 |
+
log_cb("[OK] Descarga completada con aria2")
|
| 240 |
+
return True
|
| 241 |
+
else:
|
| 242 |
+
log_cb(f"[X] aria2 termino con codigo: {proc.returncode}")
|
| 243 |
+
return False
|
| 244 |
+
except FileNotFoundError:
|
| 245 |
+
log_cb(f"[X] aria2c no encontrado en: {ARIA2_PATH}")
|
| 246 |
+
return False
|
| 247 |
+
except Exception as e:
|
| 248 |
+
log_cb(f"[X] Error aria2: {e}")
|
| 249 |
+
return False
|
| 250 |
+
|
| 251 |
+
# βββ TORRENT HELPERS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 252 |
+
VIDEO_EXTS = {".mp4", ".mkv", ".avi", ".mov", ".ts", ".m2ts", ".wmv", ".flv", ".webm", ".mpg", ".mpeg"}
|
| 253 |
+
|
| 254 |
+
def find_video_files(base_path: Path):
|
| 255 |
+
return [f for f in sorted(base_path.rglob("*")) if f.is_file() and f.suffix.lower() in VIDEO_EXTS]
|
| 256 |
+
|
| 257 |
+
def is_torrent_source(source: str) -> bool:
|
| 258 |
+
s = source.strip().lower()
|
| 259 |
+
return s.startswith("magnet:") or s.endswith(".torrent")
|
| 260 |
+
|
| 261 |
+
# βββ PALETA βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 262 |
+
BG, BG2, BG3, BORDER = "#0a0a0a", "#111111", "#1a1a1a", "#222222"
|
| 263 |
+
BLUE, GREEN, RED, YELLOW, ORANGE = "#3b82f6", "#10b981", "#ef4444", "#f59e0b", "#f97316"
|
| 264 |
+
FG, FG2, FG3 = "#e2e8f0", "#64748b", "#334155"
|
| 265 |
+
FONT = ("Consolas", 9)
|
| 266 |
+
FONT_SM = ("Consolas", 8)
|
| 267 |
+
FONT_LG = ("Consolas", 11, "bold")
|
| 268 |
+
FONT_XL = ("Consolas", 16, "bold")
|
| 269 |
+
|
| 270 |
+
# βββ UTILIDADES βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 271 |
def safe_name(s, maxlen=120):
|
| 272 |
if not s: return "video"
|
| 273 |
return re.sub(r'[<>:"/\\|?*\x00-\x1f]', '_', s).strip()[:maxlen]
|
|
|
|
| 281 |
s = int(secs)
|
| 282 |
return f"{s//3600:02d}:{(s%3600)//60:02d}:{s%60:02d}"
|
| 283 |
|
| 284 |
+
def fmt_size(b):
|
| 285 |
+
if b < 1024: return f"{b} B"
|
| 286 |
+
if b < 1024**2: return f"{b/1024:.1f} KB"
|
| 287 |
+
if b < 1024**3: return f"{b/1024**2:.1f} MB"
|
| 288 |
+
return f"{b/1024**3:.2f} GB"
|
| 289 |
+
|
| 290 |
+
def fmt_speed(bps):
|
| 291 |
+
if bps < 1024: return f"{bps} B/s"
|
| 292 |
+
if bps < 1024**2: return f"{bps/1024:.1f} KB/s"
|
| 293 |
+
return f"{bps/1024**2:.1f} MB/s"
|
| 294 |
+
|
| 295 |
def fetch_tmdb(url):
|
| 296 |
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
| 297 |
+
with urllib.request.urlopen(req, timeout=10) as r:
|
| 298 |
+
return json.loads(r.read().decode())
|
| 299 |
|
| 300 |
def probe(source):
|
| 301 |
info = {"audio": [], "subs": [], "duration": 0.0, "title": ""}
|
|
|
|
| 305 |
"-show_format", "-show_streams", source],
|
| 306 |
capture_output=True, text=True, timeout=90
|
| 307 |
)
|
| 308 |
+
if r.returncode != 0: return info
|
|
|
|
| 309 |
data = json.loads(r.stdout)
|
| 310 |
tags = data.get("format", {}).get("tags", {})
|
| 311 |
+
info["title"] = (tags.get("title") or tags.get("TITLE") or "").strip()
|
| 312 |
info["duration"] = float(data.get("format", {}).get("duration", 0) or 0)
|
| 313 |
ai = si = 0
|
| 314 |
for s in data.get("streams", []):
|
| 315 |
+
t, ct = s.get("tags", {}), s.get("codec_type", "")
|
|
|
|
| 316 |
if ct == "audio":
|
| 317 |
+
info["audio"].append({"idx": ai, "codec": s.get("codec_name","?"),
|
| 318 |
+
"lang": t.get("language","und"), "ch": s.get("channels",2),
|
| 319 |
+
"title": t.get("title","")})
|
| 320 |
ai += 1
|
| 321 |
elif ct == "subtitle":
|
| 322 |
+
info["subs"].append({"idx": si, "codec": s.get("codec_name","?"),
|
| 323 |
+
"lang": t.get("language","und"), "title": t.get("title",""),
|
| 324 |
+
"forced": s.get("disposition",{}).get("forced",0)==1})
|
| 325 |
si += 1
|
| 326 |
except Exception:
|
| 327 |
pass
|
|
|
|
| 331 |
"-user_agent", "Mozilla/5.0",
|
| 332 |
"-headers", "Referer: https://google.com\r\n",
|
| 333 |
"-timeout", "180000000",
|
| 334 |
+
"-reconnect", "1", "-reconnect_streamed", "1", "-reconnect_at_eof", "1",
|
| 335 |
+
"-reconnect_delay_max", "30", "-rw_timeout", "180000000",
|
| 336 |
+
"-multiple_requests", "1",
|
| 337 |
]
|
| 338 |
|
| 339 |
def run_ffmpeg(cmd, total, log_cb, progress_cb, label):
|
| 340 |
try:
|
| 341 |
+
creationflags = subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0
|
| 342 |
+
proc = subprocess.Popen(
|
| 343 |
+
cmd, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE,
|
| 344 |
+
universal_newlines=True, bufsize=1, creationflags=creationflags
|
| 345 |
+
)
|
| 346 |
pat = re.compile(r"time=(\d+):(\d+):(\d+)\.(\d+)")
|
| 347 |
for line in proc.stderr:
|
| 348 |
m = pat.search(line)
|
|
|
|
| 357 |
log_cb(f"[ERR] ffmpeg: {e}")
|
| 358 |
return False
|
| 359 |
|
| 360 |
+
# βββ PROCESO PRINCIPAL ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 361 |
+
def process_video(token, repo_id, source, is_url, mode, audio_idx, gen_single,
|
| 362 |
+
extract_sub, sub_idx, delete_local, folder_name, file_name,
|
| 363 |
+
selected_torrent_files, log_cb, progress_cb, done_cb, cancel_flag=None):
|
| 364 |
+
if cancel_flag is None:
|
| 365 |
+
cancel_flag = [False]
|
| 366 |
try:
|
| 367 |
import sys
|
| 368 |
+
script_dir = Path(sys.argv[0]).parent.resolve()
|
| 369 |
+
output_root = script_dir / "Videos_Procesados"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
output_root.mkdir(exist_ok=True)
|
|
|
|
| 371 |
uid = str(uuid.uuid4())[:8]
|
| 372 |
tmp = output_root / f"temp_{uid}"
|
| 373 |
tmp.mkdir(exist_ok=True, parents=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
|
| 375 |
+
actual_sources = [source]
|
| 376 |
+
is_actual_url = is_url
|
| 377 |
+
|
| 378 |
+
if is_torrent_source(source):
|
| 379 |
+
log_cb(f"[P2P] Fuente torrent: {source[:80]}...")
|
| 380 |
+
if not ARIA2_OK:
|
| 381 |
+
log_cb("[X] aria2c no encontrado")
|
| 382 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 383 |
+
done_cb(False)
|
| 384 |
+
return
|
| 385 |
+
torrent_out = tmp / "torrent_dl"
|
| 386 |
+
ok = download_with_aria2(
|
| 387 |
+
source, torrent_out, log_cb, progress_cb, cancel_flag,
|
| 388 |
+
selected_files=selected_torrent_files
|
| 389 |
+
)
|
| 390 |
+
if not ok:
|
| 391 |
+
log_cb("[X] No se descargaron videos.")
|
| 392 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 393 |
+
done_cb(False)
|
| 394 |
+
return
|
| 395 |
+
video_files = find_video_files(torrent_out)
|
| 396 |
+
if not video_files:
|
| 397 |
+
log_cb("[X] No se encontraron archivos de video en la descarga.")
|
| 398 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 399 |
+
done_cb(False)
|
| 400 |
+
return
|
| 401 |
+
actual_sources = [str(f) for f in video_files]
|
| 402 |
+
is_actual_url = False
|
| 403 |
+
log_cb(f"[OK] {len(actual_sources)} archivo(s) listo(s) para procesar")
|
| 404 |
+
|
| 405 |
+
for src_idx, src in enumerate(actual_sources):
|
| 406 |
+
if cancel_flag[0]:
|
| 407 |
+
log_cb("[X] Cancelado")
|
| 408 |
+
break
|
| 409 |
+
suffix = f"_{src_idx+1}" if len(actual_sources) > 1 else ""
|
| 410 |
+
cur_file_name = f"{file_name}{suffix}"
|
| 411 |
+
out_mp4 = tmp / f"{cur_file_name}.mp4"
|
| 412 |
+
|
| 413 |
+
log_cb(f"[->] Analizando: {Path(src).name[:50]}...")
|
| 414 |
+
info = probe(src)
|
| 415 |
+
dur = info["duration"] if info["duration"] > 0 else 1
|
| 416 |
+
log_cb(f"[info] {info['title'] or 'sin titulo'} | {fmt_dur(dur)} | {len(info['audio'])} audio | {len(info['subs'])} subs")
|
| 417 |
+
|
| 418 |
+
# Construir comando ffmpeg - INCLUYE TODOS LOS AUDIOS en el video procesado
|
| 419 |
+
cmd = ["ffmpeg", "-y"] + (NET_ARGS if is_actual_url else []) + ["-i", src, "-map", "0:v:0"]
|
| 420 |
for i in range(len(info["audio"])):
|
| 421 |
+
cmd.extend(["-map", f"0:a:{i}"])
|
| 422 |
+
|
| 423 |
+
if mode == "Copy + MP3":
|
| 424 |
+
cmd += ["-c:v", "copy"]
|
| 425 |
+
for i in range(len(info["audio"])):
|
| 426 |
+
cmd.extend([f"-c:a:{i}", "libmp3lame", f"-b:a:{i}", "320k"])
|
| 427 |
+
elif mode == "Copy + FLAC":
|
| 428 |
+
cmd += ["-c:v", "copy"]
|
| 429 |
+
for i in range(len(info["audio"])):
|
| 430 |
+
cmd.extend([f"-c:a:{i}", "flac"])
|
| 431 |
+
else:
|
| 432 |
+
cmd += ["-c:v", "libx264", "-vf", "scale=-2:1080", "-preset", "fast", "-crf", "18"]
|
| 433 |
+
for i in range(len(info["audio"])):
|
| 434 |
+
cmd.extend([f"-c:a:{i}", "libmp3lame", f"-b:a:{i}", "320k"])
|
| 435 |
+
|
| 436 |
+
cmd += ["-map_metadata", "0", str(out_mp4)]
|
| 437 |
+
log_cb(f"[ffmpeg] Convirtiendo ({mode})...")
|
| 438 |
+
log_cb(f"[ffmpeg] Audio en video procesado: {len(info['audio'])} pistas")
|
| 439 |
+
ok = run_ffmpeg(cmd, dur, log_cb, progress_cb, "Convirtiendo")
|
| 440 |
+
if not ok:
|
| 441 |
+
log_cb(f"[X] Fallo la conversion: {Path(src).name}")
|
| 442 |
+
continue
|
| 443 |
+
progress_cb(100, "Conversion completa")
|
| 444 |
+
|
| 445 |
+
# EXTRAER AUDIO del video PROCESADO (out_mp4)
|
| 446 |
+
# audio_idx es el indice 0-based (pista 1 = 0, pista 4 = 3)
|
| 447 |
+
if gen_single:
|
| 448 |
+
log_cb(f"[->] Extrayendo audio indice {audio_idx} del video procesado...")
|
| 449 |
+
sp = tmp / f"{cur_file_name}_aud{audio_idx}.mp4"
|
| 450 |
+
ffmpeg_audio = [
|
| 451 |
+
"ffmpeg", "-y",
|
| 452 |
+
"-i", str(out_mp4), # Fuente: video ya procesado
|
| 453 |
+
"-map", "0:v:0", # Video
|
| 454 |
+
"-map", f"0:a:{audio_idx}", # Audio seleccionado (0-based)
|
| 455 |
+
"-c", "copy",
|
| 456 |
+
str(sp)
|
| 457 |
+
]
|
| 458 |
+
ok_audio = run_ffmpeg(ffmpeg_audio, dur, log_cb, progress_cb, "Extrayendo audio")
|
| 459 |
+
if ok_audio:
|
| 460 |
+
log_cb(f"[OK] Audio {audio_idx} extraido: {sp.name}")
|
| 461 |
+
else:
|
| 462 |
+
log_cb(f"[X] Fallo al extraer audio {audio_idx}")
|
| 463 |
+
|
| 464 |
+
# EXTRAER SUBTITULO del video PROCESADO (out_mp4)
|
| 465 |
+
# sub_idx es el indice 0-based
|
| 466 |
+
if extract_sub:
|
| 467 |
+
log_cb(f"[->] Extrayendo subtitulo indice {sub_idx} del video procesado...")
|
| 468 |
+
vtt = tmp / f"{cur_file_name}_sub{sub_idx}.vtt"
|
| 469 |
+
# Primero intentar del video procesado (si tiene subs)
|
| 470 |
+
info_proc = probe(str(out_mp4))
|
| 471 |
+
if info_proc["subs"] and sub_idx < len(info_proc["subs"]):
|
| 472 |
+
ffmpeg_sub = [
|
| 473 |
+
"ffmpeg", "-y",
|
| 474 |
+
"-i", str(out_mp4),
|
| 475 |
+
"-map", f"0:s:{sub_idx}",
|
| 476 |
+
"-c:s", "webvtt",
|
| 477 |
+
str(vtt)
|
| 478 |
+
]
|
| 479 |
+
ok_sub = run_ffmpeg(ffmpeg_sub, dur, log_cb, progress_cb, "Extrayendo sub")
|
| 480 |
+
else:
|
| 481 |
+
# Si no hay subs en procesado, extraer del original
|
| 482 |
+
log_cb(f"[->] Subs no en procesado, extrayendo del original...")
|
| 483 |
+
ffmpeg_sub = [
|
| 484 |
+
"ffmpeg", "-y"
|
| 485 |
+
] + (NET_ARGS if is_actual_url else []) + [
|
| 486 |
+
"-i", src,
|
| 487 |
+
"-map", f"0:s:{sub_idx}",
|
| 488 |
+
"-c:s", "webvtt",
|
| 489 |
+
str(vtt)
|
| 490 |
+
]
|
| 491 |
+
ok_sub = subprocess.run(ffmpeg_sub, capture_output=True, check=False).returncode == 0
|
| 492 |
+
|
| 493 |
+
if ok_sub if 'ok_sub' in dir() else False:
|
| 494 |
+
log_cb(f"[OK] Subtitulo {sub_idx} extraido: {vtt.name}")
|
| 495 |
+
else:
|
| 496 |
+
log_cb(f"[X] Fallo al extraer subtitulo {sub_idx}")
|
| 497 |
|
| 498 |
+
log_cb(f"[HF] Subiendo a HuggingFace -> {repo_id}")
|
| 499 |
if HF_OK:
|
| 500 |
+
api = HfApi()
|
| 501 |
files = [f for f in tmp.iterdir() if f.is_file()]
|
| 502 |
for i, f in enumerate(files):
|
| 503 |
rpath = f"videos/{folder_name}/{f.name}"
|
|
|
|
| 505 |
progress_cb(int((i / len(files)) * 100), f"Subiendo {i+1}/{len(files)}")
|
| 506 |
try:
|
| 507 |
api.upload_file(
|
| 508 |
+
path_or_fileobj=str(f), path_in_repo=rpath,
|
| 509 |
+
repo_id=repo_id, repo_type="model", token=token
|
|
|
|
|
|
|
|
|
|
| 510 |
)
|
| 511 |
except Exception as e:
|
| 512 |
+
log_cb(f" [X] {f.name}: {e}")
|
| 513 |
progress_cb(100, "Subida completa")
|
|
|
|
|
|
|
| 514 |
|
| 515 |
if delete_local:
|
| 516 |
shutil.rmtree(tmp, ignore_errors=True)
|
| 517 |
+
log_cb("[OK] Temporales eliminados")
|
| 518 |
else:
|
| 519 |
final_dir = output_root / folder_name
|
| 520 |
final_dir.mkdir(exist_ok=True)
|
| 521 |
for f in tmp.iterdir():
|
| 522 |
shutil.move(str(f), str(final_dir / f.name))
|
| 523 |
shutil.rmtree(tmp, ignore_errors=True)
|
| 524 |
+
log_cb(f"[OK] Guardado en: {final_dir}")
|
| 525 |
|
| 526 |
done_cb(True)
|
| 527 |
|
| 528 |
except Exception as e:
|
| 529 |
import traceback
|
| 530 |
+
log_cb(f"[X] {e}\n{traceback.format_exc()}")
|
| 531 |
done_cb(False)
|
| 532 |
|
| 533 |
+
# βββ WIDGETS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 534 |
class Spinner(tk.Canvas):
|
|
|
|
| 535 |
def __init__(self, parent, size=16, color=BLUE, **kwargs):
|
| 536 |
super().__init__(parent, width=size, height=size,
|
| 537 |
bg=kwargs.pop("bg", BG2), highlightthickness=0, **kwargs)
|
| 538 |
+
self._angle = 0
|
|
|
|
|
|
|
| 539 |
self._running = False
|
| 540 |
+
self._arc = self.create_arc(2, 2, size-2, size-2, start=0, extent=270,
|
| 541 |
+
outline=color, width=2, style="arc")
|
| 542 |
+
def start(self): self._running = True; self._spin()
|
| 543 |
+
def stop(self): self._running = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
def _spin(self):
|
| 545 |
+
if not self._running: return
|
|
|
|
| 546 |
self._angle = (self._angle + 12) % 360
|
| 547 |
self.itemconfig(self._arc, start=self._angle)
|
| 548 |
self.after(30, self._spin)
|
| 549 |
|
|
|
|
| 550 |
class FlatEntry(tk.Entry):
|
| 551 |
def __init__(self, parent, **kwargs):
|
| 552 |
kwargs.setdefault("bg", BG3)
|
|
|
|
| 559 |
kwargs.setdefault("highlightbackground", BORDER)
|
| 560 |
super().__init__(parent, **kwargs)
|
| 561 |
|
|
|
|
| 562 |
class FlatButton(tk.Button):
|
| 563 |
+
VARIANTS = {
|
| 564 |
+
"primary": (BLUE, "white", "#2563eb"),
|
| 565 |
+
"ghost": (BG3, FG2, BORDER),
|
| 566 |
+
"torrent": (ORANGE, "white", "#ea580c"),
|
| 567 |
+
"aria2": ("#22c55e", "white", "#16a34a"),
|
| 568 |
+
"default": (BG2, FG2, BG3),
|
| 569 |
+
}
|
| 570 |
def __init__(self, parent, variant="default", **kwargs):
|
| 571 |
+
c = self.VARIANTS.get(variant, self.VARIANTS["default"])
|
| 572 |
+
kwargs.setdefault("bg", c[0])
|
| 573 |
+
kwargs.setdefault("fg", c[1])
|
| 574 |
+
kwargs.setdefault("activebackground", c[2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 575 |
kwargs.setdefault("relief", "flat")
|
| 576 |
kwargs.setdefault("font", FONT)
|
| 577 |
kwargs.setdefault("cursor", "hand2")
|
|
|
|
| 580 |
kwargs.setdefault("bd", 0)
|
| 581 |
super().__init__(parent, **kwargs)
|
| 582 |
|
|
|
|
| 583 |
class Section(tk.Frame):
|
| 584 |
def __init__(self, parent, title="", **kwargs):
|
| 585 |
kwargs.setdefault("bg", BG2)
|
|
|
|
| 587 |
if title:
|
| 588 |
hdr = tk.Frame(self, bg=BG2)
|
| 589 |
hdr.pack(fill="x", pady=(0, 8))
|
| 590 |
+
tk.Label(hdr, text=title.upper(), bg=BG2, fg=FG3, font=FONT_SM).pack(side="left")
|
| 591 |
+
tk.Frame(hdr, bg=BORDER, height=1).pack(side="left", fill="x", expand=True, padx=(8, 0))
|
| 592 |
+
|
| 593 |
+
# βββ DIALOGO SELECCION ARCHIVOS TORRENT ββββββββββββββββββββββββββββββββββββββ
|
| 594 |
+
class TorrentFilesDialog(tk.Toplevel):
|
| 595 |
+
def __init__(self, parent, torrent_info: dict):
|
| 596 |
+
super().__init__(parent)
|
| 597 |
+
self.title(f"Archivos: {torrent_info.get('name', 'Torrent')[:50]}")
|
| 598 |
+
self.geometry("600x450")
|
| 599 |
+
self.configure(bg=BG)
|
| 600 |
+
self.transient(parent)
|
| 601 |
+
self.grab_set()
|
| 602 |
+
self.result = None
|
| 603 |
+
self.files = torrent_info.get('files', [])
|
| 604 |
+
self.check_vars = []
|
| 605 |
+
tk.Label(self, text=torrent_info.get('name', 'Torrent'), bg=BG, fg=FG,
|
| 606 |
+
font=FONT_LG, wraplength=580).pack(pady=(15, 5), padx=15, anchor="w")
|
| 607 |
+
tk.Label(self, text=f"{len(self.files)} archivo(s)", bg=BG, fg=FG3,
|
| 608 |
+
font=FONT_SM).pack(padx=15, anchor="w")
|
| 609 |
+
btn_frame = tk.Frame(self, bg=BG)
|
| 610 |
+
btn_frame.pack(fill="x", padx=15, pady=(10, 5))
|
| 611 |
+
FlatButton(btn_frame, text="Seleccionar videos", variant="aria2",
|
| 612 |
+
command=self._select_videos).pack(side="left")
|
| 613 |
+
FlatButton(btn_frame, text="Todos", variant="ghost",
|
| 614 |
+
command=self._select_all).pack(side="left", padx=(8, 0))
|
| 615 |
+
FlatButton(btn_frame, text="Ninguno", variant="ghost",
|
| 616 |
+
command=self._deselect_all).pack(side="left", padx=(8, 0))
|
| 617 |
+
list_frame = tk.Frame(self, bg=BG3, highlightthickness=1, highlightbackground=BORDER)
|
| 618 |
+
list_frame.pack(fill="both", expand=True, padx=15, pady=(5, 15))
|
| 619 |
+
canvas = tk.Canvas(list_frame, bg=BG3, highlightthickness=0)
|
| 620 |
+
scrollbar = ttk.Scrollbar(list_frame, orient="vertical", command=canvas.yview)
|
| 621 |
+
scroll_frame = tk.Frame(canvas, bg=BG3)
|
| 622 |
+
scroll_frame.bind("<Configure>", lambda e: canvas.configure(scrollregion=canvas.bbox("all")))
|
| 623 |
+
canvas.create_window((0, 0), window=scroll_frame, anchor="nw")
|
| 624 |
+
canvas.configure(yscrollcommand=scrollbar.set)
|
| 625 |
+
canvas.pack(side="left", fill="both", expand=True)
|
| 626 |
+
scrollbar.pack(side="right", fill="y")
|
| 627 |
+
for i, f in enumerate(self.files):
|
| 628 |
+
var = tk.BooleanVar(value=f.get('selected', True))
|
| 629 |
+
self.check_vars.append(var)
|
| 630 |
+
is_video = Path(f['path']).suffix.lower() in VIDEO_EXTS
|
| 631 |
+
fg_color = GREEN if is_video else FG2
|
| 632 |
+
row = tk.Frame(scroll_frame, bg=BG3)
|
| 633 |
+
row.pack(fill="x", padx=5, pady=1)
|
| 634 |
+
tk.Checkbutton(row, variable=var, bg=BG3, selectcolor=BG2,
|
| 635 |
+
activebackground=BG3, activeforeground=FG).pack(side="left")
|
| 636 |
+
icon = "V" if is_video else "F"
|
| 637 |
+
text = f"[{icon}][{i}] {f['path']} ({fmt_size(f['length'])})"
|
| 638 |
+
tk.Label(row, text=text, bg=BG3, fg=fg_color, font=FONT_SM, anchor="w").pack(side="left", fill="x", expand=True)
|
| 639 |
+
bottom = tk.Frame(self, bg=BG)
|
| 640 |
+
bottom.pack(fill="x", padx=15, pady=(0, 15))
|
| 641 |
+
FlatButton(bottom, text="CANCELAR", variant="ghost", command=self._cancel).pack(side="right")
|
| 642 |
+
FlatButton(bottom, text="ACEPTAR", variant="primary", command=self._accept).pack(side="right", padx=(0, 8))
|
| 643 |
+
def _select_videos(self):
|
| 644 |
+
for i, (var, f) in enumerate(zip(self.check_vars, self.files)):
|
| 645 |
+
var.set(Path(f['path']).suffix.lower() in VIDEO_EXTS)
|
| 646 |
+
def _select_all(self):
|
| 647 |
+
for var in self.check_vars:
|
| 648 |
+
var.set(True)
|
| 649 |
+
def _deselect_all(self):
|
| 650 |
+
for var in self.check_vars:
|
| 651 |
+
var.set(False)
|
| 652 |
+
def _accept(self):
|
| 653 |
+
selected = [i for i, var in enumerate(self.check_vars) if var.get()]
|
| 654 |
+
self.result = selected if selected else None
|
| 655 |
+
self.destroy()
|
| 656 |
+
def _cancel(self):
|
| 657 |
+
self.result = None
|
| 658 |
+
self.destroy()
|
| 659 |
+
|
| 660 |
+
# βββ APP βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 661 |
class App(tk.Tk):
|
| 662 |
def __init__(self):
|
| 663 |
super().__init__()
|
| 664 |
self.title("vcpro")
|
| 665 |
+
self.geometry("1160x900")
|
| 666 |
self.configure(bg=BG)
|
| 667 |
self.resizable(True, True)
|
|
|
|
| 668 |
self._queue = []
|
| 669 |
self._total_queue = 0
|
| 670 |
self._current_idx = 0
|
| 671 |
+
self._cancel_flag = [False]
|
| 672 |
+
self._torrent_info = None
|
| 673 |
+
self._selected_files = None
|
| 674 |
self._build_ui()
|
| 675 |
self._update_hf_status()
|
| 676 |
+
self._update_aria2_status()
|
| 677 |
+
self._on_track_mode_change()
|
| 678 |
|
|
|
|
| 679 |
def _build_ui(self):
|
|
|
|
| 680 |
s = ttk.Style(self)
|
| 681 |
s.theme_use("clam")
|
| 682 |
s.configure(".", background=BG, foreground=FG, font=FONT, borderwidth=0)
|
|
|
|
| 686 |
s.map("TCheckbutton", background=[("active", BG2)], foreground=[("active", FG)])
|
| 687 |
s.configure("TRadiobutton", background=BG2, foreground=FG2, font=FONT)
|
| 688 |
s.map("TRadiobutton", background=[("active", BG2)])
|
| 689 |
+
s.configure("TCombobox", fieldbackground=BG3, background=BG3, foreground=FG,
|
| 690 |
+
arrowcolor=FG2, font=FONT)
|
| 691 |
+
s.map("TCombobox", fieldbackground=[("readonly", BG3)], background=[("readonly", BG3)])
|
| 692 |
+
s.configure("Horizontal.TProgressbar", troughcolor=BG3, background=BLUE, thickness=2, borderwidth=0)
|
| 693 |
+
s.configure("Aria2.Horizontal.TProgressbar", troughcolor=BG3, background="#22c55e", thickness=2, borderwidth=0)
|
| 694 |
+
|
|
|
|
|
|
|
|
|
|
| 695 |
top = tk.Frame(self, bg=BG, pady=14, padx=20)
|
| 696 |
top.pack(fill="x")
|
|
|
|
| 697 |
tk.Label(top, text="vcpro", bg=BG, fg=FG, font=FONT_XL).pack(side="left")
|
| 698 |
tk.Label(top, text="video converter", bg=BG, fg=FG3, font=FONT).pack(side="left", padx=(10, 0))
|
| 699 |
+
self._aria2_dot = tk.Label(top, text="β", bg=BG, fg=FG3, font=FONT)
|
| 700 |
+
self._aria2_dot.pack(side="right")
|
| 701 |
+
self._aria2_lbl = tk.Label(top, text="aria2:-", bg=BG, fg=FG3, font=FONT_SM)
|
| 702 |
+
self._aria2_lbl.pack(side="right", padx=(0, 8))
|
| 703 |
self._hf_dot = tk.Label(top, text="β", bg=BG, fg=FG3, font=FONT)
|
| 704 |
self._hf_dot.pack(side="right")
|
| 705 |
+
self._hf_lbl = tk.Label(top, text="hf:-", bg=BG, fg=FG3, font=FONT_SM)
|
| 706 |
+
self._hf_lbl.pack(side="right", padx=(0, 8))
|
|
|
|
|
|
|
| 707 |
tk.Frame(self, bg=BORDER, height=1).pack(fill="x")
|
| 708 |
|
|
|
|
| 709 |
body = tk.Frame(self, bg=BG)
|
| 710 |
body.pack(fill="both", expand=True, padx=20, pady=16)
|
| 711 |
body.columnconfigure(0, weight=4, uniform="col")
|
| 712 |
body.columnconfigure(1, weight=5, uniform="col")
|
| 713 |
body.rowconfigure(0, weight=1)
|
|
|
|
| 714 |
left = tk.Frame(body, bg=BG)
|
| 715 |
right = tk.Frame(body, bg=BG)
|
| 716 |
left.grid(row=0, column=0, sticky="nsew", padx=(0, 10))
|
| 717 |
right.grid(row=0, column=1, sticky="nsew")
|
|
|
|
| 718 |
self._build_left(left)
|
| 719 |
self._build_right(right)
|
| 720 |
|
| 721 |
def _build_left(self, parent):
|
| 722 |
+
# ββ HuggingFace ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 723 |
+
hf = Section(parent, title="HuggingFace"); hf.pack(fill="x", pady=(0, 14))
|
|
|
|
|
|
|
| 724 |
tk.Label(hf, text="Token", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
| 725 |
+
tok_row = tk.Frame(hf, bg=BG2); tok_row.pack(fill="x", pady=(2, 8))
|
| 726 |
self._hf_token = tk.StringVar()
|
| 727 |
+
FlatEntry(tok_row, textvariable=self._hf_token, show="*").pack(side="left", fill="x", expand=True, ipady=5)
|
|
|
|
|
|
|
| 728 |
self._btn_connect = FlatButton(tok_row, text="conectar", command=self._connect_hf)
|
| 729 |
self._btn_connect.pack(side="right", padx=(6, 0))
|
| 730 |
+
self._spinner_hf = Spinner(tok_row, bg=BG2); self._spinner_hf.pack(side="right", padx=(4, 0))
|
|
|
|
|
|
|
| 731 |
tk.Label(hf, text="Repositorio", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
| 732 |
+
repo_row = tk.Frame(hf, bg=BG2); repo_row.pack(fill="x", pady=(2, 0))
|
|
|
|
| 733 |
self._repo_cb = ttk.Combobox(repo_row, state="normal", font=FONT)
|
| 734 |
self._repo_cb.pack(side="left", fill="x", expand=True)
|
| 735 |
+
FlatButton(repo_row, text="R", command=self._load_repos).pack(side="right", padx=(6, 0))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 736 |
|
| 737 |
+
# ββ TMDb (API KEY HARDCODEADA) ββββββββββββββββββββββββββββββββββββββ
|
| 738 |
+
td = Section(parent, title="TMDb Metadatos"); td.pack(fill="x", pady=(0, 14))
|
| 739 |
self._use_tmdb = tk.BooleanVar(value=False)
|
| 740 |
ttk.Checkbutton(td, text="Usar TMDb para nombres", variable=self._use_tmdb).pack(anchor="w", pady=(0, 6))
|
| 741 |
+
tk.Label(td, text=f"API Key: {TMDB_API_KEY[:8]}... (integrada)", bg=BG2, fg=GREEN, font=FONT_SM).pack(anchor="w")
|
| 742 |
+
search_row = tk.Frame(td, bg=BG2); search_row.pack(fill="x", pady=(4, 6))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 743 |
self._tmdb_type = tk.StringVar(value="serie")
|
| 744 |
+
ttk.Radiobutton(search_row, text="Serie", variable=self._tmdb_type, value="serie",
|
| 745 |
+
command=self._tmdb_clear).pack(side="left")
|
| 746 |
+
ttk.Radiobutton(search_row, text="Pelicula", variable=self._tmdb_type, value="pelicula",
|
| 747 |
+
command=self._tmdb_clear).pack(side="left", padx=(6, 10))
|
| 748 |
self._tmdb_query = tk.StringVar()
|
| 749 |
FlatEntry(search_row, textvariable=self._tmdb_query).pack(side="left", fill="x", expand=True, ipady=3)
|
| 750 |
+
self._spinner_tmdb = Spinner(search_row, bg=BG2); self._spinner_tmdb.pack(side="right", padx=4)
|
|
|
|
| 751 |
FlatButton(search_row, text="buscar", command=self._search_tmdb).pack(side="right")
|
|
|
|
| 752 |
self._tmdb_res_cb = ttk.Combobox(td, state="readonly", font=FONT)
|
| 753 |
self._tmdb_res_cb.pack(fill="x", pady=(0, 6))
|
| 754 |
self._tmdb_res_cb.bind("<<ComboboxSelected>>", self._on_tmdb_res_select)
|
| 755 |
+
ep_row = tk.Frame(td, bg=BG2); ep_row.pack(fill="x")
|
|
|
|
|
|
|
| 756 |
self._tmdb_season_cb = ttk.Combobox(ep_row, state="disabled", font=FONT, width=14)
|
| 757 |
self._tmdb_season_cb.pack(side="left", padx=(0, 6))
|
| 758 |
self._tmdb_season_cb.bind("<<ComboboxSelected>>", self._on_tmdb_season_select)
|
| 759 |
self._tmdb_ep_cb = ttk.Combobox(ep_row, state="disabled", font=FONT)
|
| 760 |
self._tmdb_ep_cb.pack(side="left", fill="x", expand=True)
|
|
|
|
| 761 |
self._tmdb_id_map = {}
|
| 762 |
self._tmdb_episodes = []
|
| 763 |
|
| 764 |
+
# ββ Opciones ββββββββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½
|
| 765 |
+
opt = Section(parent, title="Opciones"); opt.pack(fill="x", pady=(0, 14))
|
|
|
|
|
|
|
| 766 |
tk.Label(opt, text="Nombre manual", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
| 767 |
self._manual_name = tk.StringVar()
|
| 768 |
FlatEntry(opt, textvariable=self._manual_name).pack(fill="x", ipady=4, pady=(2, 10))
|
| 769 |
+
tk.Label(opt, text="Modo de conversion", bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w")
|
| 770 |
+
mode_row = tk.Frame(opt, bg=BG2); mode_row.pack(fill="x", pady=(2, 10))
|
|
|
|
|
|
|
| 771 |
self._mode = tk.StringVar(value="Copy + MP3")
|
| 772 |
for m in ["Copy + MP3", "Copy + FLAC", "H264 1080p"]:
|
| 773 |
ttk.Radiobutton(mode_row, text=m, variable=self._mode, value=m).pack(side="left", padx=(0, 10))
|
| 774 |
|
| 775 |
+
# ββ Pistas: Auto / Manual ββββββββββββββββββββββββββββββββββββββββββββ
|
| 776 |
+
trk = Section(parent, title="Pistas (Audio/Sub)"); trk.pack(fill="x", pady=(0, 14))
|
| 777 |
+
|
| 778 |
+
# Modo de seleccion
|
| 779 |
+
mode_trk_row = tk.Frame(trk, bg=BG2); mode_trk_row.pack(fill="x", pady=(0, 8))
|
| 780 |
+
self._track_mode = tk.StringVar(value="auto")
|
| 781 |
+
ttk.Radiobutton(mode_trk_row, text="AUTOMATICO (segun analizar)",
|
| 782 |
+
variable=self._track_mode, value="auto",
|
| 783 |
+
command=self._on_track_mode_change).pack(side="left")
|
| 784 |
+
ttk.Radiobutton(mode_trk_row, text="MANUAL (yo elijo)",
|
| 785 |
+
variable=self._track_mode, value="manual",
|
| 786 |
+
command=self._on_track_mode_change).pack(side="left", padx=(10, 0))
|
| 787 |
+
|
| 788 |
+
# Info
|
| 789 |
+
tk.Label(trk, text="Pista 1 = indice 0 | Pista 4 = indice 3 | etc.",
|
| 790 |
+
bg=BG2, fg=YELLOW, font=FONT_SM).pack(anchor="w", pady=(0, 8))
|
| 791 |
+
|
| 792 |
+
# Auto frame (combobox del analizar)
|
| 793 |
+
self._track_auto_frame = tk.Frame(trk, bg=BG2)
|
| 794 |
+
auto_row = tk.Frame(self._track_auto_frame, bg=BG2); auto_row.pack(fill="x")
|
| 795 |
+
tk.Label(auto_row, text="Audio", bg=BG2, fg=FG3, font=FONT_SM, width=5, anchor="w").pack(side="left")
|
| 796 |
+
self._aud_cb = ttk.Combobox(auto_row, state="readonly", font=FONT)
|
| 797 |
+
self._aud_cb.pack(side="left", fill="x", expand=True, padx=(4, 14))
|
| 798 |
+
tk.Label(auto_row, text="Sub", bg=BG2, fg=FG3, font=FONT_SM, width=4, anchor="w").pack(side="left")
|
| 799 |
+
self._sub_cb = ttk.Combobox(auto_row, state="readonly", font=FONT)
|
| 800 |
+
self._sub_cb.pack(side="left", fill="x", expand=True, padx=(4, 0))
|
| 801 |
+
tk.Label(self._track_auto_frame, text="(usa 'analizar' para llenar estos campos)",
|
| 802 |
+
bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w", pady=(4, 0))
|
| 803 |
+
|
| 804 |
+
# Manual frame (entradas de indice)
|
| 805 |
+
self._track_manual_frame = tk.Frame(trk, bg=BG2)
|
| 806 |
+
man_aud_row = tk.Frame(self._track_manual_frame, bg=BG2); man_aud_row.pack(fill="x", pady=(0, 4))
|
| 807 |
+
tk.Label(man_aud_row, text="Audio indice:", bg=BG2, fg=FG3, font=FONT_SM, anchor="w").pack(side="left")
|
| 808 |
+
self._manual_audio_idx = tk.StringVar(value="0")
|
| 809 |
+
FlatEntry(man_aud_row, textvariable=self._manual_audio_idx, width=8).pack(side="left", padx=(8, 4), ipady=3)
|
| 810 |
+
tk.Label(man_aud_row, text="(0 = pista 1, 3 = pista 4)", bg=BG2, fg=FG3, font=FONT_SM).pack(side="left")
|
| 811 |
+
|
| 812 |
+
man_sub_row = tk.Frame(self._track_manual_frame, bg=BG2); man_sub_row.pack(fill="x", pady=(0, 4))
|
| 813 |
+
tk.Label(man_sub_row, text="Subtitulo indice:", bg=BG2, fg=FG3, font=FONT_SM, anchor="w").pack(side="left")
|
| 814 |
+
self._manual_sub_idx = tk.StringVar(value="0")
|
| 815 |
+
FlatEntry(man_sub_row, textvariable=self._manual_sub_idx, width=8).pack(side="left", padx=(8, 4), ipady=3)
|
| 816 |
+
tk.Label(man_sub_row, text="(0 = sub 1, 2 = sub 3)", bg=BG2, fg=FG3, font=FONT_SM).pack(side="left")
|
| 817 |
+
|
| 818 |
+
# ββ Checkboxes extraer βββββββββββββββββββββββββββββββββββββββββββββββ
|
| 819 |
+
chk_row = tk.Frame(trk, bg=BG2); chk_row.pack(fill="x", pady=(8, 0))
|
| 820 |
self._gen_single = tk.BooleanVar(value=False)
|
| 821 |
self._ext_sub = tk.BooleanVar(value=False)
|
| 822 |
self._del_local = tk.BooleanVar(value=True)
|
| 823 |
+
ttk.Checkbutton(chk_row, text="Extraer audio (del procesado)", variable=self._gen_single).pack(side="left")
|
| 824 |
+
ttk.Checkbutton(chk_row, text="Extraer sub", variable=self._ext_sub).pack(side="left", padx=10)
|
| 825 |
+
ttk.Checkbutton(chk_row, text="Borrar locales", variable=self._del_local).pack(side="left")
|
| 826 |
+
|
| 827 |
+
# ββ aria2 ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 828 |
+
aria2_sec = Section(parent, title="aria2 (Torrent)"); aria2_sec.pack(fill="x", pady=(0, 0))
|
| 829 |
+
self._aria2_status_lbl = tk.Label(aria2_sec, bg=BG2, fg=FG3, font=FONT_SM, text="verificando...", anchor="w")
|
| 830 |
+
self._aria2_status_lbl.pack(anchor="w", pady=(0, 6))
|
| 831 |
+
btn_row = tk.Frame(aria2_sec, bg=BG2); btn_row.pack(fill="x")
|
| 832 |
+
FlatButton(btn_row, text="verificar aria2", variant="aria2", command=self._check_aria2).pack(side="left")
|
| 833 |
+
tk.Label(aria2_sec, text="Coloca aria2c.exe junto al script para descargar torrents",
|
| 834 |
+
bg=BG2, fg=FG2, font=FONT_SM).pack(anchor="w", pady=(8, 0))
|
| 835 |
+
|
| 836 |
+
def _on_track_mode_change(self, *_):
|
| 837 |
+
if self._track_mode.get() == "auto":
|
| 838 |
+
self._track_manual_frame.pack_forget()
|
| 839 |
+
self._track_auto_frame.pack(fill="x")
|
| 840 |
+
else:
|
| 841 |
+
self._track_auto_frame.pack_forget()
|
| 842 |
+
self._track_manual_frame.pack(fill="x")
|
| 843 |
|
| 844 |
def _build_right(self, parent):
|
| 845 |
+
src = Section(parent, title="Fuente"); src.pack(fill="x", pady=(0, 10))
|
| 846 |
+
tab_row = tk.Frame(src, bg=BG2); tab_row.pack(fill="x", pady=(0, 8))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 847 |
self._src_mode = tk.StringVar(value="url")
|
| 848 |
+
self._btn_tab_url = FlatButton(tab_row, text="URLs / Magnets", variant="primary",
|
| 849 |
+
command=lambda: self._switch_src("url"))
|
| 850 |
+
self._btn_tab_file = FlatButton(tab_row, text="Archivo / .torrent",
|
| 851 |
+
command=lambda: self._switch_src("file"))
|
| 852 |
self._btn_tab_url.pack(side="left")
|
| 853 |
self._btn_tab_file.pack(side="left", padx=(4, 0))
|
| 854 |
|
| 855 |
+
self._src_type_lbl = tk.Label(src, text="", bg=BG2, fg=FG3, font=FONT_SM, anchor="w")
|
| 856 |
+
self._src_type_lbl.pack(anchor="w", pady=(0, 4))
|
| 857 |
+
|
| 858 |
self._file_frame = tk.Frame(src, bg=BG2)
|
| 859 |
self._file_var = tk.StringVar()
|
| 860 |
+
self._file_var.trace_add("write", self._on_file_change)
|
| 861 |
FlatEntry(self._file_frame, textvariable=self._file_var).pack(side="left", fill="x", expand=True, ipady=4)
|
| 862 |
FlatButton(self._file_frame, text="examinar", command=self._browse).pack(side="right", padx=(6, 0))
|
| 863 |
+
FlatButton(self._file_frame, text=".torrent", variant="torrent", command=self._browse_torrent).pack(side="right", padx=(4, 0))
|
| 864 |
|
|
|
|
| 865 |
self._url_frame = tk.Frame(src, bg=BG2)
|
| 866 |
url_inner = tk.Frame(self._url_frame, bg=BG3, highlightthickness=1, highlightbackground=BORDER)
|
| 867 |
url_inner.pack(fill="x")
|
| 868 |
self._url_text = tk.Text(url_inner, bg=BG3, fg=FG, insertbackground=FG,
|
| 869 |
+
font=FONT, relief="flat", height=5, padx=8, pady=6)
|
| 870 |
+
self._url_text.bind("<KeyRelease>", self._on_url_change)
|
| 871 |
sb = ttk.Scrollbar(url_inner, command=self._url_text.yview)
|
| 872 |
self._url_text.configure(yscrollcommand=sb.set)
|
| 873 |
self._url_text.pack(side="left", fill="both", expand=True)
|
| 874 |
sb.pack(side="right", fill="y")
|
| 875 |
|
| 876 |
+
tk.Label(src, text="Soporta http/https - magnet:? - archivo.torrent",
|
| 877 |
+
bg=BG2, fg=FG3, font=FONT_SM).pack(anchor="w", pady=(4, 0))
|
| 878 |
+
|
| 879 |
+
self._torrent_frame = tk.Frame(src, bg=BG2)
|
| 880 |
+
self._torrent_files_lbl = tk.Label(self._torrent_frame, text="", bg=BG2, fg=ORANGE,
|
| 881 |
+
font=FONT_SM, anchor="w", wraplength=600, justify="left")
|
| 882 |
+
self._torrent_files_lbl.pack(anchor="w", pady=(0, 4))
|
| 883 |
+
self._btn_select_files = FlatButton(self._torrent_frame, text="seleccionar archivos",
|
| 884 |
+
variant="torrent", command=self._select_torrent_files)
|
| 885 |
+
self._btn_select_files.pack(anchor="w")
|
| 886 |
+
|
| 887 |
self._switch_src("url")
|
| 888 |
|
| 889 |
+
info_row = tk.Frame(src, bg=BG2, pady=6); info_row.pack(fill="x")
|
| 890 |
+
self._spinner_probe = Spinner(info_row, bg=BG2); self._spinner_probe.pack(side="left")
|
|
|
|
|
|
|
|
|
|
| 891 |
self._lbl_info = tk.Label(info_row, text="sin analizar", bg=BG2, fg=FG3, font=FONT_SM, anchor="w")
|
| 892 |
self._lbl_info.pack(side="left", padx=(6, 0))
|
| 893 |
FlatButton(info_row, text="analizar", command=self._do_analyze).pack(side="right")
|
| 894 |
|
| 895 |
+
pg = Section(parent, title="Progreso"); pg.pack(fill="both", expand=True, pady=(0, 0))
|
| 896 |
+
prog_row = tk.Frame(pg, bg=BG2); prog_row.pack(fill="x", pady=(0, 4))
|
| 897 |
+
self._spinner_proc = Spinner(prog_row, bg=BG2); self._spinner_proc.pack(side="left")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 898 |
self._lbl_prog = tk.Label(prog_row, text="esperando", bg=BG2, fg=FG3, font=FONT_SM, anchor="w")
|
| 899 |
self._lbl_prog.pack(side="left", padx=(6, 0))
|
| 900 |
self._lbl_queue = tk.Label(prog_row, text="", bg=BG2, fg=FG3, font=FONT_SM)
|
| 901 |
self._lbl_queue.pack(side="right")
|
|
|
|
| 902 |
self._pbar = ttk.Progressbar(pg, mode="determinate", style="Horizontal.TProgressbar")
|
| 903 |
self._pbar.pack(fill="x", pady=(0, 8))
|
|
|
|
| 904 |
log_wrap = tk.Frame(pg, bg=BG3, highlightthickness=1, highlightbackground=BORDER)
|
| 905 |
log_wrap.pack(fill="both", expand=True)
|
| 906 |
+
self._log_txt = tk.Text(log_wrap, bg=BG3, fg="#4ade80", font=("Consolas", 8),
|
| 907 |
+
relief="flat", state="disabled", padx=10, pady=8, cursor="arrow")
|
|
|
|
|
|
|
| 908 |
sb2 = ttk.Scrollbar(log_wrap, command=self._log_txt.yview)
|
| 909 |
self._log_txt.configure(yscrollcommand=sb2.set)
|
| 910 |
sb2.pack(side="right", fill="y")
|
| 911 |
self._log_txt.pack(fill="both", expand=True)
|
| 912 |
|
| 913 |
+
btn_row = tk.Frame(parent, bg=BG); btn_row.pack(fill="x", pady=(8, 0))
|
| 914 |
+
self._btn_cancel = FlatButton(btn_row, text="CANCELAR", variant="ghost",
|
| 915 |
+
command=self._do_cancel, font=FONT_LG, pady=10)
|
| 916 |
+
self._btn_cancel.pack(side="right", padx=(6, 0))
|
| 917 |
+
self._btn_cancel.configure(state="disabled")
|
| 918 |
+
self._btn_proc = FlatButton(btn_row, text="PROCESAR COLA", variant="primary",
|
| 919 |
+
command=self._do_process, font=FONT_LG, pady=10)
|
| 920 |
+
self._btn_proc.pack(side="left", fill="x", expand=True)
|
| 921 |
+
|
| 922 |
+
# ββ STATUS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 923 |
+
def _update_aria2_status(self):
|
| 924 |
+
global ARIA2_PATH, ARIA2_OK
|
| 925 |
+
ARIA2_PATH = get_aria2_path()
|
| 926 |
+
ARIA2_OK = ARIA2_PATH is not None
|
| 927 |
+
if ARIA2_OK:
|
| 928 |
+
self._aria2_dot.configure(fg="#22c55e")
|
| 929 |
+
self._aria2_lbl.configure(text="aria2:ok", fg="#22c55e")
|
| 930 |
+
self._aria2_status_lbl.configure(text=f"aria2c encontrado: {ARIA2_PATH}", fg="#22c55e")
|
| 931 |
+
else:
|
| 932 |
+
self._aria2_dot.configure(fg=FG3)
|
| 933 |
+
self._aria2_lbl.configure(text="aria2:-", fg=FG3)
|
| 934 |
+
self._aria2_status_lbl.configure(text="aria2c no encontrado - coloca aria2c.exe junto al script", fg=YELLOW)
|
| 935 |
|
|
|
|
| 936 |
def _update_hf_status(self):
|
| 937 |
if HF_OK:
|
| 938 |
self._hf_dot.configure(fg=GREEN)
|
| 939 |
+
self._hf_lbl.configure(text="hf:ok", fg=GREEN)
|
| 940 |
else:
|
| 941 |
self._hf_dot.configure(fg=RED)
|
| 942 |
+
self._hf_lbl.configure(text="hf:no", fg=RED)
|
| 943 |
|
| 944 |
+
def _check_aria2(self):
|
| 945 |
+
self._log("\n[->] Verificando aria2c...")
|
| 946 |
+
self._update_aria2_status()
|
| 947 |
+
if ARIA2_OK:
|
| 948 |
+
self._log(f"[OK] aria2c encontrado: {ARIA2_PATH}")
|
| 949 |
+
else:
|
| 950 |
+
self._log("[X] aria2c no encontrado")
|
| 951 |
+
self._log(" Descarga de: https://github.com/aria2/aria2/releases")
|
| 952 |
+
|
| 953 |
+
# ββ HF ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 954 |
def _connect_hf(self):
|
| 955 |
t = self._hf_token.get().strip()
|
| 956 |
+
if not t: self._log("[!] Ingresa token"); return
|
|
|
|
|
|
|
| 957 |
self._spinner_hf.start()
|
| 958 |
self._btn_connect.configure(state="disabled")
|
| 959 |
+
self._log("[->] Verificando token HuggingFace...")
|
|
|
|
| 960 |
def _go():
|
| 961 |
try:
|
| 962 |
+
if not HF_OK: raise ImportError("huggingface_hub no instalado")
|
|
|
|
| 963 |
api = HfApi()
|
| 964 |
info = api.whoami(token=t)
|
| 965 |
+
self.after(0, lambda: self._log(f"[OK] Conectado: {info.get('name')}"))
|
|
|
|
| 966 |
self.after(0, self._load_repos)
|
| 967 |
except Exception as e:
|
| 968 |
+
self.after(0, lambda: self._log(f"[X] {e}"))
|
| 969 |
finally:
|
| 970 |
self.after(0, self._spinner_hf.stop)
|
| 971 |
self.after(0, lambda: self._btn_connect.configure(state="normal"))
|
|
|
|
| 973 |
|
| 974 |
def _load_repos(self):
|
| 975 |
t = self._hf_token.get().strip()
|
| 976 |
+
if not t or not HF_OK: return
|
|
|
|
|
|
|
| 977 |
self._spinner_hf.start()
|
| 978 |
+
self._log("[->] Cargando repositorios...")
|
|
|
|
| 979 |
def _go():
|
| 980 |
try:
|
| 981 |
api = HfApi()
|
| 982 |
whoami = api.whoami(token=t)
|
| 983 |
author = whoami.get("name", "")
|
| 984 |
+
repos = [m.modelId for m in list(api.list_models(author=author, token=t))]
|
|
|
|
|
|
|
|
|
|
| 985 |
try:
|
| 986 |
+
repos += [d.id for d in list(api.list_datasets(author=author, token=t))]
|
|
|
|
| 987 |
except Exception:
|
| 988 |
pass
|
| 989 |
self.after(0, lambda: self._repo_cb.configure(values=repos))
|
| 990 |
+
if repos: self.after(0, lambda: self._repo_cb.set(repos[0]))
|
| 991 |
+
self.after(0, lambda: self._log(f"[OK] {len(repos)} repositorios"))
|
|
|
|
| 992 |
except Exception as e:
|
| 993 |
+
self.after(0, lambda: self._log(f"[X] {e}"))
|
| 994 |
finally:
|
| 995 |
self.after(0, self._spinner_hf.stop)
|
| 996 |
threading.Thread(target=_go, daemon=True).start()
|
| 997 |
|
| 998 |
+
# ββ TMDb βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 999 |
def _tmdb_clear(self, *_):
|
| 1000 |
self._tmdb_res_cb.set("")
|
| 1001 |
self._tmdb_res_cb.configure(values=[])
|
|
|
|
| 1005 |
self._tmdb_ep_cb.configure(state="disabled")
|
| 1006 |
|
| 1007 |
def _search_tmdb(self):
|
|
|
|
| 1008 |
q = self._tmdb_query.get().strip()
|
| 1009 |
+
if not q: self._log("[!] Ingresa busqueda"); return
|
|
|
|
|
|
|
| 1010 |
t = "movie" if self._tmdb_type.get() == "pelicula" else "tv"
|
| 1011 |
+
url = (f"https://api.themoviedb.org/3/search/{t}?api_key={TMDB_API_KEY}"
|
| 1012 |
+
f"&query={urllib.parse.quote(q)}&language=es-MX")
|
| 1013 |
self._spinner_tmdb.start()
|
|
|
|
| 1014 |
def _go():
|
| 1015 |
try:
|
| 1016 |
data = fetch_tmdb(url)
|
| 1017 |
res, self._tmdb_id_map = [], {}
|
| 1018 |
for r in data.get("results", [])[:15]:
|
| 1019 |
title = r.get("title") or r.get("name", "?")
|
| 1020 |
+
dt = r.get("release_date") or r.get("first_air_date") or ""
|
| 1021 |
+
yr = dt.split("-")[0] if dt else "N/A"
|
| 1022 |
+
lbl = f"{title} ({yr})"
|
| 1023 |
res.append(lbl)
|
| 1024 |
self._tmdb_id_map[lbl] = r.get("id")
|
| 1025 |
self.after(0, lambda: self._tmdb_res_cb.configure(values=res))
|
|
|
|
| 1027 |
self.after(0, lambda: self._tmdb_res_cb.set(res[0]))
|
| 1028 |
self.after(0, self._on_tmdb_res_select)
|
| 1029 |
except Exception as e:
|
| 1030 |
+
self.after(0, lambda: self._log(f"[X] TMDb: {e}"))
|
| 1031 |
finally:
|
| 1032 |
self.after(0, self._spinner_tmdb.stop)
|
| 1033 |
threading.Thread(target=_go, daemon=True).start()
|
|
|
|
| 1038 |
self._tmdb_ep_cb.configure(state="disabled")
|
| 1039 |
return
|
| 1040 |
self._tmdb_season_cb.configure(state="readonly")
|
| 1041 |
+
tid = self._tmdb_id_map.get(self._tmdb_res_cb.get())
|
|
|
|
| 1042 |
if not tid: return
|
| 1043 |
+
url = f"https://api.themoviedb.org/3/tv/{tid}?api_key={TMDB_API_KEY}&language=es-MX"
|
|
|
|
| 1044 |
self._spinner_tmdb.start()
|
|
|
|
| 1045 |
def _go():
|
| 1046 |
try:
|
| 1047 |
data = fetch_tmdb(url)
|
| 1048 |
+
seasons = [f"Temporada {s['season_number']}" for s in data.get("seasons", []) if s["season_number"] > 0]
|
|
|
|
| 1049 |
self.after(0, lambda: self._tmdb_season_cb.configure(values=seasons))
|
| 1050 |
if seasons:
|
| 1051 |
self.after(0, lambda: self._tmdb_season_cb.set(seasons[0]))
|
| 1052 |
self.after(0, self._on_tmdb_season_select)
|
| 1053 |
except Exception as e:
|
| 1054 |
+
self.after(0, lambda: self._log(f"[X] TMDb: {e}"))
|
| 1055 |
finally:
|
| 1056 |
self.after(0, self._spinner_tmdb.stop)
|
| 1057 |
threading.Thread(target=_go, daemon=True).start()
|
| 1058 |
|
| 1059 |
def _on_tmdb_season_select(self, *_):
|
| 1060 |
self._tmdb_ep_cb.configure(state="readonly")
|
| 1061 |
+
tid = self._tmdb_id_map.get(self._tmdb_res_cb.get())
|
| 1062 |
+
s_num = self._tmdb_season_cb.get().split(" ")[1] if self._tmdb_season_cb.get() else "1"
|
| 1063 |
+
url = f"https://api.themoviedb.org/3/tv/{tid}/season/{s_num}?api_key={TMDB_API_KEY}&language=es-MX"
|
|
|
|
|
|
|
| 1064 |
self._spinner_tmdb.start()
|
|
|
|
| 1065 |
def _go():
|
| 1066 |
try:
|
| 1067 |
data = fetch_tmdb(url)
|
| 1068 |
+
self._tmdb_episodes = [{"num": e["episode_number"], "name": e["name"]} for e in data.get("episodes", [])]
|
|
|
|
| 1069 |
ep_strs = [f"Ep {e['num']:02d}: {e['name']}" for e in self._tmdb_episodes]
|
| 1070 |
self.after(0, lambda: self._tmdb_ep_cb.configure(values=ep_strs))
|
| 1071 |
if ep_strs: self.after(0, lambda: self._tmdb_ep_cb.set(ep_strs[0]))
|
| 1072 |
except Exception as e:
|
| 1073 |
+
self.after(0, lambda: self._log(f"[X] TMDb: {e}"))
|
| 1074 |
finally:
|
| 1075 |
self.after(0, self._spinner_tmdb.stop)
|
| 1076 |
threading.Thread(target=_go, daemon=True).start()
|
| 1077 |
|
| 1078 |
+
# ββ SRC βββββββοΏ½οΏ½οΏ½ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1079 |
def _switch_src(self, mode):
|
| 1080 |
self._src_mode.set(mode)
|
| 1081 |
+
self._torrent_info = None
|
| 1082 |
+
self._selected_files = None
|
| 1083 |
+
self._torrent_frame.pack_forget()
|
| 1084 |
if mode == "file":
|
| 1085 |
self._url_frame.pack_forget()
|
| 1086 |
self._file_frame.pack(fill="x", pady=(0, 6))
|
|
|
|
| 1094 |
|
| 1095 |
def _browse(self):
|
| 1096 |
p = filedialog.askopenfilename(
|
| 1097 |
+
filetypes=[("Video/Torrent", "*.mp4 *.mkv *.avi *.mov *.ts *.torrent"), ("Todos", "*.*")])
|
| 1098 |
+
if p: self._file_var.set(p)
|
| 1099 |
+
|
| 1100 |
+
def _browse_torrent(self):
|
| 1101 |
+
p = filedialog.askopenfilename(filetypes=[("Torrent", "*.torrent"), ("Todos", "*.*")])
|
| 1102 |
+
if p: self._file_var.set(p); self._switch_src("file")
|
| 1103 |
+
|
| 1104 |
+
def _on_file_change(self, *_):
|
| 1105 |
+
p = self._file_var.get().strip()
|
| 1106 |
+
self._torrent_info = None
|
| 1107 |
+
self._selected_files = None
|
| 1108 |
+
self._torrent_frame.pack_forget()
|
| 1109 |
+
if p.endswith(".torrent"):
|
| 1110 |
+
self._src_type_lbl.configure(text="[torrent] detectado", fg=ORANGE)
|
| 1111 |
+
elif p:
|
| 1112 |
+
self._src_type_lbl.configure(text="[video] archivo de video", fg=GREEN)
|
| 1113 |
+
else:
|
| 1114 |
+
self._src_type_lbl.configure(text="", fg=FG3)
|
| 1115 |
+
|
| 1116 |
+
def _on_url_change(self, *_):
|
| 1117 |
+
self._torrent_info = None
|
| 1118 |
+
self._selected_files = None
|
| 1119 |
+
self._torrent_frame.pack_forget()
|
| 1120 |
+
lines = [ln.strip() for ln in self._url_text.get("1.0", "end").split("\n") if ln.strip()]
|
| 1121 |
+
if not lines: self._src_type_lbl.configure(text="", fg=FG3); return
|
| 1122 |
+
types = []
|
| 1123 |
+
if any(l.lower().startswith("magnet:") for l in lines): types.append("magnet")
|
| 1124 |
+
if any(l.lower().endswith(".torrent") for l in lines): types.append(".torrent")
|
| 1125 |
+
if any(l.startswith("http") for l in lines): types.append("http/s")
|
| 1126 |
+
col = ORANGE if ("magnet" in types or ".torrent" in types) else GREEN
|
| 1127 |
+
self._src_type_lbl.configure(text=f"[{' + '.join(types)}] ({len(lines)} elem)", fg=col)
|
| 1128 |
|
| 1129 |
def _get_sources(self):
|
| 1130 |
if self._src_mode.get() == "file":
|
| 1131 |
p = self._file_var.get().strip()
|
| 1132 |
return ([p] if p else []), False
|
| 1133 |
else:
|
| 1134 |
+
return [ln.strip() for ln in self._url_text.get("1.0", "end").split("\n") if ln.strip()], True
|
|
|
|
| 1135 |
|
| 1136 |
+
# ββ LOG / PROGRESS βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1137 |
def _log(self, msg):
|
| 1138 |
self._log_txt.configure(state="normal")
|
| 1139 |
+
if any(k in msg for k in ["aria2", "ARIA2"]):
|
| 1140 |
+
self._log_txt.tag_configure("aria2", foreground="#4ade80")
|
| 1141 |
+
self._log_txt.insert("end", msg + "\n", "aria2")
|
| 1142 |
+
elif any(k in msg for k in ["torrent", "magnet", "P2P", "metadata", "Metadata"]):
|
| 1143 |
+
self._log_txt.tag_configure("t", foreground=ORANGE)
|
| 1144 |
+
self._log_txt.insert("end", msg + "\n", "t")
|
| 1145 |
+
elif any(k in msg for k in ["[OK]"]):
|
| 1146 |
+
self._log_txt.tag_configure("ok", foreground=GREEN)
|
| 1147 |
+
self._log_txt.insert("end", msg + "\n", "ok")
|
| 1148 |
+
elif any(k in msg for k in ["[X]", "Error", "fallo"]):
|
| 1149 |
+
self._log_txt.tag_configure("e", foreground=RED)
|
| 1150 |
+
self._log_txt.insert("end", msg + "\n", "e")
|
| 1151 |
+
else:
|
| 1152 |
+
self._log_txt.insert("end", msg + "\n")
|
| 1153 |
self._log_txt.see("end")
|
| 1154 |
self._log_txt.configure(state="disabled")
|
| 1155 |
|
| 1156 |
def _set_progress(self, pct, label=""):
|
| 1157 |
self._pbar["value"] = pct
|
| 1158 |
+
if "aria2" in label.lower():
|
| 1159 |
+
self._pbar.configure(style="Aria2.Horizontal.TProgressbar")
|
| 1160 |
+
else:
|
| 1161 |
+
self._pbar.configure(style="Horizontal.TProgressbar")
|
| 1162 |
self._lbl_prog.configure(text=label)
|
| 1163 |
self.update_idletasks()
|
| 1164 |
|
| 1165 |
+
# ββ OBTENER INDICES DE PISTAS ββββββββββββββββββββββββββββββββββββββββββββ
|
| 1166 |
+
def _get_track_indices(self):
|
| 1167 |
+
"""
|
| 1168 |
+
Retorna (audio_idx, sub_idx) segun el modo seleccionado.
|
| 1169 |
+
Siempre 0-based (pista 1 = 0, pista 4 = 3)
|
| 1170 |
+
"""
|
| 1171 |
+
ai = 0
|
| 1172 |
+
si = 0
|
| 1173 |
+
|
| 1174 |
+
if self._track_mode.get() == "manual":
|
| 1175 |
+
# Modo manual: leer de los campos
|
| 1176 |
+
try:
|
| 1177 |
+
ai = int(self._manual_audio_idx.get().strip())
|
| 1178 |
+
except (ValueError, AttributeError):
|
| 1179 |
+
ai = 0
|
| 1180 |
+
try:
|
| 1181 |
+
si = int(self._manual_sub_idx.get().strip())
|
| 1182 |
+
except (ValueError, AttributeError):
|
| 1183 |
+
si = 0
|
| 1184 |
+
else:
|
| 1185 |
+
# Modo automatico: leer de los combobox del analizar
|
| 1186 |
+
try:
|
| 1187 |
+
if self._aud_cb.get():
|
| 1188 |
+
ai = int(self._aud_cb.get().split("]")[0].strip("["))
|
| 1189 |
+
except (ValueError, IndexError):
|
| 1190 |
+
ai = 0
|
| 1191 |
+
try:
|
| 1192 |
+
if self._sub_cb.get():
|
| 1193 |
+
si = int(self._sub_cb.get().split("]")[0].strip("["))
|
| 1194 |
+
except (ValueError, IndexError):
|
| 1195 |
+
si = 0
|
| 1196 |
+
|
| 1197 |
+
return ai, si
|
| 1198 |
+
|
| 1199 |
+
# ββ ANALYZE ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1200 |
def _do_analyze(self):
|
| 1201 |
sources, _ = self._get_sources()
|
| 1202 |
if not sources:
|
| 1203 |
+
messagebox.showwarning("vcpro", "Selecciona fuente.")
|
| 1204 |
+
return
|
| 1205 |
+
src = sources[0]
|
| 1206 |
+
|
| 1207 |
+
if src.strip().lower().startswith("magnet:"):
|
| 1208 |
+
if not ARIA2_OK:
|
| 1209 |
+
self._lbl_info.configure(text="[X] aria2c no encontrado", fg=RED)
|
| 1210 |
+
self._log("[X] aria2c no encontrado. No se puede analizar magnet sin aria2")
|
| 1211 |
+
return
|
| 1212 |
+
self._spinner_probe.start()
|
| 1213 |
+
self._lbl_info.configure(text="obteniendo metadata del magnet...", fg=ORANGE)
|
| 1214 |
+
self._log(f"\n[->] Analizando magnet: {src[:80]}...")
|
| 1215 |
+
def _go():
|
| 1216 |
+
info = get_magnet_info(src, lambda m: self.after(0, self._log, m),
|
| 1217 |
+
lambda p, l: self.after(0, self._set_progress, p, l),
|
| 1218 |
+
self._cancel_flag)
|
| 1219 |
+
if info:
|
| 1220 |
+
self._torrent_info = info
|
| 1221 |
+
self._selected_files = None
|
| 1222 |
+
videos = [f for f in info['files'] if Path(f['path']).suffix.lower() in VIDEO_EXTS]
|
| 1223 |
+
txt = f"{info['name']} | {len(info['files'])} archivos | {len(videos)} videos"
|
| 1224 |
+
self.after(0, lambda: self._lbl_info.configure(text=txt, fg=ORANGE))
|
| 1225 |
+
file_list = "\n".join([f" [{f['index']}] {f['path']} ({fmt_size(f['length'])})"
|
| 1226 |
+
for f in info['files'][:15]])
|
| 1227 |
+
if len(info['files']) > 15:
|
| 1228 |
+
file_list += f"\n ... y {len(info['files'])-15} mas"
|
| 1229 |
+
self.after(0, lambda: self._torrent_files_lbl.configure(text=f"Archivos en torrent:\n{file_list}"))
|
| 1230 |
+
self.after(0, lambda: self._torrent_frame.pack(fill="x", pady=(4, 0)))
|
| 1231 |
+
self.after(0, lambda: self._aud_cb.configure(values=[]))
|
| 1232 |
+
self.after(0, lambda: self._sub_cb.configure(values=[]))
|
| 1233 |
+
else:
|
| 1234 |
+
self.after(0, lambda: self._lbl_info.configure(text="[X] No se pudo obtener metadata", fg=RED))
|
| 1235 |
+
self.after(0, self._spinner_probe.stop)
|
| 1236 |
+
self.after(0, lambda: self._set_progress(0, ""))
|
| 1237 |
+
threading.Thread(target=_go, daemon=True).start()
|
| 1238 |
+
return
|
| 1239 |
+
|
| 1240 |
+
if src.strip().lower().endswith(".torrent"):
|
| 1241 |
+
self._lbl_info.configure(text="[.torrent] los archivos se muestran al procesar", fg=ORANGE)
|
| 1242 |
+
self._log("[->] Archivo .torrent detectado. Archivos se muestran al procesar.")
|
| 1243 |
return
|
| 1244 |
+
|
| 1245 |
+
# Video normal o URL - analizar con ffprobe
|
| 1246 |
self._spinner_probe.start()
|
| 1247 |
self._lbl_info.configure(text="analizando...", fg=FG3)
|
|
|
|
| 1248 |
def _go():
|
| 1249 |
+
info = probe(src)
|
| 1250 |
+
ac = [f"[{t['idx']}] {t['lang']} - {t['codec']}" for t in info["audio"]]
|
| 1251 |
+
sc = [f"[{t['idx']}] {t['lang']} - {t['codec']}" for t in info["subs"]]
|
| 1252 |
self.after(0, lambda: self._aud_cb.configure(values=ac))
|
| 1253 |
self.after(0, lambda: self._sub_cb.configure(values=sc))
|
| 1254 |
if ac: self.after(0, lambda: self._aud_cb.set(ac[0]))
|
| 1255 |
if sc: self.after(0, lambda: self._sub_cb.set(sc[0]))
|
| 1256 |
+
txt = (f"{info['title'] or 'sin titulo'} - {fmt_dur(info['duration'])} - "
|
| 1257 |
+
f"{len(ac)}aud - {len(sc)}sub")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1258 |
self.after(0, lambda: self._lbl_info.configure(text=txt, fg=GREEN))
|
| 1259 |
self.after(0, self._spinner_probe.stop)
|
| 1260 |
threading.Thread(target=_go, daemon=True).start()
|
| 1261 |
|
| 1262 |
+
def _select_torrent_files(self):
|
| 1263 |
+
if not self._torrent_info:
|
| 1264 |
+
messagebox.showinfo("vcpro", "Primero analiza el magnet link")
|
| 1265 |
+
return
|
| 1266 |
+
dialog = TorrentFilesDialog(self, self._torrent_info)
|
| 1267 |
+
self.wait_window(dialog)
|
| 1268 |
+
if dialog.result is not None:
|
| 1269 |
+
self._selected_files = dialog.result
|
| 1270 |
+
videos = [i for i in dialog.result
|
| 1271 |
+
if i < len(self._torrent_info['files'])
|
| 1272 |
+
and Path(self._torrent_info['files'][i]['path']).suffix.lower() in VIDEO_EXTS]
|
| 1273 |
+
self._log(f"[OK] Seleccionados {len(dialog.result)} archivos ({len(videos)} videos)")
|
| 1274 |
+
self._lbl_info.configure(text=f"Seleccionados: {len(videos)} videos", fg=GREEN)
|
| 1275 |
+
else:
|
| 1276 |
+
self._log("[!] Seleccion cancelada")
|
| 1277 |
+
self._selected_files = None
|
| 1278 |
+
|
| 1279 |
+
# ββ CANCEL βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1280 |
+
def _do_cancel(self):
|
| 1281 |
+
self._cancel_flag[0] = True
|
| 1282 |
+
self._log("[!] Cancelando...")
|
| 1283 |
+
self._btn_cancel.configure(state="disabled")
|
| 1284 |
+
|
| 1285 |
+
# ββ PROCESS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1286 |
def _do_process(self):
|
| 1287 |
+
tok, rep = self._hf_token.get().strip(), self._repo_cb.get().strip()
|
|
|
|
| 1288 |
sources, is_url = self._get_sources()
|
| 1289 |
if not tok or not rep or not sources:
|
| 1290 |
+
messagebox.showwarning("vcpro", "Faltan datos (token, repo o fuente).")
|
| 1291 |
return
|
| 1292 |
+
if is_torrent_source(sources[0]) and not ARIA2_OK:
|
| 1293 |
+
messagebox.showwarning("vcpro", "aria2c no encontrado. Coloca aria2c.exe junto al script.")
|
| 1294 |
+
return
|
| 1295 |
+
|
| 1296 |
+
# Obtener indices de pistas
|
| 1297 |
+
ai, si = self._get_track_indices()
|
| 1298 |
+
self._log(f"[pistas] Modo: {self._track_mode.get()} | Audio indice: {ai} | Sub indice: {si}")
|
| 1299 |
+
|
| 1300 |
+
self._cancel_flag = [False]
|
| 1301 |
+
self._queue = sources.copy()
|
| 1302 |
self._total_queue = len(self._queue)
|
| 1303 |
self._current_idx = 0
|
|
|
|
| 1304 |
self._btn_proc.configure(state="disabled", bg=FG3)
|
| 1305 |
+
self._btn_cancel.configure(state="normal")
|
| 1306 |
self._log_txt.configure(state="normal")
|
| 1307 |
self._log_txt.delete("1.0", "end")
|
| 1308 |
self._log_txt.configure(state="disabled")
|
|
|
|
| 1310 |
self._process_next()
|
| 1311 |
|
| 1312 |
def _process_next(self):
|
| 1313 |
+
if self._cancel_flag[0] or not self._queue:
|
| 1314 |
self._btn_proc.configure(state="normal", bg=BLUE)
|
| 1315 |
+
self._btn_cancel.configure(state="disabled")
|
| 1316 |
self._lbl_queue.configure(text="")
|
| 1317 |
self._spinner_proc.stop()
|
| 1318 |
+
if self._cancel_flag[0]:
|
| 1319 |
+
self._set_progress(0, "cancelado")
|
| 1320 |
+
self._log("\n[X] CANCELADO")
|
| 1321 |
+
else:
|
| 1322 |
+
self._set_progress(100, "completado")
|
| 1323 |
+
self._log("\n[OK] COLA FINALIZADA")
|
| 1324 |
return
|
| 1325 |
|
| 1326 |
src = self._queue.pop(0)
|
| 1327 |
self._current_idx += 1
|
| 1328 |
+
self._lbl_queue.configure(text=f"{self._current_idx}/{self._total_queue}", fg=FG2)
|
| 1329 |
+
self._log(f"\n{'='*50}")
|
| 1330 |
+
self._log(f"[{self._current_idx}/{self._total_queue}] {src[:60]}...")
|
| 1331 |
+
self._log(f"{'='*50}")
|
| 1332 |
|
|
|
|
| 1333 |
folder_name = "Bulk_Upload"
|
| 1334 |
+
file_name = f"Video_{self._current_idx}"
|
| 1335 |
|
| 1336 |
if self._use_tmdb.get() and self._tmdb_res_cb.get():
|
| 1337 |
base = self._tmdb_res_cb.get().split(" (")[0]
|
| 1338 |
if self._tmdb_type.get() == "pelicula":
|
| 1339 |
folder_name = to_leet(base)
|
| 1340 |
+
file_name = (to_leet(f"{base} Parte {self._current_idx}")
|
| 1341 |
+
if self._total_queue > 1 else to_leet(base))
|
| 1342 |
else:
|
| 1343 |
+
s_num = self._tmdb_season_cb.get().split(" ")[1] if self._tmdb_season_cb.get() else "1"
|
|
|
|
| 1344 |
folder_name = to_leet(f"{base} S{int(s_num):02d}")
|
| 1345 |
+
tgt = max(self._tmdb_ep_cb.current(), 0) + self._current_idx - 1
|
|
|
|
| 1346 |
if tgt < len(self._tmdb_episodes):
|
| 1347 |
ep = self._tmdb_episodes[tgt]
|
| 1348 |
+
file_name = to_leet(f"{base} S{int(s_num):02d}E{ep['num']:02d} {ep['name']}")
|
|
|
|
| 1349 |
else:
|
| 1350 |
file_name = to_leet(f"{base} S{int(s_num):02d}E{tgt+1:02d}")
|
| 1351 |
else:
|
| 1352 |
m = self._manual_name.get().strip()
|
| 1353 |
if m:
|
| 1354 |
folder_name = to_leet(m)
|
| 1355 |
+
file_name = to_leet(f"{m} {self._current_idx}") if self._total_queue > 1 else to_leet(m)
|
| 1356 |
+
elif self._src_mode.get() == "file" and not is_torrent_source(src):
|
|
|
|
| 1357 |
base = Path(src).stem
|
| 1358 |
folder_name = to_leet(base)
|
| 1359 |
+
file_name = to_leet(base)
|
| 1360 |
|
| 1361 |
+
# Obtener indices de pistas (ya calculados al inicio de _do_process)
|
| 1362 |
+
ai, si = self._get_track_indices()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1363 |
|
| 1364 |
_, is_url_chk = self._get_sources()
|
| 1365 |
+
sel_files = self._selected_files if is_torrent_source(src) else None
|
| 1366 |
|
| 1367 |
threading.Thread(
|
| 1368 |
target=process_video,
|
| 1369 |
args=(
|
| 1370 |
self._hf_token.get().strip(),
|
| 1371 |
self._repo_cb.get().strip(),
|
| 1372 |
+
src, is_url_chk, self._mode.get(),
|
|
|
|
| 1373 |
ai, self._gen_single.get(),
|
| 1374 |
self._ext_sub.get(), si,
|
| 1375 |
self._del_local.get(),
|
| 1376 |
+
folder_name, file_name, sel_files,
|
| 1377 |
lambda m: self.after(0, self._log, m),
|
| 1378 |
lambda p, l: self.after(0, self._set_progress, p, l),
|
| 1379 |
lambda ok: self.after(0, self._process_next),
|
| 1380 |
+
self._cancel_flag,
|
| 1381 |
),
|
| 1382 |
daemon=True
|
| 1383 |
).start()
|
| 1384 |
|
| 1385 |
+
# βββ INSTALLER βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 1386 |
def run_installer_and_restart():
|
| 1387 |
+
import sys
|
|
|
|
|
|
|
|
|
|
| 1388 |
root = tk.Tk()
|
| 1389 |
root.title("vcpro - Setup")
|
| 1390 |
+
root.geometry("460x200")
|
| 1391 |
root.configure(bg=BG)
|
| 1392 |
root.resizable(False, False)
|
|
|
|
|
|
|
| 1393 |
root.update_idletasks()
|
| 1394 |
+
x = (root.winfo_screenwidth() // 2) - 230
|
| 1395 |
+
y = (root.winfo_screenheight() // 2) - 100
|
| 1396 |
root.geometry(f"+{x}+{y}")
|
| 1397 |
+
tk.Label(root, text="vcpro", bg=BG, fg=FG, font=FONT_XL).pack(pady=(20, 4))
|
| 1398 |
+
lbl = tk.Label(root, text="Instalando dependencias...", bg=BG, fg=FG2, font=FONT)
|
| 1399 |
+
lbl.pack()
|
| 1400 |
+
sp = Spinner(root, size=24, color=BLUE, bg=BG)
|
| 1401 |
+
sp.pack(pady=10)
|
| 1402 |
+
sp.start()
|
| 1403 |
+
def go():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1404 |
try:
|
| 1405 |
+
creationflags = subprocess.CREATE_NO_WINDOW if os.name == 'nt' else 0
|
| 1406 |
+
p = subprocess.Popen(
|
| 1407 |
+
[sys.executable, "-m", "pip", "install", "huggingface_hub"],
|
| 1408 |
+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
|
| 1409 |
+
creationflags=creationflags
|
|
|
|
| 1410 |
)
|
| 1411 |
+
for l in p.stdout:
|
| 1412 |
+
if any(k in l for k in ["Collecting", "Installing", "Successfully"]):
|
| 1413 |
+
root.after(0, lbl.configure, {"text": l.strip()[:60]})
|
| 1414 |
+
p.wait()
|
| 1415 |
+
if p.returncode == 0:
|
| 1416 |
+
root.after(0, lbl.configure, {"text": "Listo. Reiniciando...", "fg": GREEN})
|
| 1417 |
+
time.sleep(1.5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1418 |
os.execv(sys.executable, ['python'] + sys.argv)
|
| 1419 |
else:
|
| 1420 |
+
root.after(0, sp.stop)
|
| 1421 |
+
root.after(0, lbl.configure, {"text": "Error al instalar.", "fg": RED})
|
| 1422 |
except Exception as e:
|
| 1423 |
+
root.after(0, sp.stop)
|
| 1424 |
+
root.after(0, lbl.configure, {"text": str(e), "fg": RED})
|
| 1425 |
+
threading.Thread(target=go, daemon=True).start()
|
|
|
|
| 1426 |
root.mainloop()
|
| 1427 |
+
sys.exit()
|
|
|
|
| 1428 |
|
| 1429 |
+
# βββ MAIN βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 1430 |
if __name__ == "__main__":
|
|
|
|
| 1431 |
try:
|
| 1432 |
import huggingface_hub
|
| 1433 |
+
DEP = True
|
| 1434 |
except ImportError:
|
| 1435 |
+
DEP = False
|
| 1436 |
|
| 1437 |
+
if not DEP:
|
|
|
|
| 1438 |
run_installer_and_restart()
|
| 1439 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1440 |
app = App()
|
|
|
|
|
|
|
| 1441 |
if not shutil.which("ffmpeg"):
|
| 1442 |
+
app._log("[!] ffmpeg no detectado en PATH. Las conversiones fallaran.")
|
| 1443 |
+
if ARIA2_OK:
|
| 1444 |
+
app._log(f"[OK] aria2c encontrado: {ARIA2_PATH}")
|
| 1445 |
+
else:
|
| 1446 |
+
app._log("[!] aria2c no encontrado. Coloca aria2c.exe junto al script para descargar torrents.")
|
| 1447 |
app.mainloop()
|