本文整理汇总了Python中mutagen.File.has_key方法的典型用法代码示例。如果您正苦于以下问题:Python File.has_key方法的具体用法?Python File.has_key怎么用?Python File.has_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.File
的用法示例。
在下文中一共展示了File.has_key方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_files
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import has_key [as 别名]
def process_files(path, stats):
"""
Recurse down directory path and process each audio file.
"""
counter = 0
for root, dirs, files in os.walk(path):
for f in files:
# We maintain a counter to keep file names unique
counter += 1
stats.files_read += 1
filename = os.path.join(root, f)
try:
audio = File(filename, easy=True)
except Exception, e:
stats.add_type_failure(filename)
continue
if not audio:
stats.add_parse_failure(filename)
continue
test_tags = ['artist', 'album', 'title']
missing_tags = []
for tag in test_tags:
if not audio.has_key(tag):
missing_tags.append(tag)
tracknumber = audio.get('tracknumber', [None])[0]
artist = sanitize_path(audio.get('artist', ['No Artist'])[0])
album = sanitize_path(audio.get('album', ['No Album'])[0])
title = sanitize_path(audio.get('title', ["%d_%s" % (counter, f)])[0])
if tracknumber:
try:
tracknumber = int(re.sub(r'.*?(\d+).*', r'\1', tracknumber))
except ValueError, e:
tracknumber = None
pass
(_, extension) = os.path.splitext(filename)
if not tracknumber:
newname = os.path.join(artist, album, title + extension)
else:
newname = os.path.join(
artist, album, "%02d - %s%s" % (tracknumber, title, extension))
if len(missing_tags) > 0:
pretty_missing_tags = str.join(", ", missing_tags)
stats.add_missing_tag_failure(
filename + ": " + pretty_missing_tags,
newname)
stats.add_track(filename, newname, artist, album, tracknumber, title)