예제 #1
0
 def test_cuesheet_lookup(self):
     """Test a lookup by CueSheet."""
     mb = MusicBrainz()
     offsets = [
         0,
         11991084,
         24196200,
         31142244,
         44369304,
         53759664,
         60492264,
         70755804,
         84466200,
         93937704,
         103864320,
     ]
     releases = mb.releases_by_cuesheet(FakeCueSheet(offsets))
     self.assert_release(
         releases,
         '2c62e70e-5f2a-4aaf-913f-e29d212cc64c',
         'Van Morrison',
         'Moondance',
         '1989-03-09',
         '075992732628'
     )
예제 #2
0
파일: cli.py 프로젝트: 7adietri/flackup
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
예제 #3
0
파일: cli.py 프로젝트: 7adietri/flackup
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()
예제 #4
0
 def test_discid_lookup(self):
     """Test a lookup by disc ID."""
     mb = MusicBrainz()
     discid = 'RHNAnAo97C4V.gbmOWsLQwXfTOA-'
     releases = mb.releases_by_disc(FakeDisc(discid))
     self.assert_release(
         releases,
         '7542431b-0fab-4443-a994-5fa98593da02',
         'Zoë Keating',
         'Into the Trees',
         '2010-06-19',
         '700261301921'
     )
예제 #5
0
 def test_toc_lookup(self):
     """Test a lookup by TOC string."""
     mb = MusicBrainz()
     toc = '1 12 178475 150 12289 27294 41177 56350 74389 87462 100844 114867 133013 148708 157085'  # noqa
     releases = mb.releases_by_disc(FakeDisc(None, toc, 12))
     self.assert_release(
         releases,
         '43607a9a-54cd-4346-88db-50d7bcbfbd33',
         'All India Radio',
         'The Silent Surf',
         '2010-12-06',
         '884502818352'
     )
예제 #6
0
 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
예제 #7
0
 def test_mbid_lookup(self):
     """Test a lookup by release ID."""
     mb = MusicBrainz()
     release = mb.release_by_id('68d6add0-b185-38ad-9814-39ed5e4e231a')
     assert release is not None
     self.assert_release(
         [release],
         '68d6add0-b185-38ad-9814-39ed5e4e231a',
         'David Bowie',
         '“Heroes”',
         '1999-09-17',
         '724352190805'
     )
     media = release['media']
     assert len(media) == 1
     tracks = media[0]['tracks']
     assert len(tracks) == 10
     number = tracks[2]['number']
     assert number == '3'
     title = tracks[2]['title']
     assert title == '“Heroes”'
예제 #8
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'
예제 #9
0
 def test_invalid_lookup(self):
     """Test an invalid lookup by disc ID."""
     mb = MusicBrainz()
     with pytest.raises(MusicBrainzError):
         mb.releases_by_disc(FakeDisc('invalid-id'))