def test_read_standardize_write_file(self): path = self.create_test_file(TEST_TAG_LIST) au_file = audio_file.scan(path) self.assertTrue(au_file is not None) au_file.volume = TEST_VOL au_file.import_timestamp = TEST_TS au_file.album_id = 77777 # Inject the necessary UFID tag. au_file.mutagen_id3[constants.UFID_OWNER_IDENTIFIER] = ufid.ufid_tag( TEST_VOL, TEST_TS, au_file.fingerprint) import_file.standardize_file(au_file) # Do some basic checks for tag in au_file.mutagen_id3.values(): self.assertTrue((tag.FrameID in constants.ID3_TAG_WHITELIST or tag.HashKey in constants.ID3_TAG_WHITELIST)) for frame_id in constants.ID3_TAG_REQUIRED: self.assertTrue(frame_id in au_file.mutagen_id3) # Write the standardized file out, then re-read it and make sure # that everything is as we expected. alt_prefix = os.path.join(self.prefix, "alt") new_path = import_file.write_file(au_file, alt_prefix) new_au_file = audio_file.scan(new_path) self.assertEqual(sorted(au_file.mutagen_id3.keys()), sorted(new_au_file.mutagen_id3.keys())) for key in au_file.mutagen_id3.keys(): self.assertEqual(repr(au_file.mutagen_id3[key]), repr(new_au_file.mutagen_id3[key])) self.assertEqual(au_file.fingerprint, new_au_file.fingerprint) self.assertEqual(au_file.payload, new_au_file.payload)
def test_read_standardize_write_file(self): path = self.create_test_file(TEST_TAG_LIST) au_file = audio_file.scan(path) self.assertTrue(au_file is not None) au_file.volume = TEST_VOL au_file.import_timestamp = TEST_TS au_file.album_id = 77777 # Inject the necessary UFID tag. au_file.mutagen_id3[constants.UFID_OWNER_IDENTIFIER] = ufid.ufid_tag( TEST_VOL, TEST_TS, au_file.fingerprint) import_file.standardize_file(au_file) # Do some basic checks for tag in au_file.mutagen_id3.values(): self.assertTrue( (tag.FrameID in constants.ID3_TAG_WHITELIST or tag.HashKey in constants.ID3_TAG_WHITELIST)) for frame_id in constants.ID3_TAG_REQUIRED: self.assertTrue(frame_id in au_file.mutagen_id3) # Write the standardized file out, then re-read it and make sure # that everything is as we expected. alt_prefix = os.path.join(self.prefix, "alt") new_path = import_file.write_file(au_file, alt_prefix) new_au_file = audio_file.scan(new_path) self.assertEqual(sorted(au_file.mutagen_id3.keys()), sorted(new_au_file.mutagen_id3.keys())) for key in au_file.mutagen_id3.keys(): self.assertEqual(repr(au_file.mutagen_id3[key]), repr(new_au_file.mutagen_id3[key])) self.assertEqual(au_file.fingerprint, new_au_file.fingerprint) self.assertEqual(au_file.payload, new_au_file.payload)
def add_album(self, alb, new_album_name=None): # Plug in the volume and import timestamp for this transaction. alb.set_volume_and_import_timestamp( self._volume, self._import_timestamp) alb.ensure_payloads() cprint(u'Adding Album "%s"' % alb.title()) sys.stdout.flush() # Write the files to our temporary prefix. for au_file in alb.all_au_files: # Might raise an ImportFileError. if not self._dry_run: import_file.write_file(au_file, self._tmp_prefix) # We forget the payloads immediately to save RAM. alb.drop_payloads() # Everything checks out! self._all_au_files.extend(alb.all_au_files) self.num_albums += 1 self.total_size_in_bytes += sum( au.frame_size for au in alb.all_au_files)
def add_album(self, alb, new_album_name=None): # Plug in the volume and import timestamp for this transaction. alb.set_volume_and_import_timestamp(self._volume, self._import_timestamp) alb.ensure_payloads() cprint(u'Adding Album "%s"' % alb.title()) sys.stdout.flush() # Write the files to our temporary prefix. for au_file in alb.all_au_files: # Might raise an ImportFileError. if not self._dry_run: import_file.write_file(au_file, self._tmp_prefix) # We forget the payloads immediately to save RAM. alb.drop_payloads() # Everything checks out! self._all_au_files.extend(alb.all_au_files) self.num_albums += 1 self.total_size_in_bytes += sum(au.frame_size for au in alb.all_au_files)