def _loading_finished(self, callback, result=None, error=None): if self.state != File.PENDING or self.tagger.stopping: return config = get_config() if error is not None: self.state = self.ERROR self.error_append(str(error)) # If loading failed, force format guessing and try loading again from picard.formats.util import guess_format try: alternative_file = guess_format(self.filename) except (FileNotFoundError, OSError): log.error("Guessing format of %s failed", self.filename, exc_info=True) alternative_file = None if alternative_file: # Do not retry reloading exactly the same file format if type(alternative_file) != type(self): # pylint: disable=unidiomatic-typecheck log.debug('Loading %r failed, retrying as %r' % (self, alternative_file)) self.remove() alternative_file.load(callback) return else: alternative_file.remove() # cleanup unused File object from picard.formats import supported_extensions file_name, file_extension = os.path.splitext(self.base_filename) if file_extension not in supported_extensions(): log.error( 'Unsupported media file %r wrongly loaded. Removing ...', self) callback(self, remove_file=True) return else: self.clear_errors() self.state = self.NORMAL postprocessors = [] if config.setting["guess_tracknumber_and_title"]: postprocessors.append(self._guess_tracknumber_and_title) self._copy_loaded_metadata(result, postprocessors) # use cached fingerprint from file metadata if not config.setting["ignore_existing_acoustid_fingerprints"]: fingerprints = self.metadata.getall('acoustid_fingerprint') if fingerprints: self.set_acoustid_fingerprint(fingerprints[0]) run_file_post_load_processors(self) self.update() callback(self)
def test_guess_format(self): temp_file = self.copy_of_original_testfile() audio = guess_format(temp_file) audio_original = picard.formats.open_(self.filename) self.assertEqual(type(audio), type(audio_original))
def OggContainerFile(filename): """Generic Ogg file.""" options = [ OggFLACFile, OggOpusFile, OggSpeexFile, OggTheoraFile, OggVorbisFile ] return guess_format(filename, options)
def OggVideoFile(filename): """Generic Ogg video file.""" options = [OggTheoraFile] return guess_format(filename, options)
def OggAudioFile(filename): """Generic Ogg audio file.""" options = [OggFLACFile, OggOpusFile, OggSpeexFile, OggVorbisFile] return guess_format(filename, options)