【问题标题】:Python Batch convert of FLAC filesFLAC文件的Python批量转换
【发布时间】:2011-10-29 09:48:38
【问题描述】:

我想把工作目录下的所有FLAC文件都转成OGG:

这是我已经拥有的。

for root, dirs, files in os.walk(args):
        flacs = [f for f in files if f.endswith('.flac')]
        oggs = [o for o in files if o.endswith('.ogg')]

        for flacfiles in flacs:
            id3 = ('id3v2', '-C', flacfiles)
            cmd = ('oggenc', '-q7', flacfiles)
            try:
                subprocess.check_call(id3, cwd=root)
                subprocess.check_call(cmd, cwd=root)
            except subprocess.CalledProcessError:
                print "subprocess.CalledProcessError: Command %s returned non-zero exit status 1" % cwd

现在我想知道如何在包含我的 FLAC 文件的目录中检查是否有一个 .flac 和一个 .cue,如果是这样的话 do_something()

【问题讨论】:

  • 也可以考虑GNU Make。它是专门为解决此类任务而开发的。使用this Makefile,您可以检测已转换的文件、并行启动多个转换器进程的能力等等!

标签: python ogg os.walk flac


【解决方案1】:
for flacfiles in flacs:
    if os.path.exists(os.path.splitext(flacfiles)[0] + '.cue')):
        # do something 

【讨论】:

  • 得到一个:TypeError:强制转换为 Unicode:需要字符串或缓冲区,找到元组
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-02
  • 2013-04-15
  • 2017-08-22
  • 1970-01-01
相关资源
最近更新 更多