feat: Add handling for author-series name collisions in Audiobookshelf metadata

This commit is contained in:
JB
2025-11-11 07:56:51 -08:00
parent 67453ed17c
commit 95f0307be1
2 changed files with 62 additions and 1 deletions
+29
View File
@@ -359,6 +359,33 @@ def _build_audiobookshelf_metadata(job: Job) -> Dict[str, Any]:
tags.get("series_title"), tags.get("series_title"),
tags.get("seriestitle"), tags.get("seriestitle"),
) )
if series_name:
normalized_series = series_name.strip()
if normalized_series:
author_candidates: set[str] = set()
for name in authors:
author_name = name.strip()
if author_name:
author_candidates.add(author_name.casefold())
raw_author_fields = (
tags.get("authors"),
tags.get("author"),
tags.get("album_artist"),
tags.get("artist"),
tags.get("writer"),
tags.get("composer"),
)
for raw_author in raw_author_fields:
if not raw_author:
continue
author_text = str(raw_author).strip()
if author_text:
author_candidates.add(author_text.casefold())
joined_authors = ", ".join(authors)
if joined_authors:
author_candidates.add(joined_authors.casefold())
if normalized_series.casefold() in author_candidates:
series_name = None
series_sequence = None series_sequence = None
for key in _SERIES_SEQUENCE_TAG_KEYS: for key in _SERIES_SEQUENCE_TAG_KEYS:
raw_value = tags.get(key) raw_value = tags.get(key)
@@ -366,6 +393,8 @@ def _build_audiobookshelf_metadata(job: Job) -> Dict[str, Any]:
if normalized_sequence: if normalized_sequence:
series_sequence = normalized_sequence series_sequence = normalized_sequence
break break
if not series_name:
series_sequence = None
data: Dict[str, Any] = { data: Dict[str, Any] = {
"title": title, "title": title,
"authors": authors, "authors": authors,
+33 -1
View File
@@ -248,4 +248,36 @@ def test_audiobookshelf_metadata_allows_decimal_sequence(tmp_path):
metadata = _build_audiobookshelf_metadata(job) metadata = _build_audiobookshelf_metadata(job)
assert metadata["seriesSequence"] == "4.5" assert metadata["seriesSequence"] == "4.5"
def test_audiobookshelf_metadata_ignores_author_series_collision(tmp_path):
source = tmp_path / "book.txt"
source.write_text("content", encoding="utf-8")
job = Job(
id="job-abs-author-series",
original_filename="book.txt",
stored_path=source,
language="en",
voice="af_alloy",
speed=1.0,
use_gpu=False,
subtitle_mode="Sentence",
output_format="mp3",
save_mode="Save next to input file",
output_folder=tmp_path,
replace_single_newlines=False,
subtitle_format="srt",
created_at=time.time(),
metadata_tags={
"series": "Jane Doe",
"series_index": "1",
"authors": "Jane Doe",
},
)
metadata = _build_audiobookshelf_metadata(job)
assert "seriesName" not in metadata
assert "seriesSequence" not in metadata