def cover(flac): """Add cover images to tagged FLAC files.""" mb = MusicBrainz() for path in flac: info = FileInfo(path) if not info.parse_ok: continue album_tags = info.tags.album_tags() mbid = album_tags.get('RELEASE_MBID') if mbid is None: continue front = info.get_picture(FRONT_COVER_TYPE) if front is not None: continue click.echo('{} {}'.format(info.summary, path)) try: release = mb.release_by_id(mbid) data = mb.front_cover(release) if data is not None: front = fc.parse_picture(data, FRONT_COVER_TYPE) if info.set_picture(front): info.update() width = front.width height = front.height type_ = fc.picture_ext(front).upper() click.echo('- {} x {} {}'.format(width, height, type_)) else: click.echo('- No image found') except MusicBrainzError: click.echo('- Error while querying MusicBrainz') continue except Exception as e: click.echo('- Error while processing image ({})'.format(e)) continue
def test_mbid_cuesheet_lookup(self): """Test a lookup by release ID and cuesheet.""" mb = MusicBrainz() offsets = [ 0, 5515440, 13365240, 20744640, 30230256, 39166680, 43464960, 54129516, 68778360, 78015840, 86018520, 95589396, 108109680, 111931680, 121875936, 134958936, ] mbid = 'c51e17aa-653f-3a8b-88df-8e7148d83587' release = mb.release_by_id(mbid, FakeCueSheet(offsets)) assert release is not None self.assert_release( [release], mbid, 'Belly', 'Star', '1993', '5014436300202' ) media = release['media'] assert len(media) == 1 tracks = media[0]['tracks'] assert len(tracks) == 15 number = tracks[2]['number'] assert number == '3' title = tracks[2]['title'] assert title == 'Dusted' front_cover = mb.front_cover(release) assert front_cover is not None