Skip to content

Commit

Permalink
refactor subs to own main function and add stage
Browse files Browse the repository at this point in the history
  • Loading branch information
cbusillo committed Jun 23, 2024
1 parent b635bcd commit 2cee350
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bd_to_avp/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def handle_mkv_creation_error(self, error: MKVCreationError) -> None:

if result == QMessageBox.StandardButton.Yes:
config.continue_on_error = True
config.start_stage = Stage.EXTRACT_MVC_AUDIO_AND_SUB
config.start_stage = Stage.EXTRACT_MVC_AND_AUDIO
self.start_processing(is_continuing=True)
return

Expand Down
6 changes: 4 additions & 2 deletions bd_to_avp/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

class Stage(Enum):
CREATE_MKV = auto()
EXTRACT_MVC_AUDIO_AND_SUB = auto()
EXTRACT_MVC_AND_AUDIO = auto()
EXTRACT_SUBTITLES = auto()
CREATE_LEFT_RIGHT_FILES = auto()
COMBINE_TO_MV_HEVC = auto()
UPSCALE_VIDEO = auto()
Expand All @@ -26,7 +27,8 @@ def __str__(self) -> str:
def human_readable(self) -> str:
return {
"CREATE_MKV": "Create MKV",
"EXTRACT_MVC_AUDIO_AND_SUB": "Extract MVC Audio and Sub",
"EXTRACT_MVC_AND_AUDIO": "Extract MVC and Audio",
"EXTRACT_SUBTITLES": "Extract Subtitles",
"CREATE_LEFT_RIGHT_FILES": "Create Left Right Files",
"UPSCALE_VIDEO": "Upscale Video",
"COMBINE_TO_MV_HEVC": "Combine to MV HEVC",
Expand Down
12 changes: 4 additions & 8 deletions bd_to_avp/modules/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from babelfish import Language

from bd_to_avp.modules.config import Stage, config
from bd_to_avp.modules.sub import extract_subtitle_to_srt
from bd_to_avp.modules.command import run_command, run_ffmpeg_print_errors
from bd_to_avp.modules.util import sorted_files_by_creation_filtered_on_suffix

Expand Down Expand Up @@ -42,18 +41,15 @@ def create_muxed_file(
return muxed_path


def create_mvc_audio_and_subtitle_files(
def create_mvc_and_audio(
disc_name: str,
mkv_output_path: Path | None,
mkv_output_path: Path,
output_folder: Path,
) -> tuple[Path, Path]:
video_output_path = output_folder / f"{disc_name}_mvc.h264"
audio_output_path = output_folder / f"{disc_name}_audio_PCM.mov"

if config.start_stage.value <= Stage.EXTRACT_MVC_AUDIO_AND_SUB.value and mkv_output_path:
if not config.skip_subtitles:
extract_subtitle_to_srt(mkv_output_path, output_folder)

if config.start_stage.value <= Stage.EXTRACT_MVC_AND_AUDIO.value:
extract_mvc_and_audio(
mkv_output_path,
video_output_path,
Expand Down Expand Up @@ -113,7 +109,7 @@ def mux_video_audio_subs(mv_hevc_path: Path, audio_path: Path, muxed_path: Path,
output_track_index += 1

command += [muxed_path]
run_command(command, "Mux video, audio, and subtitles.")
run_command(command, "mux video, audio, and subtitles.")


def get_audio_stream_data(file_path: Path) -> list[dict[str, Any]]:
Expand Down
8 changes: 4 additions & 4 deletions bd_to_avp/modules/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

from bd_to_avp.modules.audio import create_transcoded_audio_file
from bd_to_avp.modules.config import config
from bd_to_avp.modules.container import create_muxed_file, create_mvc_audio_and_subtitle_files
from bd_to_avp.modules.container import create_muxed_file, create_mvc_and_audio
from bd_to_avp.modules.disc import create_mkv_file, get_disc_and_mvc_video_info
from bd_to_avp.modules.file import (
file_exists_normalized,
move_file_to_output_root_folder,
prepare_output_folder_for_source,
remove_folder_if_exists,
)
from bd_to_avp.modules.sub import create_srt_from_mkv
from bd_to_avp.modules.video import (
create_left_right_files,
create_mv_hevc_file,
Expand Down Expand Up @@ -64,9 +65,8 @@ def process_each() -> None:

mkv_output_path = create_mkv_file(output_folder, disc_info, config.language_code)
crop_params = detect_crop_parameters(mkv_output_path)
audio_output_path, video_output_path = create_mvc_audio_and_subtitle_files(
disc_info.name, mkv_output_path, output_folder
)
audio_output_path, video_output_path = create_mvc_and_audio(disc_info.name, mkv_output_path, output_folder)
create_srt_from_mkv(mkv_output_path, output_folder)
left_output_path, right_output_path = create_left_right_files(
disc_info, output_folder, video_output_path, crop_params
)
Expand Down
9 changes: 8 additions & 1 deletion bd_to_avp/modules/sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
from babelfish import Language
from pgsrip import Mkv, Options, pgsrip

from bd_to_avp.modules.config import config
from bd_to_avp.modules.config import config, Stage
from bd_to_avp.modules.command import Spinner


class SRTCreationError(Exception):
pass


def create_srt_from_mkv(mkv_path: Path, output_path: Path) -> None:
if config.start_stage.value <= Stage.EXTRACT_SUBTITLES.value:
if config.skip_subtitles:
return None
extract_subtitle_to_srt(mkv_path, output_path)


def extract_subtitle_to_srt(mkv_path: Path, output_path: Path) -> None:
if config.skip_subtitles:
return None
Expand Down

0 comments on commit 2cee350

Please sign in to comment.