当前位置: 首页>>代码示例>>Python>>正文


Python Picture.mime方法代码示例

本文整理汇总了Python中mutagen.flac.Picture.mime方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.mime方法的具体用法?Python Picture.mime怎么用?Python Picture.mime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagen.flac.Picture的用法示例。


在下文中一共展示了Picture.mime方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_image

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
    def set_image(self, image):
        """Replaces all embedded images by the passed image"""

        with translate_errors():
            audio = self.MutagenType(self["~filename"])

        try:
            data = image.read()
        except EnvironmentError as e:
            raise AudioFileError(e)

        pic = Picture()
        pic.data = data
        pic.type = APICType.COVER_FRONT
        pic.mime = image.mime_type
        pic.width = image.width
        pic.height = image.height
        pic.depth = image.color_depth

        audio.pop("coverart", None)
        audio.pop("coverartmime", None)
        audio["metadata_block_picture"] = base64.b64encode(
            pic.write()).decode("ascii")

        with translate_errors():
            audio.save()

        self.has_images = True
开发者ID:zsau,项目名称:quodlibet,代码行数:30,代码来源:xiph.py

示例2: _add_picture

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
 def _add_picture(self, mime, type_, desc, data):
     picture = Picture()
     picture.data = data
     picture.mime = mime
     picture.type = type_
     picture.desc = desc
     self._flac.add_picture(picture)
开发者ID:Iconoclasteinc,项目名称:tgit,代码行数:9,代码来源:flac_file.py

示例3: download_and_fix_ogg

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
def download_and_fix_ogg(ogg, audio_metadata, cover_art_file):
    global DRY_RUN
    if DRY_RUN:
        print "This is a dry run. So pretending to download the ogg..."
        return "/tmp/ogg"
    print "Now downloading the ogg in order to set the metadata in it..."
    if not LIVE and len(sys.argv) >= 6 and os.path.exists(sys.argv[5]):
        ogg_local_fn = sys.argv[5]
        print "(using presupplied file %s)" % ogg_local_fn
    else:
        f, metadata = client.get_file_and_metadata(ogg)
        ogg_local_fn = fetch_file(f, metadata)
    print "Successfully downloaded (to %s): now editing metadata..." % ogg_local_fn
    audio = OggVorbis(ogg_local_fn)
    for k in audio_metadata.keys():
        audio[k] = audio_metadata[k]
    # add cover art
    im=Image.open(cover_art_file)
    w,h=im.size
    p=Picture()
    imdata=open(cover_art_file,'rb').read()
    p.data=imdata
    p.type=3
    p.desc=''
    p.mime='image/jpeg';
    p.width=w; p.height=h
    p.depth=24
    dt=p.write(); 
    enc=base64.b64encode(dt).decode('ascii');
    audio['metadata_block_picture']=[enc];
    audio.save()
    print "Successfully updated metadata."
    return ogg_local_fn
开发者ID:stuartlangridge,项目名称:bv-publish,代码行数:35,代码来源:publish-public.py

示例4: set_art

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
 def set_art(self, art_file):
     art_tag = mutagen.File(self.path, None, False)
     if type(art_tag) is mutagen.mp3.MP3:
         with open(art_file, 'rb') as f:
             image = f.read()
         art_tag.tags.delall('APIC')
         art_tag.tags.add(APIC(
             encoding=3,  # 3 is for utf-8
             mime='image/jpg',  # image/jpeg or image/png
             type=3,  # 3 is for the cover image
             desc=u'Cover',
             data=image
             ))
         art_tag.save()
         print 'Wrote embedded MP3 art.'
     if type(art_tag) is mutagen.flac.FLAC:
         image = Picture()
         image.type = 3
         image.mime = 'image/jpg'
         image.desc = 'front cover'
         with open(art_file, 'rb') as f:
             image.data = f.read()
         art_tag.clear_pictures()
         art_tag.add_picture(image)
         art_tag.save()
         print 'Wrote embedded FLAC art'
开发者ID:robled,项目名称:formalizer,代码行数:28,代码来源:formalizer.py

