Exemple #1
0
def tag(flac, mbid, hide, unhide, hide_track, unhide_track):
    """Tag FLAC files.

    Files with a cue sheet but no album/track-level tags will be tagged using
    metadata from MusicBrainz.
    """
    mb = MusicBrainz()
    for path in flac:
        info = FileInfo(path)
        summary = info.summary
        if not summary.parse_ok or not summary.cuesheet:
            continue
        tagged = summary.album_tags or summary.track_tags
        album_edit = hide or unhide
        track_edit = hide_track or unhide_track
        if tagged and not (album_edit or track_edit):
            continue
        click.echo('{} {}'.format(summary, path))
        album_changed = False
        track_changed = False
        # Query MusicBrainz
        if not tagged:
            try:
                if mbid is None:
                    release = find_release(mb, info)
                else:
                    release = mb.release_by_id(mbid, info.cuesheet)
                if release is None:
                    continue
                original_date = mb.first_release_date(release['group-id'])
            except MusicBrainzError:
                click.echo('- Error while querying MusicBrainz')
                continue
            album_changed |= update_album_tags(info, release, original_date)
            track_changed |= update_track_tags(info, release)
        # Hide or unhide album
        tags = info.tags.album_tags()
        if hide:
            tags['HIDE'] = 'true'
        if unhide:
            tags.pop('HIDE', None)
        album_changed |= info.tags.update_album(tags)
        # Hide or unhide tracks
        for number in hide_track:
            tags = info.tags.track_tags(number)
            tags['HIDE'] = 'true'
            track_changed |= info.tags.update_track(number, tags)
        for number in unhide_track:
            tags = info.tags.track_tags(number)
            tags.pop('HIDE', None)
            track_changed |= info.tags.update_track(number, tags)
        # Save any changes
        if album_changed or track_changed:
            info.update()
Exemple #2
0
 def test_first_release_date(self):
     """Test the first_release_date method."""
     mb = MusicBrainz()
     date = mb.first_release_date('95950776-0eb8-3672-a503-e2181b1773be')
     assert date == '1978'