Extd rename/unmux to pad with zeroes

This commit is contained in:
Javanaut
2026-04-12 11:44:32 +02:00
parent d05b01cfb2
commit ef0d6e9274
13 changed files with 730 additions and 73 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
import json
import os
from pathlib import Path
import sys
import tempfile
@@ -21,6 +23,8 @@ class RenameCliTests(unittest.TestCase):
def setUp(self):
self.tempdir = tempfile.TemporaryDirectory()
self.workspace = Path(self.tempdir.name)
self.home_dir = self.workspace / "home"
self.home_dir.mkdir()
def tearDown(self):
self.tempdir.cleanup()
@@ -30,9 +34,18 @@ class RenameCliTests(unittest.TestCase):
source_path.write_bytes(payload)
return source_path
def write_config(self, data: dict) -> None:
config_dir = self.home_dir / ".local" / "etc"
config_dir.mkdir(parents=True, exist_ok=True)
(config_dir / "ffx.json").write_text(json.dumps(data), encoding="utf-8")
def invoke_rename(self, *args: str):
runner = CliRunner()
result = runner.invoke(cli.ffx, ["rename", *args])
result = runner.invoke(
cli.ffx,
["rename", *args],
env={**os.environ, "HOME": str(self.home_dir)},
)
self.assertEqual(0, result.exit_code, result.output)
return result
@@ -41,8 +54,8 @@ class RenameCliTests(unittest.TestCase):
result = self.invoke_rename("--prefix", "dball", str(source_path))
target_path = self.workspace / "dball_s2e3.mkv"
self.assertIn("demo_S02E03.mkv -> dball_s2e3.mkv", result.output)
target_path = self.workspace / "dball_s02e03.mkv"
self.assertIn("demo_S02E03.mkv -> dball_s02e03.mkv", result.output)
self.assertFalse(source_path.exists())
self.assertTrue(target_path.exists())
self.assertEqual(b"season-episode", target_path.read_bytes())
@@ -58,8 +71,8 @@ class RenameCliTests(unittest.TestCase):
str(source_path),
)
target_path = self.workspace / "dball_s1e7_bonus.mp4"
self.assertIn("demo_E07.mp4 -> dball_s1e7_bonus.mp4", result.output)
target_path = self.workspace / "dball_s01e07_bonus.mp4"
self.assertIn("demo_E07.mp4 -> dball_s01e07_bonus.mp4", result.output)
self.assertFalse(source_path.exists())
self.assertTrue(target_path.exists())
self.assertEqual(b"episode-only", target_path.read_bytes())
@@ -75,8 +88,8 @@ class RenameCliTests(unittest.TestCase):
str(source_path),
)
target_path = self.workspace / "dball_s5e7.webm"
self.assertIn("demo_s02e07.webm -> dball_s5e7.webm", result.output)
target_path = self.workspace / "dball_s05e07.webm"
self.assertIn("demo_s02e07.webm -> dball_s05e07.webm", result.output)
self.assertFalse(source_path.exists())
self.assertTrue(target_path.exists())
@@ -90,11 +103,27 @@ class RenameCliTests(unittest.TestCase):
str(source_path),
)
target_path = self.workspace / "dball_s1e7.mkv"
self.assertIn("demo_E07.mkv -> dball_s1e7.mkv", result.output)
target_path = self.workspace / "dball_s01e07.mkv"
self.assertIn("demo_E07.mkv -> dball_s01e07.mkv", result.output)
self.assertTrue(source_path.exists())
self.assertFalse(target_path.exists())
def test_rename_uses_configured_indicator_digit_lengths(self):
self.write_config(
{
"defaultIndicatorSeasonDigits": 3,
"defaultIndicatorEpisodeDigits": 4,
}
)
source_path = self.write_source("demo_E07.mkv")
result = self.invoke_rename("--prefix", "dball", str(source_path))
target_path = self.workspace / "dball_s001e0007.mkv"
self.assertIn("demo_E07.mkv -> dball_s001e0007.mkv", result.output)
self.assertFalse(source_path.exists())
self.assertTrue(target_path.exists())
def test_rename_skips_non_matching_filenames(self):
source_path = self.write_source("demo_finale.mkv")