【问题标题】:How to use mutagen on a directory?如何在目录上使用诱变剂?
【发布时间】:2020-06-06 11:17:32
【问题描述】:
from mutagen.flac import FLAC
audio = FLAC("/file/path") 
audio["comment"] = "This is my comment"
audio.save()

如果我提供文件路径,我检查了它是否标记了 Flac 文件。但是如何在各自专辑名称文件夹中存在的所有文件上运行它呢?像递归一样?

我在提供目录路径时收到IsADirectory 错误。

我实际上不是编码员。如果有人能在这方面帮助我,那就太棒了。我一直在寻找相同的python cli程序,但找不到。

【问题讨论】:

    标签: python tagging flac mutagen


    【解决方案1】:

    所以我从字面上使用常识,复制粘贴和反复试验写下了我自己问题的答案。 或多或少对我有用。

    import os
    from mutagen.flac import FLAC
    
    for root, dirs, files in os.walk(os.path.abspath("/path/of/directory/")):
        for file in files:
          if file.endswith(".flac"):
            print(os.path.join(root, file))
            audio = FLAC(os.path.join(root, file))
            audio["comment"] = "This is my comment"
            audio.save()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 2017-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      相关资源
      最近更新 更多