utility


20
Oct 08

FlixBot

I’ve built a proof of concept in some hacked together python code to automatically add movies to my netflix queue when I send twitter messages to @flixbot.

For example this tweet:

Gets Blade into my queue. Awesome.

I started building this out into a full fledged service so other people can use it as well. Of course I’m going to need a hosted site somewhere for people to sign up. I figured it might be a good time to play with my app engine account.

I got part of the way of there with app engine serving up pages, but then ran into problems with xml libraries I was using in my POC not existing in the AppEngine sandbox. :(

Also I’m starting to run out of enthusiasm.

So that’s where I’m at. Goodnight.


21
Jan 08

Duplicate music file finder code.

I’ve been consolidating my music collection and found that there were lots of duplicate files.

Most of the dupes were named something like “Happy Birthday 1.mp3″ and “Happy Birthday.mp3″ would exist in the same directory. I’m not sure which program added these dupes, but removing 2500 or so of em by hand would not be fun.

Without further ado, here’s some python code that takes care of that problem for you. It only examines the filename, not the date or the bitrate or the actual file contents, etc. But you could of course extend it to do all those things.

Enjoy.

#-------------------------------------------------------------------------------
# Name:        cleanDuplicateMusicFiles.py
# Purpose:     Loops over a directory structure looking for 'duplicate' music files
#				and moving them to a safe directory for deletion.
#
# Author:      Joshua Bloom
#
# Created:     01/18/2008
#-------------------------------------------------------------------------------
#!/usr/bin/env python
 
import os
import sys
 
dupList = []
rootDirectory = "/Users/joshbloom/Music/iTunes/iTunes Music"
sequesteredFilesDirectory = "/Users/joshbloom"
 
def main():
    print "Starting search ..."
    checkDir(rootDirectory)
    print "Found %s dupes" % len(dupList)
 
def checkDir(path):
    print "Checking path '%s' for duplicates" % os.path.basename(path)
    for item in [ os.path.join(path, x) for x in os.listdir(path) ]:
        if os.path.isdir(item):
            checkDir(item)
        else:
            checkForDupe(item)
 
def checkForDupe(fName):
	'''Example: if we find 'Happy Birthday 1.mp3' and 'Happy Birthday.mp3' exists in the
	same directory we consider this a duplicate and send it for re-education. '''
    fileName = os.path.basename(fName)
    folderList = os.listdir(os.path.dirname(fName))
    if fileName.endswith("1.mp3"):
        for otherName in folderList:
            if otherName != fileName: #Make sure we aren't comparing with the current file
                if os.path.basename (otherName).startswith(fileName[:-6]):
                    #This is a duplicate
                    dupList.append(fName)
                    sequesterDup(fName)
 
def sequesterDup(fName):
    ''' Move em to a new folder, if you were confident you could change
 		this function to delete the file. '''
    try:
        print "Moving file: %s" % fName
        os.rename(fName, os.path.join(sequesteredFilesDirectory, os.path.basename(fName)) )
    except Exception, E:
        print E
 
if __name__ == '__main__':
    main()

6
Jun 07

Convert m4a to mp3

I’ve been moving a bunch of my brothers music out of iTunes for him so he can use it with portable players besides iPod. Unfortunately he encoded a lot of his cd’s in .m4a format. I found a decent utility for converting to mp3 (and other formats) http://www.bonkenc.org/

Unfortunately when you point Bonk at a directory full of m4a’s it crashes on certain files for some reason (encoding issues probably.) After the crash you need to setup all of your settings and add the files again, which is really time consuming and annoying.

To make this easier I whipped up a short python script that calls Bonk for you on each file, if it runs into a bad file it will rename the file for you so you don’t try to process it again.

Here’s the python code:

import os
import pprint
import subprocess
curDir = os.getcwd() # The current directory. This should contain your .m4a files
pathToBonk = "C:\\Program Files\\BonkEnc\\becmd.exe" #Where the becmd.exe file lives
problemFiles = [] #A list of files that failed conversion
#
for item in os.listdir(curDir):
	if item.upper().endswith('.M4A'):
		fullPath = os.path.join(curDir,item)
		cmd = '"%s" -e LAME -d "%s" "%s"' #The command to convert a single file
		cmd = cmd % (pathToBonk, curDir, fullPath)
		val = subprocess.call(cmd)
		if val == 0: #Successfull conversion, delete the original
			os.remove(fullPath)
		else:
			problemFiles.append(fullPath)
			print 'Problem converting %s' % item
			os.rename(fullPath, fullPath + ".BAD")
print 'These files had problems converting and have been renamed with .BAD extensions:'
pprint.pprint(problemFiles)

NOTES: This will delete the .m4a file after converting it. If you want to keep your old files for some reason make sure to run this on a copy of your files. IE in a different directory.


26
Apr 07

Running multiple Firefoxi

I’ve been getting intermittent slowdowns and occasional lockups of my firefox browser. I suspect it’s from JS heavy pages/applications leaking memory somewhere but I wasn’t sure which pages to blame, and didn’t want to spend alot of time investigating.

Typically I have 3 different browser windows open each with their own batch of tabs:

  1. Personal browser including mail, calendar, rss feeds etc.
  2. Work Browser including work wiki’s, blogs, project management tools, documentation, java applets, applications, etc
  3. Utility browser which has blog posts to read, videos to watch, links emailed to me etc. Basically anything that doesn’t belong to the other two.

The problem with this setup is that instability on any of the browser windows affects them all, causing lost work or time reloading the relevant pages.

Luckily there’s a solution to this. Firefox has the concept of user profiles which were designed for multiple users on the same machine (family/shared computers etc). You need to create multiple profiles. To get the profile manager running run this from a command line:

"C:Program FilesMozilla Firefoxfirefox.exe" --profilemanager

Once the manager starts up you can create yourself a couple of different profiles.
Then create shortcuts for each of your profiles on your desktop that look like this:

Target = "C:Program FilesMozilla Firefoxfirefox.exe" --P Google -no-remote
Target = "C:Program FilesMozilla Firefoxfirefox.exe" --P Default -no-remote

Start FF with those shortcuts and you’ll have two completely separate windows. Now if one of the Windows is misbehaving you can kill it and not worry about the other one. Cool.

More info about the FF command line params can be found here.