Home > Experiments, python, Uncategorized > Python Script to fix VBR errors of mp3 files in a directory, recursively

Python Script to fix VBR errors of mp3 files in a directory, recursively

If the seek bar of your rhythmbox is not working with some mp3 files, it might be an issue with Variable Bit Rate of them. The tool, ‘vbrfix’ written by William Pye solves the issue, but the problem is that it doesn’t have an option to search for files recursively. Here is a small python script that gets the paths of multiple mp3 files recursively and give them as arguments to vbrfix tool. Make sure you install vbrfix (from the software repo) before running the script.

Please see comments for a better, 1 line substitute to do the same. Thanks to Rajeesh ettan and Syam ettan 🙂

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#       vbrfixdir.py
#       Copyright 2011 Ershad K <ershad92@gmail.com>     
#       Usage: python vbrfixdir.py
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       GNU General Public License for more details.
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

import sys
import os

quote = '"'
folder = sys.argv[1]
find_command = "find " + folder
find_command += " > mp3files_list"

os.system("sed 1d mp3files_list > mp3files_list1");

f = open("mp3files_list1", 'r')
for line in f:
    line = line[:len(line)-1]
    command = "vbrfix -always "
    command += quote + line + quote
    command += " " + quote + line + quote
    print command

os.system("rm mp3files_list mp3files_list1")

Improvements to code and suggestions are always welcome, Happy Hacking 🙂

  1. February 19, 2011 at 9:01 pm

    Couldn’t resist, but…

    find $1 -name *.[Mm][Pp]3 -exec vbrfix -always {} \;


    • February 19, 2011 at 9:52 pm

      Awesome! vbrfix accepts two more arguments, in and out filenames. Both are same here, etta, how could we fix that too?

      • February 20, 2011 at 11:04 am

        find $1 -name *.[Mm][Pp]3 -exec vbrfix -always {} {} \;

        might work, I guess. In find command, “{}” is used in place of the found file.

        • February 20, 2011 at 12:59 pm

          Yes, it works!! One line substitute is really awesome.

  2. February 19, 2011 at 9:10 pm

    If you’re going to use the find command, then it already has a provision to execute another arbitrary program for each file it finds.

    For example:
    find -iname “*.mp3” -exec ls -l {} \;

    The above command will execute “ls -l” for each mp3 file it finds (and the search is recursive by default). Just go through the man page of find and checkout the -exec option. {} will be replaced by the filename.

    I hope this will serve the purpose here.

    • February 19, 2011 at 9:55 pm

      This is new information to me. It’s really wonderful to solve this problem by a single command with arguments! How could we specify more arguments to the application that gets executed on finding mp3 file?

      • February 20, 2011 at 8:24 pm

        Just specify all arguments after the name of the command. In the example I posted, ‘-l’ was an argument to ‘ls’.

        • March 1, 2011 at 7:29 pm

          Ok. etta 🙂 Thanks a lot.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: