Coverage for src/romfarmer/engine/transforms/m3u.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-05 02:19 -0700

1"""M3U transform — synthesise a multi-disc playlist file. 

2 

3The ``m3u-create`` tool is declared by the disc lowering rule for 

4multi-disc CHD sets. The playlist content comes entirely from 

5``params`` — the CHD inputs exist only to express DAG ordering and to 

6make the ActionKey depend on the disc contents (a changed disc must 

7re-create the playlist's cache entry). 

8""" 

9 

10from __future__ import annotations 

11 

12from collections.abc import Mapping 

13from pathlib import Path 

14 

15from .base import Transform 

16 

17 

18class M3UTransform: 

19 """Write an ``.m3u`` playlist from ``params["entries"]``. 

20 

21 Recognised params: 

22 entries: comma-separated CHD filenames, written one per line 

23 name: output filename (default ``playlist.m3u``) 

24 """ 

25 

26 name = "m3u-create" 

27 

28 def run( 

29 self, 

30 inputs: list[Path], 

31 params: Mapping[str, str], 

32 scratch: Path, 

33 ) -> list[Path]: 

34 entries = [e for e in params.get("entries", "").split(",") if e] 

35 out_name = params.get("name", "playlist.m3u") 

36 out_path = scratch / out_name 

37 out_path.parent.mkdir(parents=True, exist_ok=True) 

38 out_path.write_text("\n".join(entries) + "\n", encoding="utf-8") 

39 return [out_path] 

40 

41 

42# Satisfy the Transform protocol at type-check time 

43_: Transform = M3UTransform()