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_defines_metadata_tags(): assert_that( tuple(Album.tags()), contains_inanyorder("release_name", "compilation", "lead_performer", "lead_performer_region", "guest_performers", "label_name", "upc", "catalog_number", "release_time", "original_release_time", "lead_performer_date_of_birth", "contributors", "isnis", "ipis"))
def test_initializes_with_album_only_metadata(): metadata = build.metadata(track_title="Smash Smash", release_name="Honeycomb", lead_performer="Joel Miller", images=[build.image(data=b"front.jpeg")]) album = Album(metadata) assert_that(album.release_name, equal_to("Honeycomb"), "release name") assert_that(album.lead_performer, equal_to("Joel Miller"), "lead performer") assert_that(album.images, contains(has_property("data", b"front.jpeg")), "attached pictures") assert_that(album.metadata, not_(has_key("track_title")), "album metadata")
def test_holds_a_list_of_tracks_in_order(): album = Album() album.add_track(build.track(track_title="Track 1")) album.add_track(build.track(track_title="Track 2")) album.add_track(build.track(track_title="Track 3")) assert_that( album.tracks, contains(has_property("track_title", "Track 1"), has_property("track_title", "Track 2"), has_property("track_title", "Track 3")), "track titles")
def album(filename="album.tgit", of_type=Album.Type.FLAC, images=(), tracks=(), **meta): new_album = Album(filename=filename, of_type=of_type) for tag, value in meta.items(): setattr(new_album, tag, value) for current_image in images: new_album.add_image(*current_image) for current_track in tracks: new_album.add_track(current_track) return new_album
def test_has_initially_no_metadata_or_images(): album = Album() for tag in Album.tags(): assert_that(getattr(album, tag), none(), tag) assert_that(album.images, empty(), "images")
def test_associates_track_to_album(): album = Album() track = build.track() album.add_track(track) assert_that(track.album, is_(album), "album of track")
def test_is_no_longer_empty_when_holding_tracks(): album = Album() album.add_track(build.track()) assert_that(album.empty(), is_(False), "emptiness")