def fetch_art(config): """A coroutine that fetches and applies album art for albums where appropriate. """ lib = _reopen_lib(config.lib) task = None while True: task = yield task if task.should_skip(): continue if task.should_fetch_art(): artpath = lib.beets.autotag.art.art_for_album(task.info, task.path) # Save the art if any was found. if artpath: try: album = lib.get_album(task.album_id) album.set_art(artpath) if config.delete and not util.samefile(artpath, album.artpath): # Delete the original file after it's imported. os.remove(artpath) finally: lib.save(False)
def fetch_art(config): """A coroutine that fetches and applies album art for albums where appropriate. """ lib = _reopen_lib(config.lib) task = None while True: task = yield task if task.should_skip(): continue if task.should_fetch_art(): artpath = lib.beets.autotag.art.art_for_album(task.info, task.path) # Save the art if any was found. if artpath: try: album = lib.get_album(task.album_id) album.set_art(artpath) if config.delete and not util.samefile( artpath, album.artpath): # Delete the original file after it's imported. os.remove(artpath) finally: lib.save(False)
def set_art(self, path): """Sets the album's cover art to the image at the given path. The image is copied into place, replacing any existing art. """ path = bytestring_path(path) oldart = self.artpath artdest = self.art_destination(path) if oldart and samefile(path, oldart): # Art already set. return elif samefile(path, artdest): # Art already in place. self.artpath = path return # Normal operation. if oldart == artdest: util.soft_remove(oldart) util.copy(path, artdest) self.artpath = artdest
def move(self, dest, copy=False): """Moves or copies the item's file, updating the path value if the move succeeds. If a file exists at ``dest``, then it is slightly modified to be unique. """ if not util.samefile(self.path, dest): dest = util.unique_path(dest) if copy: util.copy(self.path, dest) else: util.move(self.path, dest) # Either copying or moving succeeded, so update the stored path. self.path = dest