Skip to content

Commit

Permalink
rename forced subs
Browse files Browse the repository at this point in the history
  • Loading branch information
cbusillo committed Jun 15, 2024
1 parent 41ac9e1 commit e584920
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions bd_to_avp/modules/sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def extract_subtitle_to_srt(mkv_path: Path, output_path: Path) -> None:
tessdata_path = config.app.config_path / "tessdata"
subtitle_tracks = get_languages_in_mkv(mkv_path)

if not subtitle_tracks:
if not subtitle_tracks and not config.skip_subtitles:
raise SRTCreationError("No subtitle tracks found in MKV.")

forced_subtitle_tracks = [track for track in subtitle_tracks if track["forced"] == 1]
Expand All @@ -40,17 +40,23 @@ def extract_subtitle_to_srt(mkv_path: Path, output_path: Path) -> None:

pgsrip.rip(mkv_file, sub_options)

for srt_file in output_path.glob("*.srt"):
if srt_file.stat().st_size == 0:
srt_file.unlink()

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

if forced_track_language:
two_alpha_language_code = Language.fromietf(forced_track_language).alpha2
for srt_file in output_path.glob(f"*{two_alpha_language_code}.srt"):
srt_file.rename(f"{srt_file.name}.forced{srt_file.suffix}")

forced_srt_file = next(output_path.glob(f"*{two_alpha_language_code}.srt"))
if forced_srt_file and forced_srt_file.exists():
forced_srt_file.rename(forced_srt_file.with_stem(forced_srt_file.stem + ".forced"))

spinner.stop()
spinner_thread.join()

if not any(output_path.glob("*.srt")):
raise SRTCreationError("No SRT files created.")


def get_missing_tessdata_files(languages: list[str], tessdata_path: Path) -> None:
tessdata_path.mkdir(exist_ok=True)
Expand Down

0 comments on commit e584920

Please sign in to comment.