Python批量转换FLAC文件 [英] Python Batch convert of FLAC files

查看:418
本文介绍了Python批量转换FLAC文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有FLAC文件转换为工作目录中的OGG:

I want to convert all FLAC files to OGG in the working directory:

这是我已经拥有的.

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()

Now I want to know how I can - in the directory containing my FLAC files - check if there is one .flac with a .cue and if that is the case do_something()

推荐答案

for flacfiles in flacs:
    if os.path.exists(os.path.splitext(flacfiles)[0] + '.cue')):
        # do something 

这篇关于Python批量转换FLAC文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