mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-22 23:55:46 +00:00
Add option to disable all restrictions to CAA types
This is better since the list of types may change, adding a "do not restrict" ensure all types are downloaded if more types are added to MB. If restriction is enabled, then previous behavior is used (downloading only images having specified types).
This commit is contained in:
@@ -51,6 +51,7 @@ class CoverArtProviderCaa(CoverArtProvider):
|
||||
CoverArtProvider.__init__(self, coverart)
|
||||
self.caa_types = map(unicode.lower, config.setting["caa_image_types"])
|
||||
self.len_caa_types = len(self.caa_types)
|
||||
self.restrict_types = config.setting["caa_restrict_image_types"]
|
||||
|
||||
@property
|
||||
def _has_suitable_artwork(self):
|
||||
@@ -69,29 +70,30 @@ class CoverArtProviderCaa(CoverArtProvider):
|
||||
% self.release.id)
|
||||
return False
|
||||
|
||||
want_front = 'front' in self.caa_types
|
||||
want_back = 'back' in self.caa_types
|
||||
caa_has_front = caa_node.front[0].text == 'true'
|
||||
caa_has_back = caa_node.back[0].text == 'true'
|
||||
if self.restrict_types:
|
||||
want_front = 'front' in self.caa_types
|
||||
want_back = 'back' in self.caa_types
|
||||
caa_has_front = caa_node.front[0].text == 'true'
|
||||
caa_has_back = caa_node.back[0].text == 'true'
|
||||
|
||||
if self.len_caa_types == 2 and (want_front or want_back):
|
||||
# The OR cases are there to still download and process the CAA
|
||||
# JSON file if front or back is enabled but not in the CAA and
|
||||
# another type (that's neither front nor back) is enabled.
|
||||
# For example, if both front and booklet are enabled and the
|
||||
# CAA only has booklet images, the front element in the XML
|
||||
# from the webservice will be false (thus front_in_caa is False
|
||||
# as well) but it's still necessary to download the booklet
|
||||
# images by using the fact that back is enabled but there are
|
||||
# no back images in the CAA.
|
||||
front_in_caa = caa_has_front or not want_front
|
||||
back_in_caa = caa_has_back or not want_back
|
||||
caa_has_suitable_artwork = front_in_caa or back_in_caa
|
||||
if self.len_caa_types == 2 and (want_front or want_back):
|
||||
# The OR cases are there to still download and process the CAA
|
||||
# JSON file if front or back is enabled but not in the CAA and
|
||||
# another type (that's neither front nor back) is enabled.
|
||||
# For example, if both front and booklet are enabled and the
|
||||
# CAA only has booklet images, the front element in the XML
|
||||
# from the webservice will be false (thus front_in_caa is False
|
||||
# as well) but it's still necessary to download the booklet
|
||||
# images by using the fact that back is enabled but there are
|
||||
# no back images in the CAA.
|
||||
front_in_caa = caa_has_front or not want_front
|
||||
back_in_caa = caa_has_back or not want_back
|
||||
caa_has_suitable_artwork = front_in_caa or back_in_caa
|
||||
|
||||
elif self.len_caa_types == 1 and (want_front or want_back):
|
||||
front_in_caa = caa_has_front and want_front
|
||||
back_in_caa = caa_has_back and want_back
|
||||
caa_has_suitable_artwork = front_in_caa or back_in_caa
|
||||
elif self.len_caa_types == 1 and (want_front or want_back):
|
||||
front_in_caa = caa_has_front and want_front
|
||||
back_in_caa = caa_has_back and want_back
|
||||
caa_has_suitable_artwork = front_in_caa or back_in_caa
|
||||
|
||||
if not caa_has_suitable_artwork:
|
||||
log.debug("There are no suitable images in the Cover Art Archive for %s"
|
||||
@@ -107,7 +109,7 @@ class CoverArtProviderCaa(CoverArtProvider):
|
||||
if not config.setting['ca_provider_use_caa']:
|
||||
log.debug("Cover Art Archive disabled by user")
|
||||
return False
|
||||
if not self.len_caa_types:
|
||||
if self.restrict_types and not self.len_caa_types:
|
||||
log.debug("User disabled all Cover Art Archive types")
|
||||
return False
|
||||
return self._has_suitable_artwork
|
||||
@@ -157,9 +159,12 @@ class CoverArtProviderCaa(CoverArtProvider):
|
||||
image["types"] = [u"unknown"]
|
||||
else:
|
||||
image["types"] = map(unicode.lower, image["types"])
|
||||
# only keep enabled caa types
|
||||
types = set(image["types"]).intersection(
|
||||
set(self.caa_types))
|
||||
if self.restrict_types:
|
||||
# only keep enabled caa types
|
||||
types = set(image["types"]).intersection(
|
||||
set(self.caa_types))
|
||||
else:
|
||||
types = True
|
||||
if types:
|
||||
if thumbsize is None or is_pdf:
|
||||
url = image["image"]
|
||||
|
||||
@@ -99,6 +99,8 @@ class CAATypesSelectorDialog(QtGui.QDialog):
|
||||
for item, typ in self._items.iteritems():
|
||||
if item.isChecked():
|
||||
types.append(typ['name'])
|
||||
if not types:
|
||||
return [u'front']
|
||||
return types
|
||||
|
||||
@staticmethod
|
||||
@@ -131,6 +133,7 @@ class CoverOptionsPage(OptionsPage):
|
||||
config.BoolOption("setting", "caa_image_type_as_filename", False),
|
||||
config.IntOption("setting", "caa_image_size", 1),
|
||||
config.ListOption("setting", "caa_image_types", [u"front"]),
|
||||
config.BoolOption("setting", "caa_restrict_image_types", True),
|
||||
]
|
||||
|
||||
def __init__(self, parent=None):
|
||||
@@ -138,6 +141,7 @@ class CoverOptionsPage(OptionsPage):
|
||||
self.ui = Ui_CoverOptionsPage()
|
||||
self.ui.setupUi(self)
|
||||
self.ui.save_images_to_files.clicked.connect(self.update_filename)
|
||||
self.ui.restrict_images_types.clicked.connect(self.update_caa_types)
|
||||
|
||||
def load(self):
|
||||
self.ui.save_images_to_tags.setChecked(config.setting["save_images_to_tags"])
|
||||
@@ -159,6 +163,10 @@ class CoverOptionsPage(OptionsPage):
|
||||
self.connect(self.ui.caprovider_caa, QtCore.SIGNAL("toggled(bool)"),
|
||||
self.ui.gb_caa.setEnabled)
|
||||
self.ui.select_caa_types.clicked.connect(self.select_caa_types)
|
||||
self.ui.restrict_images_types.setChecked(
|
||||
config.setting["caa_restrict_image_types"])
|
||||
self.update_caa_types()
|
||||
self.update_filename()
|
||||
|
||||
def save(self):
|
||||
config.setting["save_images_to_tags"] = self.ui.save_images_to_tags.isChecked()
|
||||
@@ -181,12 +189,18 @@ class CoverOptionsPage(OptionsPage):
|
||||
self.ui.cb_type_as_filename.isChecked()
|
||||
|
||||
config.setting["save_images_overwrite"] = self.ui.save_images_overwrite.isChecked()
|
||||
config.setting["caa_restrict_image_types"] = \
|
||||
self.ui.restrict_images_types.isChecked()
|
||||
|
||||
def update_filename(self):
|
||||
enabled = self.ui.save_images_to_files.isChecked()
|
||||
self.ui.cover_image_filename.setEnabled(enabled)
|
||||
self.ui.save_images_overwrite.setEnabled(enabled)
|
||||
|
||||
def update_caa_types(self):
|
||||
enabled = self.ui.restrict_images_types.isChecked()
|
||||
self.ui.select_caa_types.setEnabled(enabled)
|
||||
|
||||
def select_caa_types(self):
|
||||
(types, ok) = CAATypesSelectorDialog.run(
|
||||
self, config.setting["caa_image_types"])
|
||||
|
||||
@@ -88,13 +88,13 @@ class Ui_CoverOptionsPage(object):
|
||||
self.cb_image_size.addItem(_fromUtf8(""))
|
||||
self.horizontalLayout.addWidget(self.cb_image_size)
|
||||
self.verticalLayout_3.addLayout(self.horizontalLayout)
|
||||
self.horizontalLayout2 = QtGui.QHBoxLayout()
|
||||
self.horizontalLayout2.setObjectName(_fromUtf8("horizontalLayout2"))
|
||||
self.label1 = QtGui.QLabel(self.gb_caa)
|
||||
self.label1.setObjectName(_fromUtf8("label1"))
|
||||
self.horizontalLayout2.addWidget(self.label1)
|
||||
self.select_caa_types_group = QtGui.QHBoxLayout()
|
||||
self.select_caa_types_group.setObjectName(_fromUtf8("select_caa_types_group"))
|
||||
self.restrict_images_types = QtGui.QCheckBox(self.gb_caa)
|
||||
self.restrict_images_types.setObjectName(_fromUtf8("restrict_images_types"))
|
||||
self.select_caa_types_group.addWidget(self.restrict_images_types)
|
||||
spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
|
||||
self.horizontalLayout2.addItem(spacerItem1)
|
||||
self.select_caa_types_group.addItem(spacerItem1)
|
||||
self.select_caa_types = QtGui.QPushButton(self.gb_caa)
|
||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
|
||||
sizePolicy.setHorizontalStretch(100)
|
||||
@@ -102,8 +102,8 @@ class Ui_CoverOptionsPage(object):
|
||||
sizePolicy.setHeightForWidth(self.select_caa_types.sizePolicy().hasHeightForWidth())
|
||||
self.select_caa_types.setSizePolicy(sizePolicy)
|
||||
self.select_caa_types.setObjectName(_fromUtf8("select_caa_types"))
|
||||
self.horizontalLayout2.addWidget(self.select_caa_types)
|
||||
self.verticalLayout_3.addLayout(self.horizontalLayout2)
|
||||
self.select_caa_types_group.addWidget(self.select_caa_types)
|
||||
self.verticalLayout_3.addLayout(self.select_caa_types_group)
|
||||
self.cb_approved_only = QtGui.QCheckBox(self.gb_caa)
|
||||
self.cb_approved_only.setObjectName(_fromUtf8("cb_approved_only"))
|
||||
self.verticalLayout_3.addWidget(self.cb_approved_only)
|
||||
@@ -154,8 +154,8 @@ class Ui_CoverOptionsPage(object):
|
||||
self.cb_image_size.setItemText(0, _("250 px"))
|
||||
self.cb_image_size.setItemText(1, _("500 px"))
|
||||
self.cb_image_size.setItemText(2, _("Full size"))
|
||||
self.label1.setText(_("Types of cover art to download:"))
|
||||
self.select_caa_types.setText(_("Select..."))
|
||||
self.restrict_images_types.setText(_("Download only cover art images matching selected types"))
|
||||
self.select_caa_types.setText(_("Select types..."))
|
||||
self.cb_approved_only.setText(_("Download only approved images"))
|
||||
self.cb_type_as_filename.setText(_("Use the first image type as the filename. This will not change the filename of front images."))
|
||||
self.caprovider_caa_release_group.setText(_("Use the image of the release group if no front image is associated with the release"))
|
||||
|
||||
@@ -153,11 +153,11 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout2">
|
||||
<layout class="QHBoxLayout" name="select_caa_types_group">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QCheckBox" name="restrict_images_types">
|
||||
<property name="text">
|
||||
<string>Types of cover art to download:</string>
|
||||
<string>Download only cover art images matching selected types</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -177,7 +177,7 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="select_caa_types">
|
||||
<property name="text">
|
||||
<string>Select...</string>
|
||||
<string>Select types...</string>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
|
||||
Reference in New Issue
Block a user