示例5: handle_audio_file

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
def handle_audio_file(audio_file):
    print('Handling audio file', audio_file)
    extension = os.path.splitext(os.path.basename(audio_file))[1]
    if extension == '.mp3':
        mp3 = MP3(audio_file, ID3=ID3)
        print(list(dict(mp3).keys()))
        if not regex_list(dict(mp3).keys(), re.compile('[Aa][Pp][Ii][Cc].*')):
            artist = mp3['TPE1'][0]
            album = mp3['TALB'][0]
            cover_data = open(get_cover_art(artist, album, audio_file), mode='rb')
            apic = APIC()
            apic.encoding = 3
            apic.mime = 'image/jpg'
            apic.type = PictureType.COVER_FRONT
            apic.desc = u'Cover'
            apic.data = cover_data.read()
            cover_data.close()
            print('Adding cover art', cover_data.name, '->', audio_file)
            mp3['APIC'] = apic
            mp3.save()
        else:
            print(audio_file, 'already has cover artwork.')
    elif extension == '.m4a' or extension is '.aac':
        m4a = MP4(audio_file)
        print(list(dict(m4a).keys()))
        if 'covr' not in m4a:
            artist = m4a['\xa9ART'][0]
            album = m4a['\xa9alb'][0]
            cover_data = open(get_cover_art(artist, album, audio_file), mode='rb')
            covr = MP4Cover()
            covr.imageformat = AtomDataType.JPEG
            covr.data = cover_data.read()
            cover_data.close()
            print('Adding cover art', cover_data.name, '->', audio_file)
            m4a['covr'] = [covr]
            m4a.save()
        else:
            print(audio_file, 'already has cover artwork.')
    elif extension == '.flac':
        flac = FLAC(audio_file)
        print(list(dict(flac).keys()))
        if not flac.pictures:
            artist = flac['artist'][0]
            album = flac['album'][0]
            cover_data = open(get_cover_art(artist, album, audio_file), mode='rb')
            picture = Picture()
            picture.type = 3
            picture.mime = 'image/jpg'
            picture.desc = u'Cover'
            picture.data = cover_data.read()
            cover_data.close()
            print('Adding cover artwork', cover_data.name, '->', audio_file)
            flac.add_picture(picture)
            flac.save()
        else:
            print(audio_file, 'already has cover artwork.')
    move_or_overwrite(audio_file, dest_audio, os.path.join(dest_audio, os.path.basename(audio_file)))
开发者ID:maximberezin97,项目名称:AutoMoveFiles,代码行数:59,代码来源:AutoMoveFiles.py

示例6: embed_cover_art

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
    def embed_cover_art(self, audio_file, cover_file):
        """Embeds cover art into an audio file.

		Arguments:
			audio_file (str): The path to the audio file to embed the artwork in.
			cover_file (str): The path to the artwork file to embed.
		"""
        if path.isfile(audio_file) and path.isfile(cover_file):
            mimetype = "image/png" if cover_file.endswith("png") else "image/jpeg"
            artwork = open(cover_file, "rb").read()
            desc = u"Cover Art"

            # Determine which filetype we're handling
            if audio_file.endswith("m4a"):
                audio = MP4(audio_file)

                covr = []
                if cover_file.endswith("png"):
                    covr.append(MP4Cover(artwork, MP4Cover.FORMAT_PNG))
                else:
                    covr.append(MP4Cover(artwork, MP4Cover.FORMAT_JPEG))

                audio.tags["covr"] = covr
            elif audio_file.endswith("mp3"):
                audio = MP3(audio_file, ID3=ID3)

                # Add ID3 tags if they don't exist
                try:
                    audio.add_tags()
                except error:
                    pass

                audio.tags.add(
                    APIC(
                        encoding=3,  # 3 is UTF-8
                        mime=mimetype,
                        type=3,  # 3 is for cover artwork
                        desc=desc,
                        data=artwork,
                    )
                )
            elif audio_file.endswith("flac"):
                audio = FLAC(audio_file)

                image = Picture()
                image.type = 3  # 3 is for cover artwork
                image.mime = mimetype
                image.desc = desc
                image.data = artwork

                audio.clear_pictures()  # Clear existing pictures
                audio.add_picture(image)

                # Save the audio file
        audio.save()
