def getFilenameForPath(self, path):
   if not "%(" in self.filename:
     return self.filename
   (artist, album) = albumart.guessArtistAndAlbum(path)
   artist = artist or "Unknown"
   album = album or "Unknown"
   return self.filename\
     .replace("%(album)", album)\
     .replace("%(artist)", artist)
示例#2
0
    def run(self):
        itemsProcessed = 0
        recognized = 0
        coversFound = 0
        coversInstalled = 0
        failures = 0
        cache = {}

        try:
            for path in self.items:
                if self.isCanceled():
                    failures = -1
                    break

                (artist, album) = albumart.guessArtistAndAlbum(path)

                if artist and album:
                    recognized += 1
                    self.setStatusText(
                        self.dialog.tr('Searching cover for "%(album)s" by %(artist)s...')
                        % {"album": album, "artist": artist}
                    )
                    if cache.has_key((artist, album)):
                        try:
                            albumart.setCover(path, cache[(artist, album)])
                            coversInstalled += 1
                        except Exception, x:
                            failures += 1
                            traceback.print_exc(file=sys.stderr)
                    else:
                        foundAny = False
                        for cover in albumart.getAvailableCovers(
                            artist, album, requireExactMatch=self.requireExactMatch
                        ):
                            foundAny = True
                            try:
                                img = Image.open(cover.path)
                                img.load()
                                coversFound += 1

                                # convert to JPEG if needed
                                if img.format != "JPEG":
                                    img = img.convert("RGB")
                                    img.save(cover.path)

                                cache[(artist, album)] = cover
                                albumart.setCover(path, cover)
                                coversInstalled += 1
                            except Exception, x:
                                failures += 1
                                traceback.print_exc(file=sys.stderr)
                            break
                        if not foundAny:
                            failures += 1
                itemsProcessed += 1
                self.setProgress(itemsProcessed, len(self.items))
示例#3
0
 def __init__(self, parent, path, extensions):
   QListViewItem.__init__(self, parent)
   self.setDropEnabled(True)
   self.path = path
   self.artist, self.album = albumart.guessArtistAndAlbum(path)
   self.tracks = []
   self.margin = 8
   self.iconSize = 64
   self.openTrigger = QRect()
   self.titleFont = QFont(QFont().family(), QFont().pointSize() + 3, QFont.Bold)
   self.setText(0, os.path.basename(self.path))
   self.extensions = extensions
   self.itemCount = len(self.getChildren())