def write_to_file(self, path): """Creates a new file containing this image's data. :raises EnvironmentError: error writing cover art file """ file_handle = fileutil.open_file(path, "wb") file_handle.write(self.data)
def _make_cover_art_file(self, filename, objects): if not isinstance(objects, list): objects = [objects] images = [] for image_object in objects: try: image = Image(image_object) except UnknownImageObjectException: logging.debug("Couldn't parse image object of type %s", type(image_object)) else: images.append(image) cover_image = None for candidate in images: if candidate.is_cover_art: cover_image = candidate break if cover_image is None: # no attached image is definitively cover art. use the first one. cover_image = images[0] cover_filename = "{0}.{1}.{2}".format(os.path.basename(filename), util.random_string(5), image.extension) cover_path = os.path.join(image_directory('cover-art'), cover_filename) try: file_handle = fileutil.open_file(cover_path, 'wb') file_handle.write(image.data) except IOError: logging.warn( "Couldn't write cover art file: {0}".format(cover_path)) cover_path = None return cover_path
def write_to_file(self, path): """Creates a new file containing this image's data. :raises EnvironmentError: error writing cover art file """ file_handle = fileutil.open_file(path, 'wb') file_handle.write(self.data)
def write_to_file(self, track_path): """Creates a new file containing this image's data. Returns the file's path. """ path = self._get_destination_path(self.get_extension(), track_path) try: file_handle = fileutil.open_file(path, 'wb') file_handle.write(self.data) except IOError: logging.warn("Couldn't write cover art file: {0}".format(path)) return None return path
def write_to_file(self, track_path): """Creates a new file containing this image's data. Returns the file's path. """ path = self._get_destination_path(self.get_extension(), track_path) try: file_handle = fileutil.open_file(path, 'wb') file_handle.write(self.data) except IOError: logging.warn( "Couldn't write cover art file: {0}".format(path)) return None return path
def _open_file(self): if self.options.resume: mode = 'ab' try: path = self.options.write_file self.resume_from = int(os.stat(path)[stat.ST_SIZE]) except OSError: # file doesn't exist, just skip resuming pass else: self.handle.setopt(pycurl.RESUME_FROM, self.resume_from) else: mode = 'wb' try: self._filehandle = fileutil.open_file(self.options.write_file, mode) except IOError: raise WriteError(self.options.write_file)