1- import contextlib
2- import subprocess
31from shutil import which
42
53import structlog
64from PySide6 .QtCore import Qt , QUrl
75from PySide6 .QtGui import QDesktopServices
86from PySide6 .QtWidgets import QMessageBox
97
8+ from tagstudio .core .palette import ColorType , UiColor , get_ui_color
109from tagstudio .qt .helpers .vendored .ffmpeg import FFMPEG_CMD , FFPROBE_CMD
10+ from tagstudio .qt .translations import Translations
1111
1212logger = structlog .get_logger (__name__ )
1313
@@ -20,10 +20,11 @@ class FfmpegChecker(QMessageBox):
2020 def __init__ (self ):
2121 super ().__init__ ()
2222
23- self .setWindowTitle ("Warning: Missing dependency" )
24- self .setText ("Warning: Could not find FFmpeg installation" )
23+ ffmpeg = "FFmpeg"
24+ ffprobe = "FFprobe"
25+ title = Translations .format ("dependency.missing.title" , dependency = ffmpeg )
26+ self .setWindowTitle (title )
2527 self .setIcon (QMessageBox .Icon .Warning )
26- # Blocks other application interactions until resolved
2728 self .setWindowModality (Qt .WindowModality .ApplicationModal )
2829
2930 self .setStandardButtons (
@@ -34,52 +35,19 @@ def __init__(self):
3435 self .setDefaultButton (QMessageBox .StandardButton .Ignore )
3536 # Enables the cancel button but hides it to allow for click X to close dialog
3637 self .button (QMessageBox .StandardButton .Cancel ).hide ()
38+ self .button (QMessageBox .StandardButton .Help ).clicked .connect (
39+ lambda : QDesktopServices .openUrl (QUrl (self .HELP_URL ))
40+ )
3741
38- self .ffmpeg = False
39- self .ffprobe = False
40-
41- def installed (self ):
42- """Checks if both FFmpeg and FFprobe are installed and in the PATH."""
43- if which (FFMPEG_CMD ):
44- self .ffmpeg = True
45- if which (FFPROBE_CMD ):
46- self .ffprobe = True
47-
48- logger .info ("FFmpeg found: {self.ffmpeg}, FFprobe found: {self.ffprobe}" )
49- return self .ffmpeg and self .ffprobe
50-
51- def version (self ):
52- """Checks the version of ffprobe and ffmpeg and returns None if they dont exist."""
53- version : dict [str , str | None ] = {"ffprobe" : None , "ffmpeg" : None }
54- self .installed ()
55- if self .ffprobe :
56- ret = subprocess .run (
57- [FFPROBE_CMD , "-show_program_version" ], shell = False , capture_output = True , text = True
58- )
59- if ret .returncode == 0 :
60- with contextlib .suppress (Exception ):
61- version ["ffprobe" ] = ret .stdout .split ("\n " )[1 ].replace ("-" , "=" ).split ("=" )[1 ]
62- if self .ffmpeg :
63- ret = subprocess .run (
64- [FFMPEG_CMD , "-version" ], shell = False , capture_output = True , text = True
65- )
66- if ret .returncode == 0 :
67- with contextlib .suppress (Exception ):
68- version ["ffmpeg" ] = ret .stdout .replace ("-" , " " ).split (" " )[2 ]
69- return version
70-
71- def show_warning (self ):
72- """Displays the warning to the user and awaits response."""
73- missing = "FFmpeg"
74- # If ffmpeg is installed but not ffprobe
75- if not self .ffprobe and self .ffmpeg :
76- missing = "FFprobe"
77-
78- self .setText (f"Warning: Could not find { missing } installation" )
79- self .setInformativeText (f"{ missing } is required for multimedia thumbnails and playback" )
80- # Shows the dialog
81- selection = self .exec ()
82-
83- # Selection will either be QMessageBox.Help or (QMessageBox.Ignore | QMessageBox.Cancel)
84- if selection == QMessageBox .StandardButton .Help :
85- QDesktopServices .openUrl (QUrl (self .HELP_URL ))
42+ red = get_ui_color (ColorType .PRIMARY , UiColor .RED )
43+ green = get_ui_color (ColorType .PRIMARY , UiColor .GREEN )
44+ missing = f"<span style='color:{ red } '>{ Translations ["generic.missing" ]} </span>"
45+ found = f"<span style='color:{ green } '>{ Translations ['about.module.found' ]} </span>"
46+ status = Translations .format (
47+ "ffmpeg.missing.status" ,
48+ ffmpeg = ffmpeg ,
49+ ffmpeg_status = found if which (FFMPEG_CMD ) else missing ,
50+ ffprobe = ffprobe ,
51+ ffprobe_status = found if which (FFPROBE_CMD ) else missing ,
52+ )
53+ self .setText (f"{ Translations ["ffmpeg.missing.description" ]} <br><br>{ status } " )
0 commit comments