!/usr/bin/env python

Convert a whole directory tree of flac files to oggs

Just a wrapper on a couple of system commands

Could be made more 'pythonic' by replacing find with os.walk

Public Domain: copy, redistribute, reuse freely and without restriction

import os import shutil import commands

base directory for flac files

srcPath = '/var/share/music'

destination directory for ogg files

destPath = '/var/share/ogg'

cmds = [ "find . -type d -exec mkdir %s/'{}' \;" % destPath, "find . -name '.flac' -exec oggenc --quiet --quality 4 '{}' \;", "find . -name '.ogg' -exec mv '{}' %s/'{}' \;" % destPath, ]

def run_cmd(cmd): status, output = commands.getstatusoutput(cmd) if status: print 'Had error running [%s]: %s' % (cmd, output)

def convert_to_ogg(clean=True): if clean: shutil.rmtree(destPath) if not os.path.exists(destPath): os.makedirs(destPath) os.chdir(srcPath) for cmd in cmds: run_cmd(cmd)

if name == 'main': convert_to_ogg()

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>