|
| 1 | +import logging |
| 2 | +import math |
| 3 | +from pathlib import Path |
| 4 | +from shutil import which |
| 5 | +import subprocess |
| 6 | + |
| 7 | +from PIL import Image, ImageQt |
| 8 | +from PySide6.QtCore import Signal, Qt, QUrl |
| 9 | +from PySide6.QtGui import QPixmap, QDesktopServices |
| 10 | +from PySide6.QtWidgets import QMessageBox |
| 11 | + |
| 12 | + |
| 13 | +class FfmpegChecker(QMessageBox): |
| 14 | + """A warning dialog for if FFmpeg is missing.""" |
| 15 | + |
| 16 | + HELP_URL = "https://docs.tagstud.io/help/ffmpeg/" |
| 17 | + |
| 18 | + def __init__(self): |
| 19 | + super().__init__() |
| 20 | + |
| 21 | + self.setWindowTitle("Warning: Missing dependency") |
| 22 | + self.setText("Warning: Could not find FFmpeg installation") |
| 23 | + self.setIcon(QMessageBox.Warning) |
| 24 | + # Blocks other application interactions until resolved |
| 25 | + self.setWindowModality(Qt.ApplicationModal) |
| 26 | + |
| 27 | + self.setStandardButtons( |
| 28 | + QMessageBox.Help | QMessageBox.Ignore | QMessageBox.Cancel |
| 29 | + ) |
| 30 | + self.setDefaultButton(QMessageBox.Ignore) |
| 31 | + # Enables the cancel button but hides it to allow for click X to close dialog |
| 32 | + self.button(QMessageBox.Cancel).hide() |
| 33 | + |
| 34 | + self.ffmpeg = False |
| 35 | + self.ffprobe = False |
| 36 | + |
| 37 | + def installed(self): |
| 38 | + """Checks if both FFmpeg and FFprobe are installed and in the PATH.""" |
| 39 | + if which("ffmpeg"): |
| 40 | + self.ffmpeg = True |
| 41 | + if which("ffprobe"): |
| 42 | + self.ffprobe = True |
| 43 | + |
| 44 | + logging.info( |
| 45 | + f"[FFmpegChecker] FFmpeg found: {self.ffmpeg}, FFprobe found: {self.ffprobe}" |
| 46 | + ) |
| 47 | + return self.ffmpeg and self.ffprobe |
| 48 | + |
| 49 | + def show_warning(self): |
| 50 | + """Displays the warning to the user and awaits respone.""" |
| 51 | + missing = "FFmpeg" |
| 52 | + # If ffmpeg is installed but not ffprobe |
| 53 | + if not self.ffprobe and self.ffmpeg: |
| 54 | + missing = "FFprobe" |
| 55 | + |
| 56 | + self.setText(f"Warning: Could not find {missing} installation") |
| 57 | + self.setInformativeText( |
| 58 | + f"{missing} is required for multimedia thumbnails and playback" |
| 59 | + ) |
| 60 | + # Shows the dialog |
| 61 | + selection = self.exec() |
| 62 | + |
| 63 | + # Selection will either be QMessageBox.Help or (QMessageBox.Ignore | QMessageBox.Cancel) which can be ignored |
| 64 | + if selection == QMessageBox.Help: |
| 65 | + QDesktopServices.openUrl(QUrl(self.HELP_URL)) |
0 commit comments