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


Python File.add_picture方法代码示例

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


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

示例1: split_item

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_picture [as 别名]
def split_item(item, DIGITAL_FOLDER=mp3_folder, DROPBOX_COPY=False):    
    logging.info('BLOOOAAARRRRGHHGGGGHHHHH!!! (Please hold...)')
    audio = wave.open(item.path)
    audio.params = audio.getparams()

    # Load AudioSegment for encoded segments
    if item.digital_ext is not 'wav':
        audio_segment = AudioSegment.from_wav(item.path)

    # Loop through cues and write regions (assumes start and end markers)
    for i, track in enumerate(item.tracks):
        # Build track filename
        digital_track_name = '{0} - {1} - {2}'.format(item.digital_file_name, str(i + 1), track.title)
        digital_track_name = ''.join([c for c in digital_track_name if c.isalpha() or c.isdigit() or c in "'- ._()[email protected]#$%^&*"]).rstrip('. ')
        digital_track_path = os.path.join(DIGITAL_FOLDER, digital_track_name) + '.' + item.digital_ext
        logging.info('Region {0} | {1} -> {2}'.format(i + 1, track.duration, digital_track_path))
        # Split, export track
        if 'wav' not in item.digital_ext:
            digital_track = audio_segment[(item.cues[i] / 44.1):(item.cues[i + 1] / 44.1)]
            tags = {'title':track.title, 'artist':item.artist, 'albumartist':item.artist, 'album':(item.album or item.artist), 'track':(i + 1)}
            digital_track.export(out_f=digital_track_path, format=item.digital_ext, bitrate='192k', tags=tags)
            # Add cover art
            if item.thumb and (item.digital_ext == 'mp3'):
                mutagen_audio = MP3(digital_track_path, ID3=ID3)
                try:
                    # Add ID3 tag if it doesn't exist
                    mutagen_audio.add_tags()
                except error:
                    pass
                mutagen_audio.tags.add(
                    APIC(
                        encoding=3, # 3 is for utf-8
                        mime='image/jpeg', # image/jpeg or image/png
                        type=3, # 3 is for the cover image
                        desc=u'Cover',
                        data=open(item.thumb_path, 'rb').read()
                    )
                )
                mutagen_audio.save()
            elif item.thumb and (item.digital_ext == 'flac'):
                mutagen_audio = File(digital_track_path)
                flac_image = Picture()
                flac_image.type = 3
                mime = 'image/jpeg'
                flac_image.desc = 'Cover'
                with open(item.thumb_path, 'rb') as f:
                    flac_image.data = f.read()
                mutagen_audio.add_picture(flac_image)
                mutagen_audio.save()
            else:
                logging.warning('No cover found for item {0}'.format(item.name))
        else:
            digital_track = wave.open(digital_track_path, 'w')
            digital_track.setparams(audio.params)  
            region_length = item.cues[i + 1] - item.cues[i]
            digital_track.writeframes(audio.readframes(region_length))
            digital_track.close()
        if DROPBOX_COPY:
            # Copy finished digital file to Dropbox order folder
            shutil.copy2(digital_track_path, item.dropbox_order_folder)
    audio.close()
开发者ID:broxeph,项目名称:ameryn,代码行数:63,代码来源:split-14+-+tweaks.py

示例2: split_item

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add_picture [as 别名]
def split_item(item, digital_folder=digital_folder, dropbox_move=True):
    logging.info("BLOOOAAARRRRGHHGGGGHHHHH!!! (Please hold...)")
    audio = wave.open(item.path)
    audio.params = audio.getparams()

    # Load AudioSegment for encoded segments
    if item.digital_ext is not "wav":
        audio_segment = AudioSegment.from_wav(item.path)

    # Loop through cues and write regions (assumes start and end markers)
    for i, track in enumerate(item.tracks):
        # Build track filename
        digital_track_name = "{0} - {1} - {2}".format(item.digital_file_name, str(i + 1), track.title)
        digital_track_name = "".join(
            [c for c in digital_track_name if c.isalpha() or c.isdigit() or c in "'- ._()[email protected]#$%^&*"]
        ).rstrip(". ")
        if dropbox_move:
            digital_track_path = os.path.join(item.dropbox_order_folder, digital_track_name) + "." + item.digital_ext
        else:
            digital_track_path = os.path.join(digital_folder, digital_track_name) + "." + item.digital_ext
        logging.info("Region {0} | {1} -> {2}".format(i + 1, track.duration, digital_track_path))
        # Split, export track
        if "wav" not in item.digital_ext:
            digital_track = audio_segment[(item.cues[i] / 44.1) : (item.cues[i + 1] / 44.1)]
            tags = {
                "title": track.title or "Track {0}".format(i + 1),
                "artist": item.artist,
                "albumartist": item.artist,
                "album": (item.album or item.artist),
                "track": (i + 1),
            }
            digital_track.export(
                out_f=digital_track_path, format=item.digital_ext, bitrate=item.bitrate, tags=tags, id3v2_version="3"
            )
            # Add cover art
            if item.thumb and (item.digital_ext == "mp3"):
                mutagen_audio = MP3(digital_track_path, ID3=ID3)
                try:
                    # Add ID3 tag if it doesn't exist
                    mutagen_audio.add_tags()
                except error:
                    pass
                mutagen_audio.tags.add(
                    APIC(
                        encoding=3,  # 3 is for utf-8
                        mime="image/jpeg",  # image/jpeg or image/png
                        type=3,  # 3 is for the cover image
                        desc=u"Cover",
                        data=open(item.thumb_path, "rb").read(),
                    )
                )
                mutagen_audio.save(v2_version=3)
            elif item.thumb and (item.digital_ext == "flac"):
                mutagen_audio = File(digital_track_path)
                flac_image = Picture()
                flac_image.type = 3
                mime = "image/jpeg"
                flac_image.desc = "Cover"
                with open(item.thumb_path, "rb") as f:
                    flac_image.data = f.read()
                mutagen_audio.add_picture(flac_image)
                mutagen_audio.save()
            else:
                logging.warning("No cover found for item {0}".format(item.name))
        else:
            digital_track = wave.open(digital_track_path, "w")
            digital_track.setparams(audio.params)
            region_length = item.cues[i + 1] - item.cues[i]
            digital_track.writeframes(audio.readframes(region_length))
            digital_track.close()
    audio.close()
开发者ID:broxeph,项目名称:ameryn,代码行数:73,代码来源:split-16+-+remove+bad+splits+from+Julius.py


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