开发者ID:nejsan,项目名称:sound_bubble,代码行数:57,代码来源:musicgen.py

示例7: __setattr__

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
 def __setattr__(self, attr, value):
     if attr in self.VALID_TAG_KEYS:
         if isinstance(value, Artwork):
             picture = Picture()
             picture.type = 3
             picture.mime = value.mime
             picture.data = value.data
             self.audio.clear_pictures()
             self.audio.add_picture(picture)
         elif isinstance(value, str):
             self.audio[attr] = [value]
         else:
             raise TagValueError(value)
     else:
         object.__setattr__(self, attr, value)
开发者ID:alexesprit,项目名称:audiotool,代码行数:17,代码来源:tag.py

示例8: _set_tag

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
 def _set_tag(self, raw, tag, value):
     if tag == 'metadata_block_picture':
         new_value = []
         for v in value:
             picture = Picture()
             picture.type = v.type
             picture.desc = v.desc
             picture.mime = v.mime
             picture.data = v.data
             new_value.append(base64.b64encode(picture.write()))
         value = new_value
     else:
         # vorbis has text based attributes, so convert everything to unicode
         value = [xl.unicode.to_unicode(v) for v in value]
     CaseInsensitveBaseFormat._set_tag(self, raw, tag, value)
开发者ID:exaile,项目名称:exaile,代码行数:17,代码来源:ogg.py

示例9: get_cover_picture

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
    def get_cover_picture(self, cover):
        """ Returns mutage Picture class for the cover image
        Usefull for OGG and FLAC format

        Picture type = cover image
        see http://flac.sourceforge.net/documentation_tools_flac.html#encoding_options
        """
        f = file(cover)
        p = Picture()
        p.type = 3
        p.data = f.read()
        p.mime = mimetypes.guess_type(cover)[0]
        f.close()

        return p
开发者ID:skysign,项目名称:gpodder,代码行数:17,代码来源:tagging.py

示例10: _set_tag

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
    def _set_tag(self, raw, tag, value):
        if tag == '__cover':
            raw.clear_pictures()
            for v in value:
                picture = Picture()
                picture.type = v.type
                picture.desc = v.desc
                picture.mime = v.mime
                picture.data = v.data
                raw.add_picture(picture)
            return

        # flac has text based attributes, so convert everything to unicode
        value = [xl.unicode.to_unicode(v) for v in value]
        CaseInsensitveBaseFormat._set_tag(self, raw, tag, value)
开发者ID:exaile,项目名称:exaile,代码行数:17,代码来源:flac.py

示例11: ogg_coverart

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
def ogg_coverart(config):
    print("Adding " + config.coverart_mime +  " cover art to " + config.ogg_file)
    coverart = config.coverart
    imgdata = open(coverart,'rb').read()

    im = Image.open(coverart)
    w,h = im.size

    p = Picture()
    p.data = imgdata
    p.type = 3
    p.desc = 'Cover'
    p.mime = config.coverart_mime
    p.width = w
    p.height = h
    p.depth = 24
    dt=p.write()
    enc=base64.b64encode(dt).decode('ascii')

    audio = OggVorbis(config.ogg_file)
    audio['metadata_block_picture']=[enc]
    audio.save()
开发者ID:rikai,项目名称:podpublish,代码行数:24,代码来源:encoder.py

示例12: set_image

# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import mime [as 别名]
    def set_image(self, image):
        """Replaces all embedded images by the passed image"""

        try:
            audio = self.MutagenType(self["~filename"])
            data = image.file.read()
        except EnvironmentError:
            return

        pic = Picture()
        pic.data = data
        pic.type = APICType.COVER_FRONT
        pic.mime = image.mime_type
        pic.width = image.width
        pic.height = image.height
        pic.depth = image.color_depth

        audio.pop("coverart", None)
        audio.pop("coverartmime", None)
        audio["metadata_block_picture"] = base64.b64encode(pic.write())
        audio.save()

        self.has_images = True
开发者ID:vrasidas,项目名称:quodlibet,代码行数:25,代码来源:xiph.py


注:本文中的mutagen.flac.Picture.mime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。