#!/usr/bin/env python2.7 # -*- coding: iso-8859-1 -*- ''' Search a folder recursively for mp3-files and repair the header for every file. A backup of the original file is made. If you don't want this, decomment line 38. Usage: -r = Path to start the incremential search. ATTENTION: This script is written for use under linux ''' import os import argparse from glob import glob def repair(srcdir): #Make a list of all mp3-files in the current folder filelist = glob(srcdir + "/*.mp3") for i in filelist: #Make a copy of the file newName = i[:(len(i) - 4)] + "_alt" + i[(len(i) - 4):] os.system("mv '%s' '%s'" % (i, newName)) #Repair Header os.system("ffmpeg -i '%s' -c copy '%s'" % (newName, i)) #Clean up copy #os.system("rm %s" % newName) #list all folders in srcdir dirs = [name for name in os.listdir(srcdir) if os.path.isdir(os.path.join(srcdir, name))] #search recursivly into every subfolder if len(dirs) != 0: for i in dirs: newDir = srcdir + "/" + i repair(newDir) argp = argparse.ArgumentParser(description=__doc__) argp.add_argument( "-r", "--root", default=None, help="Folder to start the recursive search.") args = argp.parse_args() if args.root is None: print "Please provide a root folder. [-r (absoulte)]" else: repair(args.root)