mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-03-10 16:39:01 +00:00
fix(util): improve test command error detection and add natural sorting
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -8,6 +9,11 @@ from unshackle.core import binaries
|
|||||||
from unshackle.core.constants import context_settings
|
from unshackle.core.constants import context_settings
|
||||||
|
|
||||||
|
|
||||||
|
def _natural_sort_key(path: Path) -> list:
|
||||||
|
"""Sort key for natural sorting (S01E01 before S01E10)."""
|
||||||
|
return [int(part) if part.isdigit() else part.lower() for part in re.split(r"(\d+)", path.name)]
|
||||||
|
|
||||||
|
|
||||||
@click.group(short_help="Various helper scripts and programs.", context_settings=context_settings)
|
@click.group(short_help="Various helper scripts and programs.", context_settings=context_settings)
|
||||||
def util() -> None:
|
def util() -> None:
|
||||||
"""Various helper scripts and programs."""
|
"""Various helper scripts and programs."""
|
||||||
@@ -49,7 +55,7 @@ def crop(path: Path, aspect: str, letter: bool, offset: int, preview: bool) -> N
|
|||||||
raise click.ClickException('FFmpeg executable "ffmpeg" not found but is required.')
|
raise click.ClickException('FFmpeg executable "ffmpeg" not found but is required.')
|
||||||
|
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
paths = list(path.glob("*.mkv")) + list(path.glob("*.mp4"))
|
paths = sorted(list(path.glob("*.mkv")) + list(path.glob("*.mp4")), key=_natural_sort_key)
|
||||||
else:
|
else:
|
||||||
paths = [path]
|
paths = [path]
|
||||||
for video_path in paths:
|
for video_path in paths:
|
||||||
@@ -140,7 +146,7 @@ def range_(path: Path, full: bool, preview: bool) -> None:
|
|||||||
raise click.ClickException('FFmpeg executable "ffmpeg" not found but is required.')
|
raise click.ClickException('FFmpeg executable "ffmpeg" not found but is required.')
|
||||||
|
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
paths = list(path.glob("*.mkv")) + list(path.glob("*.mp4"))
|
paths = sorted(list(path.glob("*.mkv")) + list(path.glob("*.mp4")), key=_natural_sort_key)
|
||||||
else:
|
else:
|
||||||
paths = [path]
|
paths = [path]
|
||||||
for video_path in paths:
|
for video_path in paths:
|
||||||
@@ -225,16 +231,18 @@ def test(path: Path, map_: str) -> None:
|
|||||||
raise click.ClickException('FFmpeg executable "ffmpeg" not found but is required.')
|
raise click.ClickException('FFmpeg executable "ffmpeg" not found but is required.')
|
||||||
|
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
paths = list(path.glob("*.mkv")) + list(path.glob("*.mp4"))
|
paths = sorted(list(path.glob("*.mkv")) + list(path.glob("*.mp4")), key=_natural_sort_key)
|
||||||
else:
|
else:
|
||||||
paths = [path]
|
paths = [path]
|
||||||
for video_path in paths:
|
for video_path in paths:
|
||||||
print("Starting...")
|
print(f"Testing: {video_path.name}")
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[
|
[
|
||||||
binaries.FFMPEG,
|
binaries.FFMPEG,
|
||||||
"-hide_banner",
|
"-hide_banner",
|
||||||
"-benchmark",
|
"-benchmark",
|
||||||
|
"-err_detect",
|
||||||
|
"+crccheck+bitstream+buffer+careful+compliant+aggressive",
|
||||||
"-i",
|
"-i",
|
||||||
str(video_path),
|
str(video_path),
|
||||||
"-map",
|
"-map",
|
||||||
@@ -255,13 +263,13 @@ def test(path: Path, map_: str) -> None:
|
|||||||
reached_output = True
|
reached_output = True
|
||||||
if not reached_output:
|
if not reached_output:
|
||||||
continue
|
continue
|
||||||
if line.startswith("["): # error of some kind
|
if line.startswith("[") and not line.startswith("[out#"):
|
||||||
errors += 1
|
errors += 1
|
||||||
stream, error = line.split("] ", maxsplit=1)
|
stream, error = line.split("] ", maxsplit=1)
|
||||||
stream = stream.split(" @ ")[0]
|
stream = stream.split(" @ ")[0]
|
||||||
line = f"{stream} ERROR: {error}"
|
line = f"{stream} ERROR: {error}"
|
||||||
print(line)
|
print(line)
|
||||||
p.stderr.close()
|
p.stderr.close()
|
||||||
print(f"Finished with {errors} Errors, Cleaning up...")
|
print(f"Finished with {errors} error(s)")
|
||||||
p.terminate()
|
p.terminate()
|
||||||
p.wait()
|
p.wait()
|
||||||
|
|||||||
Reference in New Issue
Block a user