✨ Downloader will check for FFmpeg before converting video files.

This commit is contained in:
Robert Honz
2024-03-22 15:50:06 +01:00
parent 12d3360c12
commit d331f93c91
4 changed files with 67 additions and 24 deletions
+1 -1
View File
@@ -170,7 +170,7 @@ profile = "black"
multi_line_output = 3 multi_line_output = 3
indent = 4 indent = 4
color_output = true color_output = true
known_third_party = ["Crypto", "PySide6", "coloredlogs", "dataclasses_json", "ffmpeg", "m3u8", "mpegdash", "mutagen", "pathvalidate", "requests", "rich", "tidalapi", "typer"] known_third_party = ["Crypto", "PySide6", "coloredlogs", "dataclasses_json", "ffmpeg", "helper", "m3u8", "mpegdash", "mutagen", "pathvalidate", "requests", "rich", "tidalapi", "typer"]
[tool.mypy] [tool.mypy]
# https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file # https://mypy.readthedocs.io/en/latest/config_file.html#using-a-pyproject-toml-file
+50 -22
View File
@@ -2,6 +2,7 @@ import os.path
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from helper.path import is_installed_ffmpeg
from PySide6 import QtCore, QtGui, QtWidgets from PySide6 import QtCore, QtGui, QtWidgets
from tidalapi import Quality as QualityAudio from tidalapi import Quality as QualityAudio
@@ -86,19 +87,39 @@ class DialogPreferences(QtWidgets.QDialog):
pixmapi: QtWidgets.QStyle.StandardPixmap = QtWidgets.QStyle.SP_MessageBoxQuestion pixmapi: QtWidgets.QStyle.StandardPixmap = QtWidgets.QStyle.SP_MessageBoxQuestion
self.icon = self.style().standardIcon(pixmapi) self.icon = self.style().standardIcon(pixmapi)
self.parameters_checkboxes = [ self._init_checkboxes()
"lyrics_embed", self._init_comboboxes()
"lyrics_file", self._init_line_edit()
"video_download",
"download_delay", # Create an instance of the GUI
"video_convert_mp4", self.ui = Ui_DialogSettings()
]
self.parameters_combo = [ # Run the .setupUi() method to show the GUI
("skip_existing", SkipExisting), self.ui.setupUi(self)
("quality_audio", QualityAudio), # Set data.
("quality_video", QualityVideo), self.gui_populate()
("metadata_cover_dimension", CoverDimensions), self._init_signals()
]
self.exec()
def _init_signals(self):
self.ui.cb_video_convert_mp4.stateChanged.connect(self.on_cb_video_convert_mp4)
def on_cb_video_convert_mp4(self, int):
if self.ui.cb_video_convert_mp4.isChecked():
# Check if ffmpeg is in PATH otherwise show error message.
if not is_installed_ffmpeg():
self.ui.cb_video_convert_mp4.setChecked(False)
self.ui.cb_video_convert_mp4.setCheckState(QtCore.Qt.CheckState.Unchecked)
QtWidgets.QMessageBox.critical(
self,
"FFmpeg not found!",
"Either FFmpeg is not installed on your computer or not set within "
"your PATH variable. You cannot activate this option until FFmpeg "
"is correctly installed and set to your environmental PATH variable.",
)
def _init_line_edit(self):
self.parameters_line_edit = [ self.parameters_line_edit = [
"download_base_path", "download_base_path",
"format_album", "format_album",
@@ -108,15 +129,22 @@ class DialogPreferences(QtWidgets.QDialog):
"format_video", "format_video",
] ]
# Create an instance of the GUI def _init_comboboxes(self):
self.ui = Ui_DialogSettings() self.parameters_combo = [
("skip_existing", SkipExisting),
("quality_audio", QualityAudio),
("quality_video", QualityVideo),
("metadata_cover_dimension", CoverDimensions),
]
# Run the .setupUi() method to show the GUI def _init_checkboxes(self):
self.ui.setupUi(self) self.parameters_checkboxes = [
# Set data. "lyrics_embed",
self.gui_populate() "lyrics_file",
"video_download",
self.exec() "download_delay",
"video_convert_mp4",
]
def gui_populate(self): def gui_populate(self):
self.populate_checkboxes() self.populate_checkboxes()
@@ -190,7 +218,7 @@ class DialogPreferences(QtWidgets.QDialog):
checkbox.setChecked(getattr(self.data, pn)) checkbox.setChecked(getattr(self.data, pn))
def accept(self): def accept(self):
# Get settings. TODO # Get settings.
self.to_settings() self.to_settings()
self.done(1) self.done(1)
+8 -1
View File
@@ -29,7 +29,7 @@ from tidal_dl_ng.constants import (
) )
from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token from tidal_dl_ng.helper.decryption import decrypt_file, decrypt_security_token
from tidal_dl_ng.helper.exceptions import MediaMissing, UnknownManifestFormat from tidal_dl_ng.helper.exceptions import MediaMissing, UnknownManifestFormat
from tidal_dl_ng.helper.path import check_file_exists, format_path_media, path_file_sanitize from tidal_dl_ng.helper.path import check_file_exists, format_path_media, is_installed_ffmpeg, path_file_sanitize
from tidal_dl_ng.helper.tidal import ( from tidal_dl_ng.helper.tidal import (
instantiate_media, instantiate_media,
items_results_all, items_results_all,
@@ -82,6 +82,13 @@ class Download:
self.progress = progress self.progress = progress
self.path_base = path_base self.path_base = path_base
if not is_installed_ffmpeg() and self.settings.data.video_convert_mp4:
self.settings.data.video_convert_mp4 = False
self.fn_logger.error(
"Cannot find FFmpeg in PATH. Videos can be downloaded but will not be processed. "
"Make sure FFmpeg is installed correctly and present within your environmental PATH variable."
)
def _download( def _download(
self, self,
media: Track | Video, media: Track | Video,
+8
View File
@@ -2,6 +2,7 @@ import glob
import math import math
import os import os
import re import re
import shutil
from pathlib import Path, PosixPath from pathlib import Path, PosixPath
from pathvalidate import sanitize_filename, sanitize_filepath from pathvalidate import sanitize_filename, sanitize_filepath
@@ -261,3 +262,10 @@ def check_file_exists(path_file: str, extension_ignore: bool = False) -> bool:
result = bool(sum([glob.glob(_file) for _file in path_files], [])) result = bool(sum([glob.glob(_file) for _file in path_files], []))
return result return result
def is_installed_ffmpeg() -> bool:
# Checks if ffmpeg is found in PATH.
result: bool = bool(shutil.which("ffmpeg"))
return result