mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-25 17:13:57 +00:00
Add an ImageList class to compare easily list of images
This removes the need to explicitly sort the list of images by image type before each comparison
This commit is contained in:
@@ -22,6 +22,7 @@ import traceback
|
||||
from PyQt4 import QtCore, QtNetwork
|
||||
from picard import config, log
|
||||
from picard.coverart import coverart
|
||||
from picard.coverart.imagelist import ImageList
|
||||
from picard.metadata import (Metadata,
|
||||
register_album_metadata_processor,
|
||||
run_album_metadata_processors,
|
||||
@@ -582,8 +583,8 @@ class Album(DataObject, Item):
|
||||
return
|
||||
|
||||
class State:
|
||||
new_images = []
|
||||
orig_images = []
|
||||
new_images = ImageList()
|
||||
orig_images = ImageList()
|
||||
has_common_new_images = True
|
||||
has_common_orig_images = True
|
||||
first_new_obj = True
|
||||
|
||||
@@ -32,6 +32,7 @@ from picard.similarity import similarity
|
||||
from picard.ui.item import Item
|
||||
from picard.util import format_time, album_artist_from_path
|
||||
from picard.const import QUERY_LIMIT
|
||||
from picard.coverart.imagelist import ImageList
|
||||
|
||||
|
||||
class Cluster(QtCore.QObject, Item):
|
||||
@@ -280,7 +281,7 @@ class Cluster(QtCore.QObject, Item):
|
||||
|
||||
def update_metadata_images(self):
|
||||
class State:
|
||||
new_images = []
|
||||
new_images = ImageList()
|
||||
has_common_new_images = True
|
||||
first_new_obj = True
|
||||
|
||||
|
||||
38
picard/coverart/imagelist.py
Normal file
38
picard/coverart/imagelist.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Picard, the next-generation MusicBrainz tagger
|
||||
# Copyright (C) 2017 Antonio Larrosa <alarrosa@suse.com>
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
def get_image_type(image):
|
||||
return image.types_as_string()
|
||||
|
||||
|
||||
class ImageList(list):
|
||||
|
||||
def __init__(self):
|
||||
super(ImageList, self).__init__()
|
||||
|
||||
def __eq__(self, other):
|
||||
return sorted(self, key=get_image_type) == sorted(other, key=get_image_type)
|
||||
|
||||
def __getslice__(self, i, j):
|
||||
i = max(0, min(i, len(self)))
|
||||
j = max(0, min(j, len(self)))
|
||||
r = ImageList()
|
||||
r[:] = [self[it] for it in range(i, j)]
|
||||
return r
|
||||
@@ -21,6 +21,7 @@ from PyQt4.QtCore import QObject
|
||||
from picard import config, log
|
||||
from picard.plugin import PluginFunctions, PluginPriority
|
||||
from picard.similarity import similarity2
|
||||
from picard.coverart.imagelist import ImageList
|
||||
from picard.util import (
|
||||
linear_combination_of_weights,
|
||||
)
|
||||
@@ -45,7 +46,7 @@ class Metadata(dict):
|
||||
|
||||
def __init__(self):
|
||||
super(Metadata, self).__init__()
|
||||
self.images = []
|
||||
self.images = ImageList()
|
||||
self.deleted_tags = set()
|
||||
self.length = 0
|
||||
|
||||
@@ -241,7 +242,7 @@ class Metadata(dict):
|
||||
|
||||
def clear(self):
|
||||
dict.clear(self)
|
||||
self.images = []
|
||||
self.images = ImageList()
|
||||
self.length = 0
|
||||
self.deleted_tags = set()
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ from picard.mbxml import recording_to_metadata
|
||||
from picard.script import ScriptParser
|
||||
from picard.const import VARIOUS_ARTISTS_ID, SILENCE_TRACK_TITLE, DATA_TRACK_TITLE
|
||||
from picard.ui.item import Item
|
||||
from picard.coverart.imagelist import ImageList
|
||||
import traceback
|
||||
|
||||
|
||||
@@ -226,7 +227,7 @@ class Track(DataObject, Item):
|
||||
|
||||
def update_orig_metadata_images(self):
|
||||
class State:
|
||||
orig_images = []
|
||||
orig_images = ImageList()
|
||||
has_common_orig_images = True
|
||||
first_orig_obj = True
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ from PyQt4 import QtCore, QtGui, QtNetwork
|
||||
from picard import config, log
|
||||
from picard.album import Album
|
||||
from picard.coverart.image import CoverArtImage, CoverArtImageError
|
||||
from picard.coverart.imagelist import ImageList
|
||||
from picard.track import Track
|
||||
from picard.file import File
|
||||
from picard.util import encode_filename, imageinfo
|
||||
@@ -94,7 +95,7 @@ class CoverArtThumbnail(ActiveLabel):
|
||||
self.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignHCenter)
|
||||
self.clicked.connect(self.open_release_page)
|
||||
self.image_dropped.connect(self.fetch_remote_image)
|
||||
self.related_images = list()
|
||||
self.related_images = ImageList()
|
||||
self._pixmap_cache = pixmap_cache
|
||||
self.current_pixmap_key = None
|
||||
|
||||
@@ -205,9 +206,9 @@ class CoverArtThumbnail(ActiveLabel):
|
||||
|
||||
def set_metadata(self, metadata):
|
||||
data = None
|
||||
self.related_images = []
|
||||
self.related_images = ImageList()
|
||||
if metadata and metadata.images:
|
||||
self.related_images = sorted(metadata.images, key=lambda image: image.types_as_string())
|
||||
self.related_images = metadata.images
|
||||
data = [image for image in metadata.images if image.is_front_image()]
|
||||
if not data:
|
||||
# There's no front image, choose the first one available
|
||||
|
||||
@@ -26,6 +26,7 @@ from picard.file import File
|
||||
from picard.track import Track
|
||||
from picard.album import Album
|
||||
from picard.coverart.image import CoverArtImageIOError
|
||||
from picard.coverart.imagelist import ImageList
|
||||
from picard.util import format_time, encode_filename, bytes2human, webbrowser2, union_sorted_lists
|
||||
from picard.ui import PicardDialog
|
||||
from picard.ui.ui_infodialog import Ui_InfoDialog
|
||||
@@ -99,14 +100,11 @@ class InfoDialog(PicardDialog):
|
||||
def __init__(self, obj, parent=None):
|
||||
PicardDialog.__init__(self, parent)
|
||||
self.obj = obj
|
||||
self.images = []
|
||||
self.existing_images = []
|
||||
self.images = ImageList()
|
||||
self.existing_images = ImageList()
|
||||
self.ui = Ui_InfoDialog()
|
||||
self.display_existing_artwork = False
|
||||
|
||||
def get_image_type(image):
|
||||
return image.types_as_string()
|
||||
|
||||
if (isinstance(obj, File) and
|
||||
isinstance(obj.parent, Track) or
|
||||
isinstance(obj, Track) or
|
||||
@@ -115,7 +113,7 @@ class InfoDialog(PicardDialog):
|
||||
# or linked to a track object or it's an album with files
|
||||
if (getattr(obj, 'orig_metadata', None) is not None and
|
||||
obj.orig_metadata.images and
|
||||
sorted(obj.orig_metadata.images, key=get_image_type) != sorted(obj.metadata.images, key=get_image_type)):
|
||||
obj.orig_metadata.images != obj.metadata.images):
|
||||
self.display_existing_artwork = True
|
||||
self.existing_images = obj.orig_metadata.images
|
||||
|
||||
@@ -217,16 +215,9 @@ class InfoDialog(PicardDialog):
|
||||
self.artwork_table.setCellWidget(row, self.artwork_table._type_col, type_wgt)
|
||||
self.artwork_table.setItem(row, self.artwork_table._type_col, item)
|
||||
|
||||
def arrange_images(self):
|
||||
def get_image_type(image):
|
||||
return image.types_as_string()
|
||||
self.images.sort(key=get_image_type)
|
||||
self.existing_images.sort(key=get_image_type)
|
||||
|
||||
def _display_artwork_tab(self):
|
||||
if not self.images:
|
||||
self.tab_hide(self.ui.artwork_tab)
|
||||
self.arrange_images()
|
||||
self._display_artwork_type()
|
||||
self._display_artwork(self.images, self.artwork_table._new_cover_col)
|
||||
if self.existing_images:
|
||||
|
||||
Reference in New Issue
Block a user