chore: sprint cleanup — language unification, parser unification, fossils removal

Several weeks of work accumulated without being committed. Grouped here for
clarity; see CHANGELOG.md [Unreleased] for the user-facing summary.

Highlights
----------

P1 #2 — ISO 639-2/B canonical migration
- New Language VO + LanguageRegistry (alfred/domain/shared/knowledge/).
- iso_languages.yaml as single source of truth for language codes.
- SubtitleKnowledgeBase now delegates lookup to LanguageRegistry; subtitles.yaml
  only declares subtitle-specific tokens (vostfr, vf, vff, …).
- SubtitlePreferences default → ["fre", "eng"]; subtitle filenames written as
  {iso639_2b}.srt (legacy fr.srt still read via alias).
- Scanner: dropped _LANG_KEYWORDS / _SDH_TOKENS / _FORCED_TOKENS /
  SUBTITLE_EXTENSIONS hardcoded dicts.
- Fixed: 'hi' token no longer marks SDH (conflicted with Hindi alias).
- Added settings.min_movie_size_bytes (was a module constant).

P1 #3 — Release parser unification + data-driven tokenizer
- parse_release() is now the single source of truth for release-name parsing.
- alfred/knowledge/release/separators.yaml declares the token separators used
  by the tokenizer (., space, [, ], (, ), _). New conventions can be added
  without code changes.
- Tokenizer now splits on any configured separator instead of name.split('.').
  Releases like 'The Father (2020) [1080p] [WEBRip] [5.1] [YTS.MX]' parse via
  the direct path without sanitization fallback.
- Site-tag extraction always runs first; well-formedness only rejects truly
  forbidden chars.
- _parse_season_episode() extended with NxNN / NxNNxNN alt forms.
- Removed dead helpers: _sanitize, _normalize.

Domain cleanup
- Deleted fossil services with zero production callers:
    alfred/domain/movies/services.py
    alfred/domain/tv_shows/services.py
    alfred/domain/subtitles/services.py (replaced by subtitles/services/ package)
    alfred/domain/subtitles/repositories.py
- Split monolithic subtitle services into a package (identifier, matcher,
  placer, pattern_detector, utils) + dedicated knowledge/ package.
- MediaInfo split into dedicated package (alfred/domain/shared/media/:
  audio, video, subtitle, info, matching).

Persistence cleanup
- Removed dead JSON repositories (movie/subtitle/tvshow_repository.py).

Tests
- Major expansion of the test suite organized to mirror the source tree.
- Removed obsolete *_edge_cases test files superseded by structured tests.
- Suite: 990 passed, 8 skipped.

Misc
- .gitignore: exclude env_backup/ and *.bak.
- Adjustments across agent/llm, app.py, application/filesystem, and
  infrastructure/filesystem to align with the new domain layout.
