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


Python File.has_key方法代码示例

本文整理汇总了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)
开发者ID:0xfe,项目名称:mp3renamer,代码行数:58,代码来源:mp3renamer.py


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