Remove exit from pipeline.

This commit is contained in:
Frédéric Tronel
2026-08-31 08:57:28 +02:00
parent 1a616f6cbd
commit d1df44c82c
4 changed files with 19 additions and 29 deletions
+3 -5
View File
@@ -5,9 +5,8 @@
import logging import logging
from typing import IO from typing import IO
from tscut.tools.mkvtoolnix import ( from tscut.tools.mkvtoolnix import extract_mkv_part
extract_mkv_part, from tscut.exceptions import TemporaryFileError
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -22,8 +21,7 @@ def do_coarse_processing(ffmpeg_path:str, ffprobe_path:str, mkvmerge_path:str,
try: try:
internal_mkv = open(internal_mkv_name, 'wb+') internal_mkv = open(internal_mkv_name, 'wb+')
except OSError: except OSError:
logger.error('Impossible to create file: %s', internal_mkv_name) raise TemporaryFileError(f"Impossible to create {internal_mkv_name}")
exit(-1)
# Extract internal part of MKV # Extract internal part of MKV
extract_mkv_part(mkvmerge_path=mkvmerge_path, input_file=input_file, output_file=internal_mkv, extract_mkv_part(mkvmerge_path=mkvmerge_path, input_file=input_file, output_file=internal_mkv,
+1 -1
View File
@@ -57,5 +57,5 @@ class PreparedMedia:
@dataclass @dataclass
class CutResult: class CutResult:
filename: str filename: str
movie: IO[bytes] movie: BinaryIO
check_positions: list[timedelta] check_positions: list[timedelta]
+13 -20
View File
@@ -7,13 +7,12 @@ import os
from datetime import datetime, timedelta from datetime import datetime, timedelta
from os import unlink from os import unlink
from shutil import copyfile, move from shutil import copyfile, move
from sys import exit
from typing import IO, Any, BinaryIO from typing import IO, Any, BinaryIO
import hexdump import hexdump
from tscut.cutting import cut_recording from tscut.cutting import cut_recording
from tscut.exceptions import InvalidMediaError from tscut.exceptions import InvalidMediaError, TemporaryFileError
from tscut.h264.avc import parse_codec_private from tscut.h264.avc import parse_codec_private
from tscut.matroska.codec import dump_codec_private_data from tscut.matroska.codec import dump_codec_private_data
from tscut.models import PreparedMedia, ProcessingOptions, SupportedFormat from tscut.models import PreparedMedia, ProcessingOptions, SupportedFormat
@@ -55,8 +54,7 @@ def process_recording(options: ProcessingOptions) -> None:
input_file = open(options.input_file, mode='rb') input_file = open(options.input_file, mode='rb')
logger.debug("Type of input file: %s", type(input_file)) logger.debug("Type of input file: %s", type(input_file))
except OSError: except OSError:
logger.error("Impossible to open %s", options.input_file) raise InvalidMediaError(f"Impossible to open {options.input_file}")
exit(-1)
format_of_file = get_format(options.tools_paths['ffprobe'], input_file) format_of_file = get_format(options.tools_paths['ffprobe'], input_file)
@@ -95,21 +93,22 @@ def process_recording(options: ProcessingOptions) -> None:
try: try:
mkv = open(mkvfilename, 'wb+') mkv = open(mkvfilename, 'wb+')
except OSError: except OSError:
logger.error('') raise TemporaryFileError(f"Impossible to create: {mkvfilename}")
ffmpeg_convert(options.tools_paths['ffmpeg'], options.tools_paths['ffprobe'], ffmpeg_convert(options.tools_paths['ffmpeg'], options.tools_paths['ffprobe'],
mp4, 'mp4', mkv, 'matroska', duration) mp4, 'mp4', mkv, 'matroska', duration)
if nb_parts > 0: if nb_parts > 0:
temporaries.append(mkv) temporaries.append(mkv)
except OSError: except OSError:
logger.error('') raise TemporaryFileError(f"Impossible to create: {mp4filename}")
elif final_format_of_file == SupportedFormat.MP4: elif final_format_of_file == SupportedFormat.MP4:
logger.info("Converting MP4 to MKV") logger.info("Converting MP4 to MKV")
try: try:
mkv = open(mkvfilename, 'wb+') mkv = open(mkvfilename, 'wb+')
except OSError: except OSError:
logger.error('') raise TemporaryFileError(f"Impossible to create: {mkvfilename}")
ffmpeg_convert(options.tools_paths['ffmpeg'], options.tools_paths['ffprobe'], ffmpeg_convert(options.tools_paths['ffmpeg'], options.tools_paths['ffprobe'],
input_file, 'mp4', mkv, 'matroska', duration) input_file, 'mp4', mkv, 'matroska', duration)
if nb_parts > 0: if nb_parts > 0:
@@ -120,8 +119,7 @@ def process_recording(options: ProcessingOptions) -> None:
streams = get_streams(options.tools_paths['ffprobe'], mkv) streams = get_streams(options.tools_paths['ffprobe'], mkv)
if streams is None: if streams is None:
logger.error("No streams found in file: %s", mkv) raise InvalidMediaError(f"No streams found in file: {mkv}")
exit(-1)
logger.debug('Streams: %s', streams) logger.debug('Streams: %s', streams)
main_video = None main_video = None
@@ -142,8 +140,7 @@ def process_recording(options: ProcessingOptions) -> None:
main_video = None main_video = None
if main_video is None: if main_video is None:
logger.error('Impossible to find main video stream.') raise InvalidMediaError(f"Impossible to find main video stream.")
exit(-1)
# We retrieve the main private codec data # We retrieve the main private codec data
_, main_codec_private_data = get_codec_private_data_from_mkv( _, main_codec_private_data = get_codec_private_data_from_mkv(
@@ -154,8 +151,7 @@ def process_recording(options: ProcessingOptions) -> None:
hexdump.dump(main_codec_private_data, sep=':')) hexdump.dump(main_codec_private_data, sep=':'))
if main_codec_private_data is None: if main_codec_private_data is None:
logger.error("Impossible to retrieve private data from MKV file %s", mkv) raise InvalidMediaError(f"Impossible to retrieve private data from MKV file {mkv}")
exit(-1)
# We parse them # We parse them
main_avc_config = parse_codec_private(main_codec_private_data) main_avc_config = parse_codec_private(main_codec_private_data)
@@ -176,9 +172,8 @@ def process_recording(options: ProcessingOptions) -> None:
# If there exists a difference between our own reconstructed AVC configuration and the # If there exists a difference between our own reconstructed AVC configuration and the
# original one, we abandon # original one, we abandon
if iso_avc_config != main_avc_config: if iso_avc_config != main_avc_config:
logger.error('AVC configurations are different: %s\n%s\n', main_avc_config, raise InvalidMediaError(f"AVC configurations are different:\
iso_avc_config) {main_avc_config}\n{iso_avc_config}\n")
exit(-1)
prepared_movie = PreparedMedia( prepared_movie = PreparedMedia(
basename = basename, basename = basename,
@@ -237,13 +232,11 @@ def process_recording(options: ProcessingOptions) -> None:
try: try:
idx = open(idx_name,'rb') idx = open(idx_name,'rb')
except OSError: except OSError:
logger.error("Impossible to open %s.", idx_name) raise TemporaryFileError(f"Impossible to open {idx_name}")
exit(-1)
try: try:
sub = open(sub_name,'rb') sub = open(sub_name,'rb')
except OSError: except OSError:
logger.error("Impossible to open %s.", sub_name) raise TemporaryFileError(f"Impossible to open {sub_name}")
exit(-1)
temporaries.append(idx) temporaries.append(idx)
temporaries.append(sub) temporaries.append(sub)
+2 -3
View File
@@ -129,7 +129,7 @@ def change_codec_private_data(mkvinfo_path:str, input_file: IO[bytes],
logger.info('Current size of file: %d', current_length) logger.info('Current size of file: %d', current_length)
position, current_data = get_codec_private_data_from_mkv(mkvinfo_path, input_file) position, current_data = get_codec_private_data_from_mkv(mkvinfo_path, input_file)
if position is None or current_data is None: if position is None or current_data is None:
return None raise InvalidMediaError(f"Impossible to retrieve private data from file")
current_data_length = len(current_data) current_data_length = len(current_data)
future_length = current_length - current_data_length + len(codec_data) future_length = current_length - current_data_length + len(codec_data)
logger.info('Expected size of file: %d', future_length) logger.info('Expected size of file: %d', future_length)
@@ -147,8 +147,7 @@ def change_codec_private_data(mkvinfo_path:str, input_file: IO[bytes],
break break
if not found: if not found:
logger.error('Impossible to retrieve the key of codec private data') raise InvalidMediaError(f"Impossible to retrieve the key of codec private data")
raise InvalidMediaError("")
if current_length < future_length: if current_length < future_length:
lseek(infd, position+current_data_length, SEEK_SET) lseek(infd, position+current_data_length, SEEK_SET)