Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cdd380d62f |
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
VERSION = "v1.9.0"
|
VERSION = "v1.9.1"
|
||||||
|
|
||||||
|
|
||||||
APP_NAME = "MusicTools"
|
APP_NAME = "MusicTools"
|
||||||
|
|||||||
+39
-9
@@ -13,6 +13,10 @@ from core.paths import find_ytdlp, find_ffmpeg_dir, find_ffprobe, subprocess_fla
|
|||||||
|
|
||||||
AUDIO_EXTENSIONS = {".mp3", ".m4a", ".wav", ".flac"}
|
AUDIO_EXTENSIONS = {".mp3", ".m4a", ".wav", ".flac"}
|
||||||
|
|
||||||
|
# Timeout massimo per singolo download yt-dlp (secondi). Watchdog kill.
|
||||||
|
# Serve a evitare hang su video geo-restricted, YouTube throttle o rete lenta.
|
||||||
|
_DOWNLOAD_TIMEOUT_SEC = 300
|
||||||
|
|
||||||
# Flag globale per interruzione
|
# Flag globale per interruzione
|
||||||
_stop_event = threading.Event()
|
_stop_event = threading.Event()
|
||||||
_current_process: Optional[subprocess.Popen] = None
|
_current_process: Optional[subprocess.Popen] = None
|
||||||
@@ -288,17 +292,43 @@ def upgrade_folder(
|
|||||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
|
cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True,
|
||||||
**subprocess_flags(),
|
**subprocess_flags(),
|
||||||
)
|
)
|
||||||
|
proc = _current_process
|
||||||
|
|
||||||
for line in _current_process.stdout:
|
# Watchdog: kill del subprocess se supera _DOWNLOAD_TIMEOUT_SEC.
|
||||||
if is_stopped():
|
# Previene hang indefinito su video problematici (geo-block,
|
||||||
_current_process.terminate()
|
# YouTube throttle, rete lenta). Alla scadenza il process viene
|
||||||
return
|
# terminato -> for line esce -> code path "download_error" naturale.
|
||||||
pct_match = re.search(r"(\d+(?:\.\d+)?)%", line)
|
def _watchdog_kill():
|
||||||
if pct_match and progress_callback:
|
try:
|
||||||
pct = int(float(pct_match.group(1)))
|
if proc.poll() is None:
|
||||||
progress_callback(processed, total, filepath.name, "downloading", current_kbps, pct)
|
proc.terminate()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
watchdog = threading.Timer(_DOWNLOAD_TIMEOUT_SEC, _watchdog_kill)
|
||||||
|
watchdog.daemon = True
|
||||||
|
watchdog.start()
|
||||||
|
|
||||||
|
try:
|
||||||
|
for line in proc.stdout:
|
||||||
|
if is_stopped():
|
||||||
|
proc.terminate()
|
||||||
|
return
|
||||||
|
pct_match = re.search(r"(\d+(?:\.\d+)?)%", line)
|
||||||
|
if pct_match and progress_callback:
|
||||||
|
pct = int(float(pct_match.group(1)))
|
||||||
|
progress_callback(processed, total, filepath.name, "downloading", current_kbps, pct)
|
||||||
|
|
||||||
|
try:
|
||||||
|
proc.wait(timeout=10)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
proc.kill()
|
||||||
|
try:
|
||||||
|
proc.wait(timeout=5)
|
||||||
|
except subprocess.TimeoutExpired:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
watchdog.cancel()
|
||||||
|
|
||||||
_current_process.wait()
|
|
||||||
with _process_lock:
|
with _process_lock:
|
||||||
_current_process = None
|
_current_process = None
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user