mirror of
https://github.com/rommapp/romm.git
synced 2026-12-02 10:08:40 +01:00
* Treat every disc descriptor as a disc, not just .cue playlist_files keyed on .cue alone, so a Dreamcast .gdi set, a CloneCD .ccd set and an Alcohol .mds set all fell through to "every file is a disc" -- the descriptor and the raw tracks it cannot boot without were listed side by side. The three readers of the rule each got that wrong in their own way: the playlist shipped inside the download zip named non-bootable tracks, and the in-browser disc swapper offered them as discs. Key on a set of descriptor extensions instead, so no one sheet format is privileged over the others. The shape is unchanged -- descriptors if any, else everything -- and so is the download zip, which lists every file regardless. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Keep a disc that stands on its own beside a descriptor Selecting descriptors and discarding everything else assumed a multi-file ROM is all one format. It is not: a .chd sitting beside a .gdi boots on its own, and returning only the .gdi dropped it from the playlist and from the swapper's targets. Exclude the raw tracks a sheet points at instead of keeping only sheets. The tracks are still not discs, so every case the previous commit fixed stays fixed, and a disc no sheet describes now survives. This also settles the same bug on the .cue path, which predates this branch: disc1.cue + disc1.bin + disc2.chd used to list the cue alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * Count a sheet's audio tracks as tracks A .cue names its CDDA tracks the same way it names its data track, so a .wav or .flac beside one is data, not a disc. The playlist listed them. Brings the list in step with the shell's own in src/main/discs/m3u.ts, which has carried the audio formats since it was written. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
162 lines
5.9 KiB
Python
162 lines
5.9 KiB
Python
from unittest.mock import MagicMock
|
|
|
|
from utils.m3u import generate_m3u_content, playlist_files
|
|
|
|
|
|
def _make_file(name: str, extension: str, download_name: str | None = None):
|
|
f = MagicMock()
|
|
f.file_extension = extension
|
|
f.file_name_for_download.return_value = download_name or name
|
|
return f
|
|
|
|
|
|
class TestGenerateM3uContent:
|
|
def test_single_file(self):
|
|
files = [_make_file("game.bin", "bin")]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.bin"
|
|
files[0].file_name_for_download.assert_called_once_with(False)
|
|
|
|
def test_multiple_files(self):
|
|
files = [
|
|
_make_file("disc1.chd", "chd"),
|
|
_make_file("disc2.chd", "chd"),
|
|
_make_file("disc3.chd", "chd"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"disc1.chd\ndisc2.chd\ndisc3.chd"
|
|
|
|
def test_cue_files_preferred_over_bin(self):
|
|
files = [
|
|
_make_file("track01.bin", "bin"),
|
|
_make_file("track02.bin", "bin"),
|
|
_make_file("game.cue", "cue"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.cue"
|
|
|
|
def test_cue_case_insensitive(self):
|
|
files = [
|
|
_make_file("track.bin", "bin"),
|
|
_make_file("game.CUE", "CUE", download_name="game.CUE"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.CUE"
|
|
|
|
def test_hidden_folder_passed_through(self):
|
|
files = [_make_file("game.chd", "chd", download_name=".hidden/game.chd")]
|
|
result = generate_m3u_content(files, hidden_folder=True)
|
|
assert result == b".hidden/game.chd"
|
|
files[0].file_name_for_download.assert_called_once_with(True)
|
|
|
|
def test_no_descriptor_files_lists_all(self):
|
|
files = [
|
|
_make_file("disc1.chd", "chd"),
|
|
_make_file("disc2.chd", "chd"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"disc1.chd\ndisc2.chd"
|
|
|
|
def test_gdi_preferred_over_raw_tracks(self):
|
|
files = [
|
|
_make_file("track01.bin", "bin"),
|
|
_make_file("track02.raw", "raw"),
|
|
_make_file("game.gdi", "gdi"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.gdi"
|
|
|
|
def test_ccd_preferred_over_img_and_sub(self):
|
|
files = [
|
|
_make_file("game.img", "img"),
|
|
_make_file("game.sub", "sub"),
|
|
_make_file("game.ccd", "ccd"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.ccd"
|
|
|
|
def test_mds_preferred_over_mdf(self):
|
|
files = [
|
|
_make_file("game.mdf", "mdf"),
|
|
_make_file("game.mds", "mds"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.mds"
|
|
|
|
def test_descriptor_case_insensitive(self):
|
|
files = [
|
|
_make_file("track01.bin", "bin"),
|
|
_make_file("game.GDI", "GDI", download_name="game.GDI"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.GDI"
|
|
|
|
def test_every_disc_descriptor_listed(self):
|
|
files = [
|
|
_make_file("disc1/track01.bin", "bin"),
|
|
_make_file("disc1.gdi", "gdi"),
|
|
_make_file("disc2/track01.bin", "bin"),
|
|
_make_file("disc2.gdi", "gdi"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"disc1.gdi\ndisc2.gdi"
|
|
|
|
def test_standalone_disc_kept_beside_a_descriptor(self):
|
|
# A set is not required to be all one format. The .gdi's tracks are
|
|
# data, but the .chd is a disc that boots on its own.
|
|
files = [
|
|
_make_file("disc1.gdi", "gdi"),
|
|
_make_file("track01.bin", "bin"),
|
|
_make_file("disc2.chd", "chd"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"disc1.gdi\ndisc2.chd"
|
|
|
|
def test_standalone_disc_kept_beside_a_cue(self):
|
|
files = [
|
|
_make_file("disc1.cue", "cue"),
|
|
_make_file("disc1.bin", "bin"),
|
|
_make_file("disc2.chd", "chd"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"disc1.cue\ndisc2.chd"
|
|
|
|
def test_audio_tracks_are_not_discs(self):
|
|
# A cue's CDDA tracks are data the sheet names, not discs beside it.
|
|
files = [
|
|
_make_file("game.cue", "cue"),
|
|
_make_file("track01.bin", "bin"),
|
|
_make_file("track02.wav", "wav"),
|
|
]
|
|
result = generate_m3u_content(files, hidden_folder=False)
|
|
assert result == b"game.cue"
|
|
|
|
|
|
class TestPlaylistFiles:
|
|
"""The disc swapper reads this directly, so the files themselves matter."""
|
|
|
|
def test_m3u_is_never_a_disc(self):
|
|
m3u = _make_file("game.m3u", "m3u")
|
|
disc = _make_file("game.chd", "chd")
|
|
assert playlist_files([m3u, disc]) == [disc]
|
|
|
|
def test_raw_tracks_are_not_discs(self):
|
|
track = _make_file("track01.bin", "bin")
|
|
gdi = _make_file("game.gdi", "gdi")
|
|
assert playlist_files([track, gdi]) == [gdi]
|
|
|
|
def test_bare_files_are_all_discs(self):
|
|
discs = [_make_file("disc1.chd", "chd"), _make_file("disc2.chd", "chd")]
|
|
assert playlist_files(discs) == discs
|
|
|
|
def test_standalone_disc_survives_a_descriptor(self):
|
|
gdi = _make_file("disc1.gdi", "gdi")
|
|
track = _make_file("track01.bin", "bin")
|
|
chd = _make_file("disc2.chd", "chd")
|
|
assert playlist_files([gdi, track, chd]) == [gdi, chd]
|
|
|
|
def test_bare_tracks_without_a_descriptor_are_discs(self):
|
|
# Nothing describes them, so they are all there is to play.
|
|
tracks = [_make_file("track01.bin", "bin"), _make_file("track02.bin", "bin")]
|
|
assert playlist_files(tracks) == tracks
|