简体   繁体   中英

Python Batch convert of FLAC files

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM