Python Batch convert of FLAC files

纵饮孤独 提交于 2019-12-11 18:16:01

问题


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

This is what I ALREADY have.

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

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


回答1:


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


来源:https://stackoverflow.com/questions/7938128/python-batch-convert-of-flac-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!