Skip to content

Instantly share code, notes, and snippets.

@pyriand3r
Last active October 9, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyriand3r/d9824f8d2baa573835ee to your computer and use it in GitHub Desktop.
Save pyriand3r/d9824f8d2baa573835ee to your computer and use it in GitHub Desktop.
Searches a folder recursively for mp3-files and repairs the header for every file using ffmpeg. A backup of the original file is made. If you don't want this, decomment line 38. Usage: -r <Rootpath> = Path to start the incremential search. ATTENTION: This script is written for use under linux
#!/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 <Rootpath> = 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 <folderpath> (absoulte)]"
else:
repair(args.root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment