Пример #1
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))
Пример #2
0
    def run(self):
        coversFound = 0
        if self.album and self.artist and len(self.album) and len(self.artist):
            self.setStatusText(
                self.dialog.tr("Searching images for '%(album)s' by %(artist)s...")
                % {"album": self.album, "artist": self.artist}
            )
        elif len(self.album):
            self.setStatusText(self.dialog.tr("Searching images for the album '%(album)s'...") % {"album": self.album})
        elif len(self.artist):
            self.setStatusText(
                self.dialog.tr("Searching images for the artist %(artist)s...") % {"artist": self.artist}
            )

        try:
            for c in albumart.getAvailableCovers(self.artist, self.album):
                coversFound += 1
                if self.isCanceled():
                    break

                img = Image.open(c.path)
                img.load()

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

                self.postEvent(self.dialog, CoverDownloadedEvent(self, c))
                # better fake progress than none at all :)
                # we can't tell how many covers we've
                # downloaded as they may have been blank or
                # corrupt.
                self.setProgress(coversFound - 1, coversFound)
        except Exception, x:
            self.postEvent(self.dialog, ExceptionEvent(self, x))