Skip to content

Commit

Permalink
Refactor subtitle skip logic
Browse files Browse the repository at this point in the history
The subtitle extraction logic in the sub.py module has been refactored to simplify the conditions that dictate whether the process continues on errors or skips subtitles. This change improves readability and makes it easier to understand the process flow.
  • Loading branch information
cbusillo committed Jun 20, 2024
1 parent 10d2087 commit 0a5eb19
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bd_to_avp/modules/sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ class SRTCreationError(Exception):


def extract_subtitle_to_srt(mkv_path: Path, output_path: Path) -> None:
skip_or_continue = config.continue_on_error or config.skip_subtitles
if config.skip_subtitles:
return None
tessdata_path = config.app.config_path / "tessdata"
subtitle_tracks = get_languages_in_mkv(mkv_path)

if not subtitle_tracks and not skip_or_continue:
if not subtitle_tracks and not config.continue_on_error:
raise SRTCreationError("No subtitle tracks found in source.")

if not subtitle_tracks:
return
return None

forced_subtitle_tracks = [track for track in subtitle_tracks if track["forced"] == 1]
forced_track_language = forced_subtitle_tracks[0]["language"] if forced_subtitle_tracks else None
Expand All @@ -48,7 +49,7 @@ def extract_subtitle_to_srt(mkv_path: Path, output_path: Path) -> None:
if srt_file.stat().st_size == 0:
srt_file.unlink()

if not any(output_path.glob("*.srt")) and not skip_or_continue:
if not any(output_path.glob("*.srt")) and not config.continue_on_error:
raise SRTCreationError("No SRT subtitle files created.")

if forced_track_language:
Expand Down

0 comments on commit 0a5eb19

Please sign in to comment.