def metadata(images=(), **meta): new_metadata = Metadata(**meta) for current_image in images: new_metadata.addImage(*current_image) return new_metadata
def test_removes_frame_when_tag_not_in_metadata(mp3): filename = mp3(TALB="Album", TMCL=[["Guitar", "Guitarist"]], TIPL=[["mix", "Mixing Engineer"]], USLT=("", "fra")) container.save(filename, Metadata()) assert_contains_metadata(filename, Metadata())
def test_overwrites_existing_attached_pictures(mp3): filename = mp3(APIC_FRONT=("image/jpeg", "", b"front-cover.jpg")) metadata = Metadata() container.save(filename, metadata) assert_that(container.load(filename).images, has_length(0), "removed images") metadata.addImage(mime="image/jpeg", data=b"salers.jpg", desc="Front") container.save(filename, metadata) assert_that(container.load(filename).images, has_length(1), "updated images")
def test_stores_several_pictures(flac): filename = flac() metadata = Metadata() metadata.addImage("image/jpeg", b"front-1.jpg", desc="Front Cover") metadata.addImage("image/jpeg", b"front-2.jpg", desc="Front Cover") container.save(filename, metadata) assert_that(container.load(filename).images, contains_inanyorder( Image("image/jpeg", b"front-1.jpg", type_=Image.OTHER, desc="Front Cover"), Image("image/jpeg", b"front-2.jpg", type_=Image.OTHER, desc="Front Cover (2)"), ))
def test_stores_several_pictures_sharing_the_same_description(mp3): filename = mp3() metadata = Metadata() metadata.addImage("image/jpeg", b"salers.jpg", desc="Front Cover") metadata.addImage("image/jpeg", b"ragber.jpg", desc="Front Cover") container.save(filename, metadata) assert_that(container.load(filename).images, contains_inanyorder( Image("image/jpeg", b"salers.jpg", type_=Image.OTHER, desc="Front Cover"), Image("image/jpeg", b"ragber.jpg", type_=Image.OTHER, desc="Front Cover (2)"), ))
def test_overwrites_existing_attached_pictures(mp3): filename = mp3(APIC_FRONT=("image/jpeg", "", b"front-cover.jpg")) metadata = Metadata() container.save(filename, metadata) assert_that( container.load(filename).images, has_length(0), "removed images") metadata.addImage(mime="image/jpeg", data=b"salers.jpg", desc="Front") container.save(filename, metadata) assert_that( container.load(filename).images, has_length(1), "updated images")
def test_round_trips_metadata_to_file(mp3): metadata = Metadata() metadata.addImage("image/jpeg", b"salers.jpg", Image.FRONT_COVER) metadata["release_name"] = "Album" metadata["compilation"] = True metadata["lead_performer"] = "Lead Performer" metadata["lead_performer_region"] = ("CA", "MTL") metadata["isnis"] = { "Lead Performer": "0000123456789", "Lyricist": "0000123456789" } metadata["ipis"] = {"Lyricist": "0000123456789"} metadata["iswc"] = "T-345246800-1" metadata["guest_performers"] = [("Guitar", "Guitarist"), ("Guitar", "Bassist"), ("Piano", "Pianist")] metadata["label_name"] = "Label Name" metadata["production_company"] = "Production Company" metadata["production_company_region"] = ("CA", "MTL") metadata["catalog_number"] = "123 456-1" metadata["upc"] = "987654321111" metadata["recording_time"] = "2012-07-01" metadata["release_time"] = "2013-12-01" metadata["original_release_time"] = "1999-01-01" metadata["recording_studio"] = "Studio Name" metadata["recording_studio_region"] = ("CA", "MTL") metadata["recording_studio_address"] = "2020 des zinzins, Montreal" metadata["music_producer"] = "Music Producer" metadata["mixer"] = "Mixing Engineer" metadata["contributors"] = [("recording", "Recording Eng."), ("mastering", "Mastering Eng."), ("recording", "Assistant Recording Eng.")] metadata["comments"] = "Comments" metadata["primary_style"] = "Jazz" metadata["track_title"] = "Track Title" metadata["version_info"] = "Version Info" metadata["featured_guest"] = "Featured Guest" metadata["lyricist"] = ["Lyricist"] metadata["composer"] = ["Composer"] metadata["publisher"] = ["Publisher"] metadata["isrc"] = "ZZXX87654321" metadata["labels"] = "Tag1 Tag2 Tag3" metadata["lyrics"] = "Lyrics" metadata["language"] = "fra" metadata["tagger"] = "TGiT" metadata["tagger_version"] = "1.0" metadata["tagging_time"] = "2014-03-26 18:18:55" metadata["track_number"] = 3 metadata["total_tracks"] = 5 assert_can_be_saved_and_reloaded_with_same_state(mp3, metadata)
def test_round_trips_metadata_to_file(flac): metadata = Metadata() metadata.addImage("image/jpeg", b"honeycomb.jpg", Image.FRONT_COVER) metadata["release_name"] = "St-Henri" metadata["lead_performer"] = "Joel Miller" metadata["lead_performer_region"] = ("CA", "MTL") metadata["isnis"] = { "Joel Miller": "0000000123456789", "Rebecca Ann Maloy": "9876543210000000" } metadata["ipis"] = { "Joel Miller": "0000000123456789", "Rebecca Ann Maloy": "9876543210000000" } metadata["label_name"] = "Effendi Records Inc." metadata["primary_style"] = "Modern Jazz" metadata["recording_time"] = "2007-11-02" metadata["track_title"] = "Salsa Coltrane" metadata["isrc"] = "CABL31201254" metadata["iswc"] = "T-345246800-1" metadata["tagger"] = "TGiT" metadata["tagger_version"] = "1.0" metadata["tagging_time"] = "2014-03-26 18:18:55" metadata["track_number"] = 3 metadata["total_tracks"] = 5 metadata["recording_studio"] = "Effendi Records Inc." metadata["recording_studio_region"] = ("CA", "MTL") metadata["recording_studio_address"] = "2020 des zinzins, Montreal" metadata["production_company"] = "Effendi Records Inc." metadata["production_company_region"] = ("CA", "MTL") metadata["music_producer"] = "Joel Miller & Paul Johnston" metadata["lyricist"] = ["Joel Miller"] metadata["catalog_number"] = "001-002-003" metadata["upc"] = "123456789999" metadata["mixer"] = "Mixing Engineer" metadata["comments"] = "Comments of any nature" metadata["publisher"] = ["Who publishes the disc the track came from"] metadata["composer"] = ["Composer of the work"] metadata["version_info"] = "Specifics about that version of the track" metadata["lyrics"] = "Lyrics of the track" metadata["language"] = "Language of the lyrics" metadata["compilation"] = False metadata["featured_guest"] = "A collaborating artist" metadata["labels"] = "tag1, tag2, tag3" metadata["release_time"] = "2008-03-01" metadata["guest_performers"] = [("Guitar", "Guitarist"), ("Guitar", "Bassist"), ("Piano", "Pianist")] _assert_can_be_saved_and_reloaded_with_same_state(flac, metadata)
def test_overwrites_existing_attached_pictures(flac): filename = flac(PICTURES=( ("image/jpeg", PictureType.FRONT_COVER, "Front", b"front.jpg"), ("image/jpeg", PictureType.BACK_COVER, "Back", b"back.jpg"))) metadata = Metadata() container.save(filename, metadata) assert_that(container.load(filename).images, has_length(0), "removed images") metadata.addImage(mime="image/jpeg", data=b"front.jpg", desc="Front") container.save(filename, metadata) assert_that(container.load(filename).images, has_length(1), "updated images")
def test_looks_up_images_by_type(): metadata = Metadata() metadata.addImage("img/jpeg", "front-cover.jpg", Image.FRONT_COVER) metadata.addImage("img/png", "front-cover.png", Image.FRONT_COVER) metadata.addImage("img/jpeg", "back-cover.jpg", Image.BACK_COVER) assert_that( metadata.imagesOfType(Image.FRONT_COVER), contains_inanyorder(has_property("data", "front-cover.jpg"), has_property("data", "front-cover.png")), "front cover images")
def test_updates_tags_and_replaces_images_when_updated(): metadata = Metadata() metadata["artist"] = "Pascal Obispo" metadata.addImage("img/jpeg", "missing") other = Metadata() other["album"] = "Un jour comme aujourd'hui" other.addImage("img/png", "cover.png") metadata.update(other) assert_that( metadata, has_entries(artist="Pascal Obispo", album="Un jour comme aujourd'hui"), "updated tags") assert_that(metadata.images, contains(has_property("data", "cover.png")), "updated images")
def test_round_trips_metadata_to_file(mp3): metadata = Metadata() metadata.addImage("image/jpeg", b"salers.jpg", Image.FRONT_COVER) metadata["release_name"] = "Album" metadata["compilation"] = True metadata["lead_performer"] = "Lead Performer" metadata["lead_performer_region"] = ("CA", "MTL") metadata["isnis"] = {"Lead Performer": "0000123456789", "Lyricist": "0000123456789"} metadata["ipis"] = {"Lyricist": "0000123456789"} metadata["iswc"] = "T-345246800-1" metadata["guest_performers"] = [("Guitar", "Guitarist"), ("Guitar", "Bassist"), ("Piano", "Pianist")] metadata["label_name"] = "Label Name" metadata["production_company"] = "Production Company" metadata["production_company_region"] = ("CA", "MTL") metadata["catalog_number"] = "123 456-1" metadata["upc"] = "987654321111" metadata["recording_time"] = "2012-07-01" metadata["release_time"] = "2013-12-01" metadata["original_release_time"] = "1999-01-01" metadata["recording_studio"] = "Studio Name" metadata["recording_studio_region"] = ("CA", "MTL") metadata["recording_studio_address"] = "2020 des zinzins, Montreal" metadata["music_producer"] = "Music Producer" metadata["mixer"] = "Mixing Engineer" metadata["contributors"] = [("recording", "Recording Eng."), ("mastering", "Mastering Eng."), ("recording", "Assistant Recording Eng.")] metadata["comments"] = "Comments" metadata["primary_style"] = "Jazz" metadata["track_title"] = "Track Title" metadata["version_info"] = "Version Info" metadata["featured_guest"] = "Featured Guest" metadata["lyricist"] = ["Lyricist"] metadata["composer"] = ["Composer"] metadata["publisher"] = ["Publisher"] metadata["isrc"] = "ZZXX87654321" metadata["labels"] = "Tag1 Tag2 Tag3" metadata["lyrics"] = "Lyrics" metadata["language"] = "fra" metadata["tagger"] = "TGiT" metadata["tagger_version"] = "1.0" metadata["tagging_time"] = "2014-03-26 18:18:55" metadata["track_number"] = 3 metadata["total_tracks"] = 5 assert_can_be_saved_and_reloaded_with_same_state(mp3, metadata)
def test_overwrites_existing_attached_pictures(flac): filename = flac(PICTURES=(("image/jpeg", PictureType.FRONT_COVER, "Front", b"front.jpg"), ("image/jpeg", PictureType.BACK_COVER, "Back", b"back.jpg"))) metadata = Metadata() container.save(filename, metadata) assert_that( container.load(filename).images, has_length(0), "removed images") metadata.addImage(mime="image/jpeg", data=b"front.jpg", desc="Front") container.save(filename, metadata) assert_that( container.load(filename).images, has_length(1), "updated images")
def test_handles_flac_files_using_flac_container(flac): audio = flac() metadata = Metadata(lead_performer="Joel Miller") embedded_containers.save_metadata(audio, metadata) metadata = embedded_containers.load_metadata(audio) assert_that(metadata, has_entry('lead_performer', "Joel Miller"), 'embedded metadata')
def test_is_a_mutable_container(): metadata = Metadata(artist="James Blunt") assert_that(metadata["artist"], equal_to("James Blunt"), "accessed item") metadata["artist"] = "Adele" assert_that(metadata["artist"], equal_to("Adele"), "assigned item") metadata["album"] = "Adele 21" assert_that(metadata, has_length(2), "length") assert_that("artist", is_in(metadata), "member") del metadata["artist"] assert_that("title", is_not(is_in(metadata)), "member")
def test_removes_old_ipi_frames(mp3): filename = mp3(TXXX_IPI_Joel_Miller="00000123456789", TXXX_IPI_Rebecca_Ann_Maloy="98765432100000") container.save(filename, Metadata(ipis={"Joel Miller": "00000123456789"})) tags = MP3(filename) assert_that( tags, all_of(has_key("TXXX:IPI:Joel Miller"), not_(has_key("TXXX:IPI:Rebecca Ann Maloy"))), "tags in file")
def test_round_trips_metadata_to_file(flac): metadata = Metadata() metadata.addImage("image/jpeg", b"honeycomb.jpg", Image.FRONT_COVER) metadata["release_name"] = "St-Henri" metadata["lead_performer"] = "Joel Miller" metadata["lead_performer_region"] = ("CA", "MTL") metadata["isnis"] = {"Joel Miller": "0000000123456789", "Rebecca Ann Maloy": "9876543210000000"} metadata["ipis"] = {"Joel Miller": "0000000123456789", "Rebecca Ann Maloy": "9876543210000000"} metadata["label_name"] = "Effendi Records Inc." metadata["primary_style"] = "Modern Jazz" metadata["recording_time"] = "2007-11-02" metadata["track_title"] = "Salsa Coltrane" metadata["isrc"] = "CABL31201254" metadata["iswc"] = "T-345246800-1" metadata["tagger"] = "TGiT" metadata["tagger_version"] = "1.0" metadata["tagging_time"] = "2014-03-26 18:18:55" metadata["track_number"] = 3 metadata["total_tracks"] = 5 metadata["recording_studio"] = "Effendi Records Inc." metadata["recording_studio_region"] = ("CA", "MTL") metadata["recording_studio_address"] = "2020 des zinzins, Montreal" metadata["production_company"] = "Effendi Records Inc." metadata["production_company_region"] = ("CA", "MTL") metadata["music_producer"] = "Joel Miller & Paul Johnston" metadata["lyricist"] = ["Joel Miller"] metadata["catalog_number"] = "001-002-003" metadata["upc"] = "123456789999" metadata["mixer"] = "Mixing Engineer" metadata["comments"] = "Comments of any nature" metadata["publisher"] = ["Who publishes the disc the track came from"] metadata["composer"] = ["Composer of the work"] metadata["version_info"] = "Specifics about that version of the track" metadata["lyrics"] = "Lyrics of the track" metadata["language"] = "Language of the lyrics" metadata["compilation"] = False metadata["featured_guest"] = "A collaborating artist" metadata["labels"] = "tag1, tag2, tag3" metadata["release_time"] = "2008-03-01" metadata["guest_performers"] = [("Guitar", "Guitarist"), ("Guitar", "Bassist"), ("Piano", "Pianist")] _assert_can_be_saved_and_reloaded_with_same_state(flac, metadata)
def test_stores_several_pictures_sharing_the_same_description(mp3): filename = mp3() metadata = Metadata() metadata.addImage("image/jpeg", b"salers.jpg", desc="Front Cover") metadata.addImage("image/jpeg", b"ragber.jpg", desc="Front Cover") container.save(filename, metadata) assert_that( container.load(filename).images, contains_inanyorder( Image("image/jpeg", b"salers.jpg", type_=Image.OTHER, desc="Front Cover"), Image("image/jpeg", b"ragber.jpg", type_=Image.OTHER, desc="Front Cover (2)"), ))
def test_stores_several_pictures(flac): filename = flac() metadata = Metadata() metadata.addImage("image/jpeg", b"front-1.jpg", desc="Front Cover") metadata.addImage("image/jpeg", b"front-2.jpg", desc="Front Cover") container.save(filename, metadata) assert_that( container.load(filename).images, contains_inanyorder( Image("image/jpeg", b"front-1.jpg", type_=Image.OTHER, desc="Front Cover"), Image("image/jpeg", b"front-2.jpg", type_=Image.OTHER, desc="Front Cover (2)"), ))
def load(self, filename): flac_file = mutagen.flac.FLAC(filename) metadata = Metadata() metadata["duration"] = flac_file.info.length metadata["bitrate"] = flac_file.info.sample_rate * flac_file.info.bits_per_sample for field in self.fields: field.read(flac_file, metadata) return metadata
def test_removes_deprecated_frames_on_save(mp3): filename = mp3(TXXX_Tagger="TGiT v1.1", TXXX_TAGGING_TIME="2014-03-26 14:18:55 EDT-0400", TXXX_UPC="987654321111") container.save(filename, Metadata()) tags = MP3(filename) assert_that( tags, all_of(not_(has_key("TXXX:Tagger")), not_(has_key("TXXX:TAGGING_TIME")), not_(has_key("TXXX:UPC"))), "tags in file")
def load(self, filename): audio_file = mp3.MP3(filename) frames = audio_file.tags or {} metadata = Metadata() metadata["duration"] = audio_file.info.length metadata["bitrate"] = audio_file.info.bitrate for processor in self._all_processors: processor.process_frames(metadata, frames) return metadata
def create_project(type_, name, location, reference_track_file=None): reference_track = from_catalog.load_track( reference_track_file) if reference_track_file else None metadata = reference_track.metadata.copy( ) if reference_track else Metadata() metadata['release_name'] = name album = Album(of_type=type_, metadata=metadata, filename=os.path.join(location, name, "{0}.tgit".format(name))) if reference_track: album.add_track(reference_track) to_catalog.save_project(album) studio.project_created(album) return album
def load_project(filename): album_folder = dirname(filename) tracks_folder = join(album_folder, TRACKS_FOLDER_NAME) artwork_folder = join(album_folder, ARTWORK_FOLDER_NAME) data = yaml.read_data(filename) if Version(data["version"]) < "1.10.0": data = _from_1_9_to_1_11(data) album = Album(Metadata(data), of_type=data["type"], filename=filename) for image in data["images"]: mime, filename, type_, desc = image album.add_image(mime, fs.read(join(artwork_folder, filename)), type_, desc) for track in data["tracks"]: album.add_track(_load_track(data["version"], tracks_folder, track)) return album
def test_copies_a_selection_of_its_tags_with_images(): metadata = Metadata(artist="Alain Souchon", album="C'est déjà ça", track="Foule sentimentale") metadata.addImage("img/jpeg", "front-cover.jpg") metadata.addImage("img/jpeg", "back-cover.jpg") selection = metadata.copy("artist", "album", "label") assert_that(selection, has_length(2)) assert_that( selection, all_of(has_entries(artist="Alain Souchon", album="C'est déjà ça"), is_not(has_key("track")), is_not(has_key("label"))), "selected tags") assert_that( selection.images, contains(has_property("data", "front-cover.jpg"), has_property("data", "back-cover.jpg")), "selected images")
def test_accesses_entries_as_attr0ibutes(): metadata = Metadata(artist="James Blunt") assert_that(metadata.artist, equal_to("James Blunt"), "accessed item")
def test_is_empty_when_cleared(): metadata = Metadata() metadata["artist"] = "John Doe" metadata.addImage("img/jpeg", "...") metadata.clear() assert_that(metadata.empty(), is_(True), "emptiness")
def __init__(self, metadata=None, of_type=Type.FLAC, filename=None): self.metadata = metadata.copy( *Album.tags()) if metadata is not None else Metadata() self.tracks = [] self.type = of_type self.filename = filename
def test_missing_tag_is_considered_none(): metadata = Metadata() assert_that(metadata["missing"], none(), "missing value")
def test_is_not_empty_when_containing_images(): metadata = Metadata() metadata.addImage("img/jpeg", "...") assert_that(metadata.empty(), is_(False), "emptiness")
def test_is_not_empty_when_holding_tags(): metadata = Metadata() metadata["artist"] = "John Doe" metadata.addImage("img/jpeg", "...") assert_that(metadata.empty(), is_(False), "emptiness")
def test_takes_none_as_absence_of_tag(mp3): filename = mp3() container.save(filename, Metadata(compilation=None)) assert_contains_metadata(filename, Metadata())
def __init__(self, filename, metadata=None, chain_of_title=None): self.filename = filename self.metadata = metadata or Metadata() self.chain_of_title = chain_of_title or ChainOfTitle.from_track(self)
def test_round_trips_empty_metadata_to_file(mp3): assert_can_be_saved_and_reloaded_with_same_state(mp3, Metadata())
def test_is_initially_empty(): metadata = Metadata() assert_that(metadata, empty(), "tags") assert_that(list(metadata.images), empty(), "images") assert_that(metadata.empty(), is_(True), "emptiness")
def test_handles_unicode_metadata(mp3): metadata = Metadata() metadata["release_name"] = "Titre en Français" assert_can_be_saved_and_reloaded_with_same_state(mp3, metadata)