Пример #1
0
 def test_remove_picture(self, datadir):
     """Test removing a picture."""
     file = FileInfo(datadir / 'tagged.flac')
     assert file.remove_picture(3) is True
     assert file.remove_picture(3) is False
     file.update()
     assert file.get_picture(3) is None
Пример #2
0
 def test_export_cover(self, datadir):
     """Test the export_cover function."""
     info = FileInfo(datadir / 'tagged.flac')
     front = info.get_picture(3)
     fc.export_cover(front, str(datadir))
     path = Path(datadir / 'cover.jpg')
     assert path.is_file()
Пример #3
0
def convert(flac, output_dir, hidden):
    """Convert FLAC files."""
    for path in flac:
        info = FileInfo(path)
        summary = info.summary
        if not summary.parse_ok or not summary.cuesheet:
            continue
        album_tags = info.tags.album_tags()
        if album_tags.get('HIDE') == 'true' and not hidden:
            continue
        if 'ARTIST' not in album_tags or 'ALBUM' not in album_tags:
            continue
        tracks = fc.prepare_tracks(info, output_dir, 'ogg')
        if not tracks:
            continue
        if any(map(lambda t: os.path.exists(t.path), tracks)):
            continue
        click.echo('{} {}'.format(summary, path))
        try:
            click.echo('- Decoding tracks')
            tempdir = fc.decode_tracks(info)
            click.echo('- Encoding tracks')
            fc.encode_tracks(tracks, tempdir, 'ogg')
        except fc.ConversionError as e:
            click.echo('ERROR {}'.format(e))
            click.get_current_context().exit(1)
        front = info.get_picture(FRONT_COVER_TYPE)
        if front is not None:
            dst_base = os.path.dirname(tracks[0].path)
            fc.export_cover(front, dst_base)
Пример #4
0
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
Пример #5
0
def analyze(flac, verbose, hidden):
    """Analyze FLAC files.

    For each file, shows a list of flags followed by the filename.

    \b
    Flags:
    - O: The file parsed successfully.
    - C: A cue sheet is present.
    - A: Album-level tags are present (any number).
    - T: Track-level tags are present (any number).
    - P: Pictures are present (any number).
    """
    for path in flac:
        info = FileInfo(path)
        if info.parse_ok:
            album_tags = info.tags.album_tags()
        else:
            album_tags = {}
        if album_tags.get('HIDE') != 'true' and hidden:
            continue
        if not verbose:
            click.echo('{} {}'.format(info.summary, path))
        else:
            img = '|                 |'
            url = ''
            if info.parse_ok:
                front = info.get_picture(FRONT_COVER_TYPE)
                if front is not None:
                    width = front.width
                    height = front.height
                    type_ = fc.picture_ext(front).upper()
                    img = '| {:4d} x {:4d} {} |'.format(width, height, type_)
                mbid = album_tags.get('RELEASE_MBID')
                if mbid is not None:
                    url = ' | ' + RELEASE_URL.format(mbid)
            click.echo('{} {} {}{}'.format(info.summary, img, path, url))