Ejemplo n.º 1
0
    def test_image_encoding(self):
        """For compatibility with OS X/iTunes.

        See https://github.com/beetbox/beets/issues/899#issuecomment-62437773
        """

        for v23 in [True, False]:
            mf = self._make_test(id3v23=v23)
            try:
                mf.images = [
                    mediafile.Image(b'data', desc=u""),
                    mediafile.Image(b'data', desc=u"foo"),
                    mediafile.Image(b'data', desc=u"\u0185"),
                ]
                mf.save()
                apic_frames = mf.mgfile.tags.getall('APIC')
                encodings = dict([(f.desc, f.encoding) for f in apic_frames])
                self.assertEqual(
                    encodings, {
                        u"": mutagen.id3.Encoding.LATIN1,
                        u"foo": mutagen.id3.Encoding.LATIN1,
                        u"\u0185": mutagen.id3.Encoding.UTF16,
                    })
            finally:
                self._delete_test()
Ejemplo n.º 2
0
def mediafile_image(image_path, maxwidth=None):
    """Return a `mediafile.Image` object for the path.
    """

    with open(syspath(image_path), 'rb') as f:
        data = f.read()
    return mediafile.Image(data, type=mediafile.ImageType.front)
Ejemplo n.º 3
0
def _embed(image_path, audio_paths, maxwidth=0):
    """Embed an image file into each file audio file.
    """
    if maxwidth:
        image_path = ArtResizer.shared.resize(maxwidth, syspath(image_path))

    try:
        with open(syspath(image_path), 'rb') as f:
            data = f.read()
    except IOError as exc:
        log.error(u'embedart: could not read image file: {0}'.format(exc))
        return
    image = mediafile.Image(data, type=mediafile.ImageType.front)

    # Add art to each file.
    log.debug('Embedding album art.')

    for path in audio_paths:
        try:
            f = mediafile.MediaFile(syspath(path))
            f.images = [image]
            f.save(config['id3v23'].get(bool))
        except (OSError, IOError, mediafile.UnreadableFileError,
                mediafile.MutagenError) as exc:
            log.error('Could not embed art in {0}: {1}'.format(
                displayable_path(path), exc))
            continue
Ejemplo n.º 4
0
def _mediafile_image(image_path, maxwidth=None):
    """Return a `mediafile.Image` object for the path.

    If maxwidth is set the image is resized if necessary.
    """
    if maxwidth:
        image_path = ArtResizer.shared.resize(maxwidth, syspath(image_path))

    with open(syspath(image_path), 'rb') as f:
        data = f.read()
    return mediafile.Image(data, type=mediafile.ImageType.front)