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


Python File.tags['\xa9ART']方法代码示例

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


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

示例1: main

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import tags['\xa9ART'] [as 别名]

#.........这里部分代码省略.........
    outputs = []
    formatstr = unicode(args.format)
    escapepat = ""
    delimiter = ''
    for c in unicode(args.escape):
        esc = ''
        if c in r'()[]\^$.|?*+{}':
            esc = '\\'
        escapepat = escapepat + delimiter + esc + c
        delimiter = '|'
    to_escape = False
    if escapepat != '':
        to_escape = True
        escapepat = '(%s)' % escapepat
    separator = unicode(args.separator)

    def getinfo(file):
        try:
            return (file.info.bitrate / 1000, int(round(file.info.length)))
        except:
            return (0,0)

    for f in args.audiofile:
        path = unicode(os.path.realpath(f.decode('utf-8')))
        artist = title = album = year = wors = ""
        file = File(f)
        kbps, len = getinfo(file)
        try:
            if (type(file) == MP3):
                # add ID3 tag if it doesn't exist
                try:
                    file.add_tags()
                except:
                    pass
                # should we set the tag in anyway?
                if to_artist != '':
                    file.tags['TPE1'] = TPE1(encoding=3, text=to_artist)
                if to_album != '':
                    file.tags['TALB'] = TALB(encoding=3, text=to_album)
                if to_title != '':
                    file.tags['TIT2'] = TIT2(encoding=3, text=to_title)
                if to_wors != '':
                    file.tags['WORS'] = WORS(url=to_wors)
                if to_year != '':
                    file.tags['TDRL'] = TDRL(encoding=3, text=to_year)
                if to_cover != '':
                    #print('The image data is '+open(to_cover).read())
                    file.tags['APIC:'] = APIC(
                            encoding=3,
                            mime=to_cover_mime,
                            type=3,
                            data=open(to_cover).read()
                    )
                file.save()

                # process mp3 specific tag information
                artist = file.tags['TPE1'].text[0] if 'TPE1' in file.tags else ''
                album = file.tags['TALB'].text[0] if 'TALB' in file.tags else ''
                title = file.tags['TIT2'].text[0] if 'TIT2' in file.tags else ''
                wors = file.tags['WORS'].url if 'WORS' in file.tags else ''
                year = file.tags['TDRL'].text[0] if 'TDRL' in file.tags else ''
            elif (type(file) == MP4):
                # should we set the tag in anyway?
                if to_artist != '':
                    file.tags['\xa9ART'] = [to_artist]
                if to_album != '':
                    file.tags['\xa9alb'] = [to_album]
                if to_title != '':
                    file.tags['\xa9nam'] = [to_title]
                if to_year != '':
                    file.tags['\xa9day'] = [to_year]
                if to_cover != '':
                    file.tags['covr'] = [open(to_cover).read()]
                file.save()

                artist = file.tags['\xa9ART'][0] if '\xa9ART' in file.tags else ''
                album = file.tags['\xa9alb'][0] if '\xa9alb' in file.tags else ''
                title = file.tags['\xa9nam'][0] if '\xa9nam' in file.tags else ''
                year = file.tags['\xa9day'][0] if '\xa9day' in file.tags else ''
        except:
            pass


        reps = {u'artist':artist,
                u'title':title,
                u'album':album,
                u'year':year,
                u"kbps":kbps,
                u'wors':wors,
                u'len':len,
                u'path':path}
        if to_escape:
            for k in reps:
                reps[k] = re.sub(escapepat, r'\\\1', u"%s" % reps[k])

        if formatstr != '':
            outputs.append(formatstr.format(**reps))

    output = separator.join(outputs).encode('utf-8')
    print(output, end=u'')
开发者ID:lynnard,项目名称:mutagen-CLI,代码行数:104,代码来源:cli.py


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