This commit is contained in:
2026-05-17 23:38:00 +02:00
parent ba6f016d49
commit e07c9ec77b
99 changed files with 8833 additions and 6533 deletions
+217
View File
@@ -0,0 +1,217 @@
"""Tests for ``alfred.application.filesystem.enrich_from_probe``.
The function mutates a ``ParsedRelease`` in place using ffprobe ``MediaInfo``.
Token-level values from the release name always win — only ``None`` fields
are filled.
Coverage:
- ``TestQuality`` — resolution fill-in (and no-overwrite).
- ``TestVideoCodec`` — codec map (hevc→x265, …) + uppercase fallback.
- ``TestAudio`` — default track preferred over first; codec & channel maps
with unknown-value fallbacks.
- ``TestLanguages`` — append-only merge; ``und`` skipped; case-insensitive
duplicate suppression.
Uses real ``ParsedRelease`` / ``MediaInfo`` instances — no mocking needed.
"""
from __future__ import annotations
from alfred.application.filesystem.enrich_from_probe import enrich_from_probe
from alfred.domain.release.value_objects import ParsedRelease
from alfred.domain.shared.media import AudioTrack, MediaInfo, VideoTrack
def _info_with_video(*, width=None, height=None, codec=None, **rest) -> MediaInfo:
"""Helper: build a MediaInfo with a single video track (the common case)."""
return MediaInfo(
video_tracks=[VideoTrack(index=0, codec=codec, width=width, height=height)],
**rest,
)
def _bare(**overrides) -> ParsedRelease:
"""Build a minimal ParsedRelease with all enrichable fields = None."""
defaults = dict(
raw="X",
normalised="X",
title="X",
year=None,
season=None,
episode=None,
episode_end=None,
quality=None,
source=None,
codec=None,
group="UNKNOWN",
tech_string="",
)
defaults.update(overrides)
return ParsedRelease(**defaults)
# --------------------------------------------------------------------------- #
# Quality / resolution #
# --------------------------------------------------------------------------- #
class TestQuality:
def test_fills_when_none(self):
p = _bare()
enrich_from_probe(p, _info_with_video(width=1920, height=1080))
assert p.quality == "1080p"
def test_does_not_overwrite_existing(self):
p = _bare(quality="2160p")
enrich_from_probe(p, _info_with_video(width=1920, height=1080))
assert p.quality == "2160p"
def test_no_dims_leaves_none(self):
p = _bare()
enrich_from_probe(p, MediaInfo())
assert p.quality is None
# --------------------------------------------------------------------------- #
# Video codec #
# --------------------------------------------------------------------------- #
class TestVideoCodec:
def test_hevc_to_x265(self):
p = _bare()
enrich_from_probe(p, _info_with_video(codec="hevc"))
assert p.codec == "x265"
def test_h264_to_x264(self):
p = _bare()
enrich_from_probe(p, _info_with_video(codec="h264"))
assert p.codec == "x264"
def test_unknown_codec_uppercased(self):
p = _bare()
enrich_from_probe(p, _info_with_video(codec="weird"))
assert p.codec == "WEIRD"
def test_does_not_overwrite_existing(self):
p = _bare(codec="HEVC")
enrich_from_probe(p, _info_with_video(codec="h264"))
assert p.codec == "HEVC"
def test_no_codec_leaves_none(self):
p = _bare()
enrich_from_probe(p, MediaInfo())
assert p.codec is None
# --------------------------------------------------------------------------- #
# Audio #
# --------------------------------------------------------------------------- #
class TestAudio:
def test_uses_default_track(self):
info = MediaInfo(
audio_tracks=[
AudioTrack(0, "aac", 2, "stereo", "eng", is_default=False),
AudioTrack(1, "eac3", 6, "5.1", "eng", is_default=True),
]
)
p = _bare()
enrich_from_probe(p, info)
assert p.audio_codec == "EAC3"
assert p.audio_channels == "5.1"
def test_falls_back_to_first_track_when_no_default(self):
info = MediaInfo(
audio_tracks=[
AudioTrack(0, "ac3", 6, "5.1", "eng"),
AudioTrack(1, "aac", 2, "stereo", "fre"),
]
)
p = _bare()
enrich_from_probe(p, info)
assert p.audio_codec == "AC3"
assert p.audio_channels == "5.1"
def test_channel_count_unknown_falls_back(self):
info = MediaInfo(
audio_tracks=[AudioTrack(0, "aac", 4, "quad", "eng")]
)
p = _bare()
enrich_from_probe(p, info)
assert p.audio_channels == "4ch"
def test_unknown_audio_codec_uppercased(self):
info = MediaInfo(
audio_tracks=[AudioTrack(0, "newcodec", 2, "stereo", "eng")]
)
p = _bare()
enrich_from_probe(p, info)
assert p.audio_codec == "NEWCODEC"
def test_no_audio_tracks(self):
p = _bare()
enrich_from_probe(p, MediaInfo())
assert p.audio_codec is None
assert p.audio_channels is None
def test_does_not_overwrite_existing_audio_fields(self):
info = MediaInfo(
audio_tracks=[AudioTrack(0, "ac3", 6, "5.1", "eng")]
)
p = _bare(audio_codec="DTS-HD.MA", audio_channels="7.1")
enrich_from_probe(p, info)
assert p.audio_codec == "DTS-HD.MA"
assert p.audio_channels == "7.1"
# --------------------------------------------------------------------------- #
# Languages #
# --------------------------------------------------------------------------- #
class TestLanguages:
def test_appends_new(self):
info = MediaInfo(
audio_tracks=[
AudioTrack(0, "aac", 2, "stereo", "eng"),
AudioTrack(1, "aac", 2, "stereo", "fre"),
]
)
p = _bare()
enrich_from_probe(p, info)
assert p.languages == ["eng", "fre"]
def test_skips_und(self):
info = MediaInfo(
audio_tracks=[
AudioTrack(0, "aac", 2, "stereo", "und"),
AudioTrack(1, "aac", 2, "stereo", "eng"),
]
)
p = _bare()
enrich_from_probe(p, info)
assert p.languages == ["eng"]
def test_dedup_against_existing_case_insensitive(self):
# existing token-level languages are typically upper-case ("FRENCH", "ENG")
# The current logic compares track.lang.upper() against existing —
# so a track with "eng" is suppressed if "ENG" is already in languages.
info = MediaInfo(
audio_tracks=[
AudioTrack(0, "aac", 2, "stereo", "eng"),
AudioTrack(1, "aac", 2, "stereo", "fre"),
]
)
p = _bare()
p.languages = ["ENG"]
enrich_from_probe(p, info)
# "eng" → upper "ENG" already present → skipped. "fre" → "FRE" new → kept.
assert p.languages == ["ENG", "fre"]
def test_no_audio_tracks_leaves_languages_empty(self):
p = _bare()
enrich_from_probe(p, MediaInfo())
assert p.languages == []