diff --git a/ffconv/args.py b/ffconv/args.py index fe5653a..c3df227 100644 --- a/ffconv/args.py +++ b/ffconv/args.py @@ -3,8 +3,8 @@ import click from ffconv.helper import ( - read_json, files_in_dir, + read_json, replace_conflicting_characters_in_filename, ) @@ -86,8 +86,8 @@ def __call__(self, ctx, param, value): if p.suffix: if not p.parent.is_dir(): raise FileNotFoundError( - f"The parent directory `{str(p.parent)}` " - f"for output argument `{str(p)}` does not exist." + f"The parent directory `{p.parent!s}` " + f"for output argument `{p!s}` does not exist." ) else: current_batch = { diff --git a/ffconv/cli.py b/ffconv/cli.py index c40cf74..3813faa 100644 --- a/ffconv/cli.py +++ b/ffconv/cli.py @@ -3,27 +3,27 @@ from pathlib import Path import click +from loguru import logger from rich.prompt import IntPrompt from ffconv.args import ( + AutoAudioFlagChecker, InputPathChecker, - OutputPathChecker, - PresetPathChecker, OptionalValueChecker, + OutputPathChecker, PresetOptionalChecker, - AutoAudioFlagChecker, + PresetPathChecker, ) from ffconv.exception import StreamOrderError, StreamTypeMissingError from ffconv.helper import ( - split_list_of_dicts_by_key, combine_arguments_by_batch, - remove_empty_dict_values, dict_to_list, preprocess_streams, + remove_empty_dict_values, + split_list_of_dicts_by_key, ) from ffconv.process import ProcessCommand from ffconv.table import table_print_stream_options -from loguru import logger # noqa def validate_stream_order(mkvmerge_identify_result, file_details): @@ -116,21 +116,9 @@ def stream_user_input(mkvmerge_identify_result): { "id": cs["id"], "codec": cs["properties"]["codec_id"], - "language": ( - cs["properties"]["language"] - if "language" in cs["properties"] - else "n/a" - ), - "title": ( - cs["properties"]["track_name"] - if "track_name" in cs["properties"] - else "n/a" - ), - "default": ( - cs["properties"]["default_track"] - if "default_track" in cs["properties"] - else "n/a" - ), + "language": cs["properties"].get("language", "n/a"), + "title": cs["properties"].get("track_name", "n/a"), + "default": cs["properties"].get("default_track", "n/a"), } for cs in stream_info["streams"] ] @@ -302,7 +290,7 @@ def ffmpeg_convert_file( audio_map_index = "0:" + str(stream_mapping["audio"]["id"]) # Filter complex subtitle map requires this escaped monstrosity for Windows - lit_file = str(input_file).replace("\\", "\\\\").replace(":", "\:") + lit_file = str(input_file).replace("\\", "\\\\").replace(":", r"\:") filter_complex_map = ( "subtitles='" + lit_file + "':si=" + str(stream_mapping["subtitles"]["id"]), ) @@ -326,7 +314,7 @@ def ffmpeg_convert_file( filter_complex_map_concat = ",".join(filter_complex_map) filter_complex_map_complete = f"[{video_map_index}]{filter_complex_map_concat}" - current_datetime = datetime.now() + current_datetime = datetime.now().astimezone() metadata_encoded_date = ( f'comment=Encoded on {current_datetime.strftime("%Y-%m-%d %H:%M:%S")}' ) @@ -467,7 +455,7 @@ def cli( for current_file_path_index, current_file_path in enumerate( current_input_files ): - mkvmerge_identify_result, mapping = mkvmerge_identify_streams( + _mkvmerge_identify_result, mapping = mkvmerge_identify_streams( current_file_path, total_current_input_files, current_file_path_index, diff --git a/ffconv/helper.py b/ffconv/helper.py index 2d6343c..4a05b0a 100644 --- a/ffconv/helper.py +++ b/ffconv/helper.py @@ -6,7 +6,7 @@ from pathlib import Path -def files_in_dir(path: Path, file_types=["*.mkv"]): +def files_in_dir(path: Path, file_types=None): """ Returns a list of files in the given directory that match the specified file types. @@ -18,6 +18,9 @@ def files_in_dir(path: Path, file_types=["*.mkv"]): List[Path]: A list of paths to the files in the directory that match the specified file types. """ + if file_types is None: + file_types = ["*.mkv"] + file_list = [ f for f in path.rglob("*") diff --git a/ffconv/process.py b/ffconv/process.py index 920db94..a0ca24b 100644 --- a/ffconv/process.py +++ b/ffconv/process.py @@ -1,6 +1,6 @@ import subprocess as sp -from ffconv.exception import MKVmergeError, ProcessError, FFmpegError +from ffconv.exception import FFmpegError, MKVmergeError, ProcessError class ProcessCommand: @@ -43,7 +43,7 @@ def run(self, process, command): f"The following {process} command will be executed: {' '.join(command)}" ) - response = sp.run(command, stdout=sp.PIPE, stderr=sp.PIPE) + response = sp.run(command, capture_output=True, check=False) return_code = response.returncode if return_code == 0: self.logger.info(f"{process} completed.") diff --git a/ffconv/table.py b/ffconv/table.py index eaa5364..0576efe 100644 --- a/ffconv/table.py +++ b/ffconv/table.py @@ -18,7 +18,7 @@ def table_print_stream_options(tracks: list) -> None: table = Table(show_header=True, header_style="bold cyan") # Header - for key in tracks[0].keys(): + for key in tracks[0]: table.add_column(key.capitalize()) # Rows diff --git a/requirements.dev.txt b/requirements.dev.txt index b0c07a1..cd474af 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -1,3 +1,3 @@ -ruff==0.15.20 +ruff==0.16.4 mypy==2.3.1 black==26.5.1 diff --git a/setup.py b/setup.py index 83825d9..3e343c0 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ -from setuptools import setup, find_packages # type: ignore import os +from setuptools import find_packages, setup # type: ignore + VERSION = "3.0.0"