Skip to content

Commit

Permalink
fix(ui): use default audio icon if ffmpeg is absent (#471)
Browse files Browse the repository at this point in the history
* fix(ThumbRenderer): Use audio icon when no ffmpeg

When ffmpeg is missing, Popen raises a FileNotFound error. This would
be caught as an Unlinked file and use the broken file icon. The
exception is now caught and a more appropriate exception is raised in
its place.

* ruff formatting
  • Loading branch information
seakrueger authored Sep 8, 2024
1 parent 8c9b04d commit bf8816f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions tagstudio/src/qt/helpers/vendored/pydub/audio_segment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# type: ignore
# Copyright (C) 2022 James Robert (jiaaro).
# Licensed under the MIT License.
# Vendored from ffmpeg-python and ffmpeg-python PR#790 by amamic1803
# Vendored from pydub

from __future__ import division

Expand Down Expand Up @@ -729,7 +729,10 @@ def is_format(f):
info = None
else:
# PATCHED
info = _mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
try:
info = _mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
except FileNotFoundError:
raise ChildProcessError
if info:
audio_streams = [x for x in info['streams']
if x['codec_type'] == 'audio']
Expand Down Expand Up @@ -1400,4 +1403,4 @@ def _repr_html_(self):
"""
fh = self.export()
data = base64.b64encode(fh.read()).decode('ascii')
return src.format(base64=data)
return src.format(base64=data)
8 changes: 7 additions & 1 deletion tagstudio/src/qt/widgets/thumb_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ def _audio_waveform_thumb(
logging.error(
f"[ThumbRenderer][WAVEFORM][ERROR]: Couldn't render waveform for {filepath.name} ({type(e).__name__})"
)

return im

def _blender(self, filepath: Path) -> Image.Image:
Expand Down Expand Up @@ -1057,7 +1058,12 @@ def render(
size=(adj_size, adj_size),
pixel_ratio=pixel_ratio,
)
except (UnidentifiedImageError, DecompressionBombError, ValueError) as e:
except (
UnidentifiedImageError,
DecompressionBombError,
ValueError,
ChildProcessError,
) as e:
logging.info(
f"[ThumbRenderer][ERROR]: Couldn't render thumbnail for {_filepath.name} ({type(e).__name__})"
)
Expand Down

0 comments on commit bf8816f

Please sign in to comment.