updated series_index to float and added UniqueConstraint to audiobook and audiobook_author
treefmt / nix fmt (pull_request) Failing after 5s
pytest / pytest (pull_request) Successful in 26s
build_systems / build-bob (pull_request) Successful in 45s
build_systems / build-leviathan (pull_request) Successful in 55s
build_systems / build-rhapsody-in-green (pull_request) Successful in 56s
build_systems / build-brain (pull_request) Successful in 47s
build_systems / build-jeeves (pull_request) Successful in 2m36s
treefmt / nix fmt (pull_request) Failing after 5s
pytest / pytest (pull_request) Successful in 26s
build_systems / build-bob (pull_request) Successful in 45s
build_systems / build-leviathan (pull_request) Successful in 55s
build_systems / build-rhapsody-in-green (pull_request) Successful in 56s
build_systems / build-brain (pull_request) Successful in 47s
build_systems / build-jeeves (pull_request) Successful in 2m36s
This commit is contained in:
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
@@ -30,6 +31,7 @@ if TYPE_CHECKING:
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
SENSITIVE_COMMAND_ARGUMENTS = {"-activation_bytes"}
|
||||
BOOK_RANGE_PATTERN = re.compile(r"(?:^|-)books?-(?P<start>[1-9]\d*)-(?P<end>[1-9]\d*)(?:-|$)")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
@@ -178,7 +180,32 @@ def output_stem(metadata: StandardBookMetadata) -> str:
|
||||
Returns:
|
||||
Output stem in author-series_01-title form.
|
||||
"""
|
||||
return f"{metadata.author}-{metadata.series}_{metadata.series_index:02}-{metadata.title}"
|
||||
index_slug = series_index_slug(metadata.series_index, metadata.title)
|
||||
return f"{metadata.author}-{metadata.series}_{index_slug}-{metadata.title}"
|
||||
|
||||
|
||||
def series_index_slug(series_index: float, title: str = "") -> str:
|
||||
"""Return a filename-safe series index."""
|
||||
if title_range := title_series_range_slug(series_index, title):
|
||||
return title_range
|
||||
index = float(series_index)
|
||||
if index.is_integer():
|
||||
return f"{int(index):02}"
|
||||
return f"{int(index):02}.5"
|
||||
|
||||
|
||||
def title_series_range_slug(series_index: float, title: str) -> str | None:
|
||||
"""Return a series range slug found in an omnibus title."""
|
||||
index = float(series_index)
|
||||
if not index.is_integer():
|
||||
return None
|
||||
first_index = int(index)
|
||||
for match in BOOK_RANGE_PATTERN.finditer(title):
|
||||
start = int(match.group("start"))
|
||||
end = int(match.group("end"))
|
||||
if start == first_index and end > start:
|
||||
return f"{start:02}-{end:02}"
|
||||
return None
|
||||
|
||||
|
||||
def metadata_output_path(output_directory: Path, metadata: StandardBookMetadata) -> Path:
|
||||
|
||||
Reference in New Issue
Block a user