style: apply ruff auto-fixes
This commit is contained in:
@@ -320,7 +320,7 @@ def _run(result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
f"Mixed file types detected: {', '.join(sorted(file_types))}",
|
||||
file=sys.stderr
|
||||
)
|
||||
log(f"Can only merge files of the same type", file=sys.stderr)
|
||||
log("Can only merge files of the same type", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
file_kind = list(file_types)[0] if file_types else "other"
|
||||
@@ -524,7 +524,7 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
current_time_ms = 0
|
||||
|
||||
log(f"Analyzing {len(files)} files for chapter information...", file=sys.stderr)
|
||||
logger.info(f"[merge-file] Analyzing files for chapters")
|
||||
logger.info("[merge-file] Analyzing files for chapters")
|
||||
|
||||
for file_path in files:
|
||||
# Get duration using ffprobe
|
||||
@@ -767,14 +767,14 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
logger.exception(f"[merge-file] ffmpeg process error: {e}")
|
||||
raise
|
||||
|
||||
log(f"Merge successful, adding chapters metadata...", file=sys.stderr)
|
||||
log("Merge successful, adding chapters metadata...", file=sys.stderr)
|
||||
|
||||
# Step 5: Embed chapters into container (MKA, MP4/M4A, or note limitation)
|
||||
if output_format == "mka" or output.suffix.lower() == ".mka":
|
||||
# MKA/MKV format has native chapter support via FFMetadata
|
||||
# Re-mux the file with chapters embedded (copy streams, no re-encode)
|
||||
log(f"Embedding chapters into Matroska container...", file=sys.stderr)
|
||||
logger.info(f"[merge-file] Adding chapters to MKA file via FFMetadata")
|
||||
log("Embedding chapters into Matroska container...", file=sys.stderr)
|
||||
logger.info("[merge-file] Adding chapters to MKA file via FFMetadata")
|
||||
|
||||
temp_output = output.parent / f".temp_{output.stem}.mka"
|
||||
|
||||
@@ -783,7 +783,7 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
|
||||
if mkvmerge_path:
|
||||
# mkvmerge is the best tool for embedding chapters in Matroska files
|
||||
log(f"Using mkvmerge for optimal chapter embedding...", file=sys.stderr)
|
||||
log("Using mkvmerge for optimal chapter embedding...", file=sys.stderr)
|
||||
cmd2 = [
|
||||
mkvmerge_path,
|
||||
"-o",
|
||||
@@ -795,7 +795,7 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
else:
|
||||
# Fallback to ffmpeg with proper chapter embedding for Matroska
|
||||
log(
|
||||
f"Using ffmpeg for chapter embedding (install mkvtoolnix for better quality)...",
|
||||
"Using ffmpeg for chapter embedding (install mkvtoolnix for better quality)...",
|
||||
file=sys.stderr,
|
||||
)
|
||||
# For Matroska files, the metadata must be provided via -f ffmetadata input
|
||||
@@ -838,12 +838,12 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
if output.exists():
|
||||
output.unlink()
|
||||
shutil.move(str(temp_output), str(output))
|
||||
log(f"✓ Chapters successfully embedded!", file=sys.stderr)
|
||||
logger.info(f"[merge-file] Chapters embedded successfully")
|
||||
log("✓ Chapters successfully embedded!", file=sys.stderr)
|
||||
logger.info("[merge-file] Chapters embedded successfully")
|
||||
except Exception as e:
|
||||
logger.warning(f"[merge-file] Could not replace file: {e}")
|
||||
log(
|
||||
f"Warning: Could not embed chapters, using merge without chapters",
|
||||
"Warning: Could not embed chapters, using merge without chapters",
|
||||
file=sys.stderr,
|
||||
)
|
||||
try:
|
||||
@@ -852,12 +852,12 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
pass
|
||||
else:
|
||||
logger.warning(
|
||||
f"[merge-file] Chapter embedding did not create output"
|
||||
"[merge-file] Chapter embedding did not create output"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(f"[merge-file] Chapter embedding failed: {e}")
|
||||
log(
|
||||
f"Warning: Chapter embedding failed, using merge without chapters",
|
||||
"Warning: Chapter embedding failed, using merge without chapters",
|
||||
file=sys.stderr,
|
||||
)
|
||||
elif output_format in {"m4a",
|
||||
@@ -865,15 +865,15 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
".m4b",
|
||||
".mp4"]:
|
||||
# MP4/M4A format has native chapter support via iTunes metadata atoms
|
||||
log(f"Embedding chapters into MP4 container...", file=sys.stderr)
|
||||
log("Embedding chapters into MP4 container...", file=sys.stderr)
|
||||
logger.info(
|
||||
f"[merge-file] Adding chapters to M4A/MP4 file via iTunes metadata"
|
||||
"[merge-file] Adding chapters to M4A/MP4 file via iTunes metadata"
|
||||
)
|
||||
|
||||
temp_output = output.parent / f".temp_{output.stem}{output.suffix}"
|
||||
|
||||
# ffmpeg embeds chapters in MP4 using -map_metadata and -map_chapters
|
||||
log(f"Using ffmpeg for MP4 chapter embedding...", file=sys.stderr)
|
||||
log("Using ffmpeg for MP4 chapter embedding...", file=sys.stderr)
|
||||
cmd2 = [
|
||||
ffmpeg_path,
|
||||
"-y",
|
||||
@@ -916,14 +916,14 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
output.unlink()
|
||||
shutil.move(str(temp_output), str(output))
|
||||
log(
|
||||
f"✓ Chapters successfully embedded in MP4!",
|
||||
"✓ Chapters successfully embedded in MP4!",
|
||||
file=sys.stderr
|
||||
)
|
||||
logger.info(f"[merge-file] MP4 chapters embedded successfully")
|
||||
logger.info("[merge-file] MP4 chapters embedded successfully")
|
||||
except Exception as e:
|
||||
logger.warning(f"[merge-file] Could not replace file: {e}")
|
||||
log(
|
||||
f"Warning: Could not embed chapters, using merge without chapters",
|
||||
"Warning: Could not embed chapters, using merge without chapters",
|
||||
file=sys.stderr,
|
||||
)
|
||||
try:
|
||||
@@ -932,12 +932,12 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
pass
|
||||
else:
|
||||
logger.warning(
|
||||
f"[merge-file] MP4 chapter embedding did not create output"
|
||||
"[merge-file] MP4 chapter embedding did not create output"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.exception(f"[merge-file] MP4 chapter embedding failed: {e}")
|
||||
log(
|
||||
f"Warning: MP4 chapter embedding failed, using merge without chapters",
|
||||
"Warning: MP4 chapter embedding failed, using merge without chapters",
|
||||
file=sys.stderr,
|
||||
)
|
||||
else:
|
||||
@@ -945,7 +945,7 @@ def _merge_audio(files: List[Path], output: Path, output_format: str) -> bool:
|
||||
logger.info(
|
||||
f"[merge-file] Format {output_format} does not have native chapter support"
|
||||
)
|
||||
log(f"Note: For chapter support, use MKA or M4A format", file=sys.stderr)
|
||||
log("Note: For chapter support, use MKA or M4A format", file=sys.stderr)
|
||||
|
||||
# Clean up temp files
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user