forked from metabrainz/picard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request metabrainz#2506 from twodoorcoupe/image_filtering
PICARD-2926: Add option to filter out images below a given size
- Loading branch information
Showing
15 changed files
with
563 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Picard, the next-generation MusicBrainz tagger | ||
# | ||
# Copyright (C) 2024 Giorgio Fontanive | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from picard.coverart.processing import ( # noqa: F401 # pylint: disable=unused-import | ||
filters, | ||
) | ||
from picard.extension_points.cover_art_filters import ( | ||
ext_point_cover_art_filters, | ||
ext_point_cover_art_metadata_filters, | ||
) | ||
|
||
|
||
def run_image_filters(data): | ||
for f in ext_point_cover_art_filters: | ||
if not f(data): | ||
return False | ||
return True | ||
|
||
|
||
def run_image_metadata_filters(metadata): | ||
for f in ext_point_cover_art_metadata_filters: | ||
if not f(metadata): | ||
return False | ||
return True | ||
|
||
|
||
# def run_image_processors(data): | ||
# pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Picard, the next-generation MusicBrainz tagger | ||
# | ||
# Copyright (C) 2024 Giorgio Fontanive | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from PyQt6.QtGui import QImage | ||
|
||
from picard import log | ||
from picard.config import get_config | ||
from picard.extension_points.cover_art_filters import ( | ||
register_cover_art_filter, | ||
register_cover_art_metadata_filter, | ||
) | ||
|
||
|
||
def _check_threshold_size(width, height): | ||
config = get_config() | ||
if not config.setting['filter_cover_by_size']: | ||
return True | ||
# If the given width or height is -1, that dimension is not considered | ||
min_width = config.setting['cover_minimum_width'] if width != -1 else -1 | ||
min_height = config.setting['cover_minimum_height'] if height != -1 else -1 | ||
if width < min_width or height < min_height: | ||
log.debug( | ||
"Discarding cover art due to size. Image size: %d x %d. Minimum: %d x %d", | ||
width, | ||
height, | ||
min_width, | ||
min_height | ||
) | ||
return False | ||
return True | ||
|
||
|
||
def size_filter(data): | ||
image = QImage.fromData(data) | ||
return _check_threshold_size(image.width(), image.height()) | ||
|
||
|
||
def size_metadata_filter(metadata): | ||
if 'width' not in metadata or 'height' not in metadata: | ||
return True | ||
return _check_threshold_size(metadata['width'], metadata['height']) | ||
|
||
|
||
register_cover_art_filter(size_filter) | ||
register_cover_art_metadata_filter(size_metadata_filter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Picard, the next-generation MusicBrainz tagger | ||
# | ||
# Copyright (C) 2024 Giorgio Fontanive | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
|
||
from picard.plugin import ExtensionPoint | ||
|
||
|
||
ext_point_cover_art_filters = ExtensionPoint(label='cover_art_filters') | ||
ext_point_cover_art_metadata_filters = ExtensionPoint(label='cover_art_metadata_filters') | ||
|
||
|
||
def register_cover_art_filter(cover_art_filter): | ||
ext_point_cover_art_filters.register(cover_art_filter.__module__, cover_art_filter) | ||
|
||
|
||
def register_cover_art_metadata_filter(cover_art_metadata_filter): | ||
ext_point_cover_art_metadata_filters.register(cover_art_metadata_filter.__module__, cover_art_metadata_filter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Form implementation generated from reading ui file 'ui/options_cover_processing.ui' | ||
# | ||
# Created by: PyQt6 UI code generator 6.6.1 | ||
# | ||
# Automatically generated - do not edit. | ||
# Use `python setup.py build_ui` to update it. | ||
|
||
from PyQt6 import ( | ||
QtCore, | ||
QtGui, | ||
QtWidgets, | ||
) | ||
|
||
from picard.i18n import gettext as _ | ||
|
||
|
||
class Ui_CoverProcessingOptionsPage(object): | ||
def setupUi(self, CoverProcessingOptionsPage): | ||
CoverProcessingOptionsPage.setObjectName("CoverProcessingOptionsPage") | ||
CoverProcessingOptionsPage.resize(400, 300) | ||
self.verticalLayout = QtWidgets.QVBoxLayout(CoverProcessingOptionsPage) | ||
self.verticalLayout.setObjectName("verticalLayout") | ||
self.filtering = QtWidgets.QGroupBox(parent=CoverProcessingOptionsPage) | ||
self.filtering.setCheckable(True) | ||
self.filtering.setChecked(False) | ||
self.filtering.setObjectName("filtering") | ||
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.filtering) | ||
self.verticalLayout_2.setObjectName("verticalLayout_2") | ||
self.width_widget = QtWidgets.QWidget(parent=self.filtering) | ||
self.width_widget.setObjectName("width_widget") | ||
self.horizontalLayout = QtWidgets.QHBoxLayout(self.width_widget) | ||
self.horizontalLayout.setContentsMargins(0, 0, 0, 0) | ||
self.horizontalLayout.setObjectName("horizontalLayout") | ||
self.width_label = QtWidgets.QLabel(parent=self.width_widget) | ||
self.width_label.setObjectName("width_label") | ||
self.horizontalLayout.addWidget(self.width_label) | ||
self.width_value = QtWidgets.QSpinBox(parent=self.width_widget) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum, QtWidgets.QSizePolicy.Policy.Fixed) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(self.width_value.sizePolicy().hasHeightForWidth()) | ||
self.width_value.setSizePolicy(sizePolicy) | ||
self.width_value.setMaximum(1000) | ||
self.width_value.setProperty("value", 250) | ||
self.width_value.setObjectName("width_value") | ||
self.horizontalLayout.addWidget(self.width_value) | ||
self.px_label2 = QtWidgets.QLabel(parent=self.width_widget) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum, QtWidgets.QSizePolicy.Policy.Preferred) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(self.px_label2.sizePolicy().hasHeightForWidth()) | ||
self.px_label2.setSizePolicy(sizePolicy) | ||
self.px_label2.setObjectName("px_label2") | ||
self.horizontalLayout.addWidget(self.px_label2) | ||
self.verticalLayout_2.addWidget(self.width_widget) | ||
self.height_widget = QtWidgets.QWidget(parent=self.filtering) | ||
self.height_widget.setObjectName("height_widget") | ||
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.height_widget) | ||
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0) | ||
self.horizontalLayout_2.setObjectName("horizontalLayout_2") | ||
self.height_label = QtWidgets.QLabel(parent=self.height_widget) | ||
self.height_label.setObjectName("height_label") | ||
self.horizontalLayout_2.addWidget(self.height_label) | ||
self.height_value = QtWidgets.QSpinBox(parent=self.height_widget) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum, QtWidgets.QSizePolicy.Policy.Fixed) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(self.height_value.sizePolicy().hasHeightForWidth()) | ||
self.height_value.setSizePolicy(sizePolicy) | ||
self.height_value.setMaximum(1000) | ||
self.height_value.setProperty("value", 250) | ||
self.height_value.setObjectName("height_value") | ||
self.horizontalLayout_2.addWidget(self.height_value) | ||
self.px_label1 = QtWidgets.QLabel(parent=self.height_widget) | ||
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Maximum, QtWidgets.QSizePolicy.Policy.Preferred) | ||
sizePolicy.setHorizontalStretch(0) | ||
sizePolicy.setVerticalStretch(0) | ||
sizePolicy.setHeightForWidth(self.px_label1.sizePolicy().hasHeightForWidth()) | ||
self.px_label1.setSizePolicy(sizePolicy) | ||
self.px_label1.setObjectName("px_label1") | ||
self.horizontalLayout_2.addWidget(self.px_label1) | ||
self.verticalLayout_2.addWidget(self.height_widget) | ||
self.verticalLayout.addWidget(self.filtering) | ||
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Policy.Minimum, QtWidgets.QSizePolicy.Policy.Expanding) | ||
self.verticalLayout.addItem(spacerItem) | ||
|
||
self.retranslateUi(CoverProcessingOptionsPage) | ||
QtCore.QMetaObject.connectSlotsByName(CoverProcessingOptionsPage) | ||
|
||
def retranslateUi(self, CoverProcessingOptionsPage): | ||
CoverProcessingOptionsPage.setWindowTitle(_("Form")) | ||
self.filtering.setTitle(_("Discard images if below the given size")) | ||
self.width_label.setText(_("Width:")) | ||
self.px_label2.setText(_("px")) | ||
self.height_label.setText(_("Height:")) | ||
self.px_label1.setText(_("px")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.