diff options
| author | Robert Honz <exislow+github@gmail.com> | 2024-11-06 10:03:41 +0100 |
|---|---|---|
| committer | Robert Honz <exislow+github@gmail.com> | 2024-11-06 10:03:41 +0100 |
| commit | 5bd65a21bc6b44f04fbb237f373cf17d3061171c (patch) | |
| tree | 50b9edda259cc99b78142b06a4226f91a1dcd6b2 | |
| parent | 8e7d6019ff0d356b3f53a851065b9c41206a58de (diff) | |
| download | tidal-dl-ng-5bd65a21bc6b44f04fbb237f373cf17d3061171c.tar.gz | |
Added default path as an alternative path for empty user setting of an option. FFmpeg path is `whiched` as an alternative path.
| -rw-r--r-- | tidal_dl_ng/dialog.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/tidal_dl_ng/dialog.py b/tidal_dl_ng/dialog.py index 1dc9038..cfd4e24 100644 --- a/tidal_dl_ng/dialog.py +++ b/tidal_dl_ng/dialog.py @@ -1,4 +1,5 @@ import os.path +import shutil import webbrowser from enum import Enum, StrEnum from pathlib import Path @@ -182,10 +183,15 @@ class DialogPreferences(QtWidgets.QDialog): self, obj_line_edit: QtWidgets.QLineEdit, file_mode: QtWidgets.QFileDialog | QtWidgets.QFileDialog.FileMode = QtWidgets.QFileDialog.Directory, + path_default: str = None, ): # If a path is set, use it otherwise the users home directory. - settings_path: str = os.path.expanduser(obj_line_edit.text()) if obj_line_edit.text() else "" - dir_current: str = settings_path if settings_path and os.path.exists(settings_path) else str(Path.home()) + path_settings: str = os.path.expanduser(obj_line_edit.text()) if obj_line_edit.text() else "" + # Check if obj_line_edit is empty but path_default can be usd instead + path_settings = ( + path_settings if path_settings else os.path.expanduser(path_default) if path_default else path_settings + ) + dir_current: str = path_settings if path_settings and os.path.exists(path_settings) else str(Path.home()) dialog: QtWidgets.QFileDialog = QtWidgets.QFileDialog() # Set to directory mode only but show files. @@ -222,7 +228,9 @@ class DialogPreferences(QtWidgets.QDialog): self.ui.pb_download_base_path.clicked.connect(lambda x: self.dialog_chose_file(self.ui.le_download_base_path)) self.ui.pb_path_binary_ffmpeg.clicked.connect( lambda x: self.dialog_chose_file( - self.ui.le_path_binary_ffmpeg, file_mode=QtWidgets.QFileDialog.FileMode.ExistingFiles + self.ui.le_path_binary_ffmpeg, + file_mode=QtWidgets.QFileDialog.FileMode.ExistingFiles, + path_default=shutil.which("ffmpeg"), ) ) |
