Skip to content

Commit

Permalink
FIX: Ruff autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
dunossauro committed Jan 3, 2024
1 parent 7fce44b commit 892049e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 9 additions & 9 deletions vmh/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -73,7 +73,7 @@ def transcribe_audio(
'type': 'transcribe',
'file_name': str(audio_path),
'data': result,
}
},
)
else:
result = cache[0]['data']
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -176,7 +176,7 @@ def _audio_chain(silences, distance):
(stop / 1_000) - threshold_distance[distance],
]
for start, stop in silences
)
),
)


Expand All @@ -185,15 +185,15 @@ 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,
) -> list[float]:
times = db.search(
(where('file_name') == audio_file)
& (where('type') == 'silence')
& (where('distance') == distance)
& (where('distance') == distance),
)

if not times or force:
Expand All @@ -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}')
Expand All @@ -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')
Expand Down
16 changes: 8 additions & 8 deletions vmh/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
Expand All @@ -98,8 +98,8 @@ def silences(
threshold=threshold,
distance=distance.value,
force=force,
)
)
),
),
)


Expand All @@ -117,7 +117,7 @@ def cut_silences(
str(output_file),
silence_time=silence_time,
threshold=threshold,
)
),
)


Expand All @@ -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,
Expand All @@ -165,7 +165,7 @@ def kdenlive(
threshold,
force,
distance.value,
)
),
)


Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion vmh/equalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions vmh/kdenlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}"]/..')
Expand All @@ -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}')
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion vmh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion vmh/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 892049e

Please sign in to comment.