本文整理汇总了Python中mutagen.File.tags['\xa9alb']方法的典型用法代码示例。如果您正苦于以下问题:Python File.tags['\xa9alb']方法的具体用法?Python File.tags['\xa9alb']怎么用?Python File.tags['\xa9alb']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.File
的用法示例。
在下文中一共展示了File.tags['\xa9alb']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import tags['\xa9alb'] [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'')