Merge pull request #280 from exislow/142-help-any-way-to-set-2-digits-for-track-number
✨ Album track number padding can be set. Fixes #142
This commit is contained in:
+23
-1
@@ -116,11 +116,13 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
parameters_checkboxes: [str]
|
parameters_checkboxes: [str]
|
||||||
parameters_combo: [(str, StrEnum)]
|
parameters_combo: [(str, StrEnum)]
|
||||||
parameters_line_edit: [str]
|
parameters_line_edit: [str]
|
||||||
|
parameters_spin_box: [str]
|
||||||
prefix_checkbox: str = "cb_"
|
prefix_checkbox: str = "cb_"
|
||||||
prefix_label: str = "l_"
|
prefix_label: str = "l_"
|
||||||
prefix_icon: str = "icon_"
|
prefix_icon: str = "icon_"
|
||||||
prefix_line_edit: str = "le_"
|
prefix_line_edit: str = "le_"
|
||||||
prefix_combo: str = "c_"
|
prefix_combo: str = "c_"
|
||||||
|
prefix_spin_box: str = "sb_"
|
||||||
|
|
||||||
def __init__(self, settings: Settings, settings_save: QtCore.Signal, parent=None):
|
def __init__(self, settings: Settings, settings_save: QtCore.Signal, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
@@ -135,6 +137,7 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
self._init_checkboxes()
|
self._init_checkboxes()
|
||||||
self._init_comboboxes()
|
self._init_comboboxes()
|
||||||
self._init_line_edit()
|
self._init_line_edit()
|
||||||
|
self._init_spin_box()
|
||||||
|
|
||||||
# Create an instance of the GUI
|
# Create an instance of the GUI
|
||||||
self.ui = Ui_DialogSettings()
|
self.ui = Ui_DialogSettings()
|
||||||
@@ -143,6 +146,7 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
# Set data.
|
# Set data.
|
||||||
self.gui_populate()
|
self.gui_populate()
|
||||||
|
# Post setup
|
||||||
|
|
||||||
self.exec()
|
self.exec()
|
||||||
|
|
||||||
@@ -157,6 +161,9 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
"path_binary_ffmpeg",
|
"path_binary_ffmpeg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def _init_spin_box(self):
|
||||||
|
self.parameters_spin_box = ["album_track_num_pad_min"]
|
||||||
|
|
||||||
def _init_comboboxes(self):
|
def _init_comboboxes(self):
|
||||||
self.parameters_combo = [
|
self.parameters_combo = [
|
||||||
("quality_audio", QualityAudio),
|
("quality_audio", QualityAudio),
|
||||||
@@ -181,6 +188,7 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
self.populate_checkboxes()
|
self.populate_checkboxes()
|
||||||
self.populate_combo()
|
self.populate_combo()
|
||||||
self.populate_line_edit()
|
self.populate_line_edit()
|
||||||
|
self.populate_spin_box()
|
||||||
|
|
||||||
def dialog_chose_file(
|
def dialog_chose_file(
|
||||||
self,
|
self,
|
||||||
@@ -225,7 +233,7 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
||||||
label_icon.setToolTip(getattr(self.help_settings, pn))
|
label_icon.setToolTip(getattr(self.help_settings, pn))
|
||||||
label.setText(pn)
|
label.setText(pn)
|
||||||
line_edit.setText(getattr(self.data, pn))
|
line_edit.setText(str(getattr(self.data, pn)))
|
||||||
|
|
||||||
# Base Path File Dialog
|
# Base Path File Dialog
|
||||||
self.ui.pb_download_base_path.clicked.connect(lambda x: self.dialog_chose_file(self.ui.le_download_base_path))
|
self.ui.pb_download_base_path.clicked.connect(lambda x: self.dialog_chose_file(self.ui.le_download_base_path))
|
||||||
@@ -265,6 +273,17 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
checkbox.setIcon(self.icon)
|
checkbox.setIcon(self.icon)
|
||||||
checkbox.setChecked(getattr(self.data, pn))
|
checkbox.setChecked(getattr(self.data, pn))
|
||||||
|
|
||||||
|
def populate_spin_box(self):
|
||||||
|
for pn in self.parameters_spin_box:
|
||||||
|
label_icon: QtWidgets.QLabel = getattr(self.ui, self.prefix_label + self.prefix_icon + pn)
|
||||||
|
label: QtWidgets.QLabel = getattr(self.ui, self.prefix_label + pn)
|
||||||
|
spin_box: QtWidgets.QSpinBox = getattr(self.ui, self.prefix_spin_box + pn)
|
||||||
|
|
||||||
|
label_icon.setPixmap(QtGui.QPixmap(self.icon.pixmap(QtCore.QSize(16, 16))))
|
||||||
|
label_icon.setToolTip(getattr(self.help_settings, pn))
|
||||||
|
label.setText(pn)
|
||||||
|
spin_box.setValue(getattr(self.data, pn))
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
# Get settings.
|
# Get settings.
|
||||||
self.to_settings()
|
self.to_settings()
|
||||||
@@ -280,4 +299,7 @@ class DialogPreferences(QtWidgets.QDialog):
|
|||||||
for item in self.parameters_combo:
|
for item in self.parameters_combo:
|
||||||
setattr(self.settings.data, item[0], getattr(self.ui, self.prefix_combo + item[0]).currentData())
|
setattr(self.settings.data, item[0], getattr(self.ui, self.prefix_combo + item[0]).currentData())
|
||||||
|
|
||||||
|
for item in self.parameters_spin_box:
|
||||||
|
setattr(self.settings.data, item, getattr(self.ui, self.prefix_spin_box + item).value())
|
||||||
|
|
||||||
self.s_settings_save.emit()
|
self.s_settings_save.emit()
|
||||||
|
|||||||
@@ -299,7 +299,7 @@ class Download:
|
|||||||
|
|
||||||
# Create file name and path
|
# Create file name and path
|
||||||
file_extension_dummy: str = AudioExtensions.FLAC
|
file_extension_dummy: str = AudioExtensions.FLAC
|
||||||
file_name_relative = format_path_media(file_template, media)
|
file_name_relative = format_path_media(file_template, media, self.settings.data.album_track_num_pad_min)
|
||||||
path_media_dst: pathlib.Path = (
|
path_media_dst: pathlib.Path = (
|
||||||
(pathlib.Path(self.path_base).expanduser() / (file_name_relative + file_extension_dummy))
|
(pathlib.Path(self.path_base).expanduser() / (file_name_relative + file_extension_dummy))
|
||||||
.resolve()
|
.resolve()
|
||||||
@@ -596,7 +596,7 @@ class Download:
|
|||||||
raise MediaMissing
|
raise MediaMissing
|
||||||
|
|
||||||
# Create file name and path
|
# Create file name and path
|
||||||
file_name_relative = format_path_media(file_template, media)
|
file_name_relative = format_path_media(file_template, media, self.settings.data.album_track_num_pad_min)
|
||||||
|
|
||||||
# Get the name of the list and check, if videos should be included.
|
# Get the name of the list and check, if videos should be included.
|
||||||
list_media_name: str = name_builder_title(media)
|
list_media_name: str = name_builder_title(media)
|
||||||
|
|||||||
@@ -49,7 +49,9 @@ def path_file_settings() -> str:
|
|||||||
return os.path.join(path_config_base(), "settings.json")
|
return os.path.join(path_config_base(), "settings.json")
|
||||||
|
|
||||||
|
|
||||||
def format_path_media(fmt_template: str, media: Track | Album | Playlist | UserPlaylist | Video | Mix) -> str:
|
def format_path_media(
|
||||||
|
fmt_template: str, media: Track | Album | Playlist | UserPlaylist | Video | Mix, album_track_num_pad_min: int = 0
|
||||||
|
) -> str:
|
||||||
result = fmt_template
|
result = fmt_template
|
||||||
|
|
||||||
# Search track format template for placeholder.
|
# Search track format template for placeholder.
|
||||||
@@ -58,7 +60,7 @@ def format_path_media(fmt_template: str, media: Track | Album | Playlist | UserP
|
|||||||
|
|
||||||
for _matchNum, match in enumerate(matches, start=1):
|
for _matchNum, match in enumerate(matches, start=1):
|
||||||
template_str = match.group()
|
template_str = match.group()
|
||||||
result_fmt = format_str_media(match.group(1), media)
|
result_fmt = format_str_media(match.group(1), media, album_track_num_pad_min)
|
||||||
|
|
||||||
if result_fmt != match.group(1):
|
if result_fmt != match.group(1):
|
||||||
value = sanitize_filename(result_fmt)
|
value = sanitize_filename(result_fmt)
|
||||||
@@ -67,7 +69,9 @@ def format_path_media(fmt_template: str, media: Track | Album | Playlist | UserP
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def format_str_media(name: str, media: Track | Album | Playlist | UserPlaylist | Video | Mix) -> str: # noqa: C901
|
def format_str_media(
|
||||||
|
name: str, media: Track | Album | Playlist | UserPlaylist | Video | Mix, album_track_num_pad_min: int = 0
|
||||||
|
) -> str:
|
||||||
result: str = name
|
result: str = name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -98,7 +102,10 @@ def format_str_media(name: str, media: Track | Album | Playlist | UserPlaylist |
|
|||||||
if isinstance(media, Track | Video):
|
if isinstance(media, Track | Video):
|
||||||
num_tracks: int = media.album.num_tracks if hasattr(media, "album") else 1
|
num_tracks: int = media.album.num_tracks if hasattr(media, "album") else 1
|
||||||
count_digits: int = int(math.log10(num_tracks)) + 1
|
count_digits: int = int(math.log10(num_tracks)) + 1
|
||||||
result = str(media.track_num).zfill(count_digits)
|
count_digits_computed: int = (
|
||||||
|
count_digits if count_digits > album_track_num_pad_min else album_track_num_pad_min
|
||||||
|
)
|
||||||
|
result = str(media.track_num).zfill(count_digits_computed)
|
||||||
case "album_num_tracks":
|
case "album_num_tracks":
|
||||||
if isinstance(media, Track | Video):
|
if isinstance(media, Track | Video):
|
||||||
result = str(media.album.num_tracks if hasattr(media, "album") else 1)
|
result = str(media.album.num_tracks if hasattr(media, "album") else 1)
|
||||||
@@ -160,11 +167,11 @@ def format_str_media(name: str, media: Track | Album | Playlist | UserPlaylist |
|
|||||||
case "track_volume_num_optional":
|
case "track_volume_num_optional":
|
||||||
if isinstance(media, Track | Video):
|
if isinstance(media, Track | Video):
|
||||||
num_volumes: int = media.album.num_volumes if hasattr(media, "album") else 1
|
num_volumes: int = media.album.num_volumes if hasattr(media, "album") else 1
|
||||||
result = "" if num_volumes is 1 else str(media.volume_num)
|
result = "" if num_volumes == 1 else str(media.volume_num)
|
||||||
case "track_volume_num_optional_CD":
|
case "track_volume_num_optional_CD":
|
||||||
if isinstance(media, Track | Video):
|
if isinstance(media, Track | Video):
|
||||||
num_volumes: int = media.album.num_volumes if hasattr(media, "album") else 1
|
num_volumes: int = media.album.num_volumes if hasattr(media, "album") else 1
|
||||||
result = "" if num_volumes is 1 else f"CD{media.volume_num!s}"
|
result = "" if num_volumes == 1 else f"CD{media.volume_num!s}"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO: Implement better exception logging.
|
# TODO: Implement better exception logging.
|
||||||
print(e)
|
print(e)
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class Settings:
|
|||||||
downloads_simultaneous_per_track_max: int = 20
|
downloads_simultaneous_per_track_max: int = 20
|
||||||
download_delay_sec_min: float = 3.0
|
download_delay_sec_min: float = 3.0
|
||||||
download_delay_sec_max: float = 5.0
|
download_delay_sec_max: float = 5.0
|
||||||
|
album_track_num_pad_min: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
@@ -82,8 +83,11 @@ class HelpSettings:
|
|||||||
cover_album_file: str = "Save cover to 'cover.jpg', if an album is downloaded."
|
cover_album_file: str = "Save cover to 'cover.jpg', if an album is downloaded."
|
||||||
extract_flac: str = "Extract FLAC audio tracks from MP4 containers and save them as `*.flac` (uses FFmpeg)."
|
extract_flac: str = "Extract FLAC audio tracks from MP4 containers and save them as `*.flac` (uses FFmpeg)."
|
||||||
downloads_simultaneous_per_track_max: str = "Maximum number of simultaneous chunk downloads per track."
|
downloads_simultaneous_per_track_max: str = "Maximum number of simultaneous chunk downloads per track."
|
||||||
download_delay_sec_min: float = "Lower boundary for the calculation of the download delay in seconds."
|
download_delay_sec_min: str = "Lower boundary for the calculation of the download delay in seconds."
|
||||||
download_delay_sec_max: float = "Upper boundary for the calculation of the download delay in seconds."
|
download_delay_sec_max: str = "Upper boundary for the calculation of the download delay in seconds."
|
||||||
|
album_track_num_pad_min: str = (
|
||||||
|
"Minimum length of the album track count, will be padded with zeroes (0). To disable " "padding set this to 0."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass_json
|
@dataclass_json
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
################################################################################
|
################################################################################
|
||||||
## Form generated from reading UI file 'dialog_settings.ui'
|
## Form generated from reading UI file 'dialog_settings.ui'
|
||||||
##
|
##
|
||||||
## Created by: Qt User Interface Compiler version 6.8.0
|
## Created by: Qt User Interface Compiler version 6.8.1
|
||||||
##
|
##
|
||||||
## WARNING! All changes made in this file will be lost when recompiling UI file!
|
## WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||||
################################################################################
|
################################################################################
|
||||||
@@ -18,6 +18,7 @@ from PySide6.QtWidgets import (
|
|||||||
QLineEdit,
|
QLineEdit,
|
||||||
QPushButton,
|
QPushButton,
|
||||||
QSizePolicy,
|
QSizePolicy,
|
||||||
|
QSpinBox,
|
||||||
QVBoxLayout,
|
QVBoxLayout,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -268,6 +269,32 @@ class Ui_DialogSettings:
|
|||||||
|
|
||||||
self.lv_main.addWidget(self.gb_choices)
|
self.lv_main.addWidget(self.gb_choices)
|
||||||
|
|
||||||
|
self.gb_numbers = QGroupBox(DialogSettings)
|
||||||
|
self.gb_numbers.setObjectName("gb_numbers")
|
||||||
|
self.verticalLayout_8 = QVBoxLayout(self.gb_numbers)
|
||||||
|
self.verticalLayout_8.setObjectName("verticalLayout_8")
|
||||||
|
self.horizontalLayout_9 = QHBoxLayout()
|
||||||
|
self.horizontalLayout_9.setObjectName("horizontalLayout_9")
|
||||||
|
self.l_album_track_num_pad_min = QLabel(self.gb_numbers)
|
||||||
|
self.l_album_track_num_pad_min.setObjectName("l_album_track_num_pad_min")
|
||||||
|
|
||||||
|
self.horizontalLayout_9.addWidget(self.l_album_track_num_pad_min)
|
||||||
|
|
||||||
|
self.l_icon_album_track_num_pad_min = QLabel(self.gb_numbers)
|
||||||
|
self.l_icon_album_track_num_pad_min.setObjectName("l_icon_album_track_num_pad_min")
|
||||||
|
|
||||||
|
self.horizontalLayout_9.addWidget(self.l_icon_album_track_num_pad_min)
|
||||||
|
|
||||||
|
self.sb_album_track_num_pad_min = QSpinBox(self.gb_numbers)
|
||||||
|
self.sb_album_track_num_pad_min.setObjectName("sb_album_track_num_pad_min")
|
||||||
|
self.sb_album_track_num_pad_min.setMaximum(4)
|
||||||
|
|
||||||
|
self.horizontalLayout_9.addWidget(self.sb_album_track_num_pad_min)
|
||||||
|
|
||||||
|
self.verticalLayout_8.addLayout(self.horizontalLayout_9)
|
||||||
|
|
||||||
|
self.lv_main.addWidget(self.gb_numbers)
|
||||||
|
|
||||||
self.gb_path = QGroupBox(DialogSettings)
|
self.gb_path = QGroupBox(DialogSettings)
|
||||||
self.gb_path.setObjectName("gb_path")
|
self.gb_path.setObjectName("gb_path")
|
||||||
self.horizontalLayout_2 = QHBoxLayout(self.gb_path)
|
self.horizontalLayout_2 = QHBoxLayout(self.gb_path)
|
||||||
@@ -533,6 +560,9 @@ class Ui_DialogSettings:
|
|||||||
self.l_quality_video.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_quality_video.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.l_icon_metadata_cover_dimension.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_icon_metadata_cover_dimension.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.l_metadata_cover_dimension.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_metadata_cover_dimension.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
|
self.gb_numbers.setTitle(QCoreApplication.translate("DialogSettings", "Numbers", None))
|
||||||
|
self.l_album_track_num_pad_min.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
|
self.l_icon_album_track_num_pad_min.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.gb_path.setTitle(QCoreApplication.translate("DialogSettings", "Path", None))
|
self.gb_path.setTitle(QCoreApplication.translate("DialogSettings", "Path", None))
|
||||||
self.l_icon_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_icon_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
self.l_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
self.l_download_base_path.setText(QCoreApplication.translate("DialogSettings", "TextLabel", None))
|
||||||
|
|||||||
@@ -355,6 +355,40 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="gb_numbers">
|
||||||
|
<property name="title">
|
||||||
|
<string>Numbers</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_8">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="l_album_track_num_pad_min">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="l_icon_album_track_num_pad_min">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="sb_album_track_num_pad_min">
|
||||||
|
<property name="maximum">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="gb_path">
|
<widget class="QGroupBox" name="gb_path">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
|||||||
Reference in New Issue
Block a user