diff --git a/tests/test_audio.py b/tests/test_audio.py index 4cc2bc4..a298079 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -53,7 +53,7 @@ def test_detect_silences_small(): small_distance = 0.100 silences = detect_silences( - audio_stub['path'], distance='small', force=True + audio_stub['path'], distance='small', force=True, ) times = chain.from_iterable( @@ -71,7 +71,7 @@ def test_detect_silences_negative(): negative_distance = 0.100 silences = detect_silences( - audio_stub['path'], distance='small', force=True + audio_stub['path'], distance='small', force=True, ) times = chain.from_iterable( diff --git a/tests/test_cli.py b/tests/test_cli.py index 35f9d87..a14f754 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -16,7 +16,7 @@ def test_cli_version(): @pytest.mark.slow('LanguageTool take seconds to start!') def test_grammar_check(): response = cli.invoke( - app, 'grammar-check tests/test_assets/grammar_file.txt' + app, 'grammar-check tests/test_assets/grammar_file.txt', ) assert 'UPPERCASE_SENTENCE_START' in response.stdout diff --git a/vmh/audio.py b/vmh/audio.py index 89e91c1..b265913 100644 --- a/vmh/audio.py +++ b/vmh/audio.py @@ -62,7 +62,7 @@ def transcribe_audio( cache = db.search( (where('file_name') == str(audio_path)) - & (where('type') == 'transcribe') + & (where('type') == 'transcribe'), ) if not cache: @@ -73,7 +73,7 @@ def transcribe_audio( 'type': 'transcribe', 'file_name': str(audio_path), 'data': result, - } + }, ) else: result = cache[0]['data'] @@ -123,7 +123,7 @@ def transcribe_audio( def extract_audio( - video_file: str, output_file: str, eq: bool = True + video_file: str, output_file: str, eq: bool = True, ) -> Path | tuple[Path, ...]: """Extract audio from vĂ­deo. @@ -156,7 +156,7 @@ def cut_silences( logger.info(f'File read: {audio_file}') silences = silence.split_on_silence( - audio, min_silence_len=silence_time, silence_thresh=threshold + audio, min_silence_len=silence_time, silence_thresh=threshold, ) combined = AudioSegment.empty() @@ -176,7 +176,7 @@ def _audio_chain(silences, distance): (stop / 1_000) - threshold_distance[distance], ] for start, stop in silences - ) + ), ) @@ -185,7 +185,7 @@ def detect_silences( silence_time: int = 400, threshold: int = -65, distance: Literal[ - 'negative', 'tiny', 'small', 'medium', 'large', 'huge' + 'negative', 'tiny', 'small', 'medium', 'large', 'huge', ] = 'tiny', *, force: bool = False, @@ -193,7 +193,7 @@ def detect_silences( times = db.search( (where('file_name') == audio_file) & (where('type') == 'silence') - & (where('distance') == distance) + & (where('distance') == distance), ) if not times or force: @@ -203,7 +203,7 @@ def detect_silences( logger.info(f'Analyze silences in {audio_file}') silences = silence.detect_silence( - audio, min_silence_len=silence_time, silence_thresh=threshold + audio, min_silence_len=silence_time, silence_thresh=threshold, ) logger.info(f'Finalized analysis: {audio_file}') @@ -217,7 +217,7 @@ def detect_silences( 'file_name': str(audio_file), 'times': times, 'distance': distance, - } + }, ) logger.info(f'Found {len(times)} silences in audio') diff --git a/vmh/cli.py b/vmh/cli.py index 1753507..8e92f62 100644 --- a/vmh/cli.py +++ b/vmh/cli.py @@ -30,7 +30,7 @@ ) threshold_option = Option( - -65, '--threshold', '-t', help='Value in db for detect silence' + -65, '--threshold', '-t', help='Value in db for detect silence', ) distance_option = Option( @@ -71,7 +71,7 @@ def extract_audio( audio_file: path_arg, output_file: Path = Argument(default='output.wav'), eq: bool = Option( - True, help='Add compression and 10db of extracted audio' + True, help='Add compression and 10db of extracted audio', ), ): """Extracts the audio from a video.""" @@ -98,8 +98,8 @@ def silences( threshold=threshold, distance=distance.value, force=force, - ) - ) + ), + ), ) @@ -117,7 +117,7 @@ def cut_silences( str(output_file), silence_time=silence_time, threshold=threshold, - ) + ), ) @@ -138,7 +138,7 @@ def kdenlive( video_file: path_arg, output_path: Path = Argument(default='cuts.kdenlive'), audio_file: Path = Argument( - default='', help='Optional audio equilized audio file' + default='', help='Optional audio equilized audio file', ), silence_time: int = silence_option, threshold: int = threshold_option, @@ -165,7 +165,7 @@ def kdenlive( threshold, force, distance.value, - ) + ), ) @@ -174,7 +174,7 @@ def cut_video( video_file: path_arg, output_path: Path = Argument(default='result.mp4'), audio_file: str = Argument( - default='', help='Optional audio equilized audio file' + default='', help='Optional audio equilized audio file', ), silence_time: int = silence_option, threshold: int = threshold_option, diff --git a/vmh/equalize.py b/vmh/equalize.py index 7acd99a..ff8cda3 100644 --- a/vmh/equalize.py +++ b/vmh/equalize.py @@ -53,7 +53,7 @@ def process_audio( ) -> Path: with AudioFile(input_file, 'r') as ifile: with AudioFile( - output_file, 'w', ifile.samplerate, ifile.num_channels + output_file, 'w', ifile.samplerate, ifile.num_channels, ) as ofile: while ifile.tell() < ifile.frames: chunk = ifile.read(ifile.samplerate) diff --git a/vmh/kdenlive.py b/vmh/kdenlive.py index 2b28a0e..c6e2912 100644 --- a/vmh/kdenlive.py +++ b/vmh/kdenlive.py @@ -16,7 +16,7 @@ def check_chain( - filename: Path, input_file: Path, property: int | None = None + filename: Path, input_file: Path, property: int | None = None, ) -> tuple[str, ...]: with open(input_file) as f: content = f.read() @@ -30,7 +30,7 @@ def check_chain( and (./property[(@name='set.test_audio' and ./text()='{property}')]) )] -""" +""", ) else: el = s.xpath(f'//chain/property[text() = "{filename.name}"]/..') @@ -41,7 +41,7 @@ def check_chain( _id = cast(str, _id) playlists = s.xpath( - f'//playlist/entry[@producer="{_chain}"]/..' + f'//playlist/entry[@producer="{_chain}"]/..', ).xpath('@id') logger.debug(f'Playlists: {filename}-{playlists}') @@ -80,7 +80,7 @@ def kdenlive_xml( entry = ElementTree.SubElement(playlist, 'entry', attrib=entry_attribs) ElementTree.SubElement( - entry, 'property', attrib={'name': 'kdenlive:id'} + entry, 'property', attrib={'name': 'kdenlive:id'}, ).text = property_id if overwrite: @@ -100,16 +100,16 @@ def cut( threshold: int, force: bool, distance: Literal[ - 'negative', 'tiny', 'small', 'medium', 'large', 'huge' + 'negative', 'tiny', 'small', 'medium', 'large', 'huge', ] = 'tiny', ) -> Path: if audio_file != Path(getcwd()): # Typer don't support Path | None times = detect_silences( - str(audio_file), silence_time, threshold, distance, force=force + str(audio_file), silence_time, threshold, distance, force=force, ) else: times = detect_silences( - str(video_file), silence_time, threshold, distance, force=force + str(video_file), silence_time, threshold, distance, force=force, ) chain_id, file_id, playlist = check_chain(video_file, input_file, 0) diff --git a/vmh/plot.py b/vmh/plot.py index da88259..931d33d 100644 --- a/vmh/plot.py +++ b/vmh/plot.py @@ -24,7 +24,7 @@ def compare_waves( ) -> None: """Plot a figure with N audio waves for comparison.""" _, ax = plt.subplots( - nrows=len(files), sharex=True, figsize=fig_size, tight_layout=True + nrows=len(files), sharex=True, figsize=fig_size, tight_layout=True, ) for n, file in enumerate(files): diff --git a/vmh/video.py b/vmh/video.py index 399b35c..331d699 100644 --- a/vmh/video.py +++ b/vmh/video.py @@ -42,7 +42,7 @@ def cut_video( silence_time: int, threshold: int, distance: Literal[ - 'negative', 'tiny', 'small', 'medium', 'large', 'huge' + 'negative', 'tiny', 'small', 'medium', 'large', 'huge', ] = 'tiny', bitrate: str = '15M', codec: Codec = Codec.mpeg4,