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()
Posted in Code, Technical, python, snippet, utility | No Comments »
Since my dogs ate my last couch, I needed a solution to make sure they didn’t eat the new one. A quick install of Skype and a cheap webcam in the living room now allow me to check in on them and if I see any couch eating I can yell at them to stop. The sound is piped through the home theater system left at an appropriately loud volume.

Here they are doing what they do best, sleeping.
The trick to this setup is to just leave Skype set to auto answer in video mode.
Posted in asides | No Comments »
Using Xray you can utilize logging in your AS3 development in a nice clean manner. One of the great benefits here is that your logging/debugging process can be the same when developing locally and when you are running on your development and production servers.
To get started download the latest xray code from their SVN repository.
http://code.google.com/p/osflash-xray/source
Then create a new AS3 flash document using the code below as the document class:
Make sure that you add the ‘trunk’ directory that you downloaded to your class path (so flash can find the xray files)
Once you are compiling correctly, launch the xray viewer in a browser from http://www.rockonflash.com/xray/flex/Xray.html. You will get a notification about not finding a SWF to connect with, ignore this for now (full xray support is not yet therefor AS3 projects). Make sure that the Show Output checkbox along the bottom is checked.
Now if you click the red square in your swf player, you should see the following show up in the XRay viewer windows.
Congratulations you are now logging. Big thanks to John Grden and everyone else contributing to Flash development methodologies.

package {
import com.blitzagency.xray.logger.XrayLog;
import flash.display.*;
import flash.events.*;
public class testLoggingAS extends MovieClip {
private var log:XrayLog = new XrayLog();
private var mc:MovieClip
public function testLoggingAS() {
log.debug("Application starting up");
createClickableMovieClip()
log.debug("Application has completed startup");
}
private function showTheClick(e:Event):void {
log.debug("Square was clicked. Tracing out the Event", [e]);
}
private function createClickableMovieClip():void {
mc = new MovieClip();
mc.name = "ClickableMovieClip"
mc.graphics.beginFill(0xFF0000);
mc.graphics.drawRect(0, 0, 100, 80);
mc.graphics.endFill();
mc.x = 80;
mc.y = 60;
addChild(mc);
mc.addEventListener(MouseEvent.CLICK, showTheClick)
}
}
}
Posted in AS3, Code, flash, xray | 3 Comments »
Check out Julie Campagna of Adobe interview Cary and I at the Adobe MAX2007 conference.
link to Adobe’s site
Posted in AIR, MAX2007, interview | No Comments »
The AIR Application that I built for Disney and presented at Adobe’s MAX2007 conference was quite a hit. I was interviewed about it by Martin LaMonica from Cnet. Read his full coverage at www.news.com:8301-10784_3-9789007-7.html

Or you can see just the important part where he quotes me
That covers a lot of what a developer needs to build applications, said Josh Bloom, a design technologist at Frog Design, which helped design and write the Disney travel application.
In this case, he picked Flex Builder, Adobe’s development tool, to write the application and used Flash as well. Frog Design takes advantage of Microsoft user interface tools, which he said are more complete.
“You can be a full Web developer and have access to the desktop (with AIR) which you didn’t have access to before,” Bloom said.
Posted in AIR, Personal | 1 Comment »
I’m going to be at the Adobe MAX conference in Chicago for the next few days.
If you’re attending and want to say hi, stop by the Monday night Birds of a Feather session where I will be showing off an AIR application I built for Disney Travel Agents.
The session is at 8:30 and is titled “frog design presents a Disney desktop travel application”
If you don’t catch me there, you can probably find me at the Halo3 booth, or possibly the hotel bar
-Josh
Posted in AIR | No Comments »
When developing AIR applications under flexbuilder you may get a situation where the app is stuck in an unresponsive state and refuses to quit itself.
To kill it quickly on a Mac you can do the following from a terminal:
ps -A | grep adl
That will return a line that looks something like this
18132 ?? S 0:22.97 /Users/joshbloom/Applications/flexb_183522/Adobe Flex Builder 3/sdks/3.0.0/bin/adl -runtime /Users/joshbloom/Appl
18148 p1 S+ 0:00.00 grep adl
The number at the beginning of the first line first line indicates the process ID of your unresponsive AIR app.
To kill it you would run this command:
kill -9 18132
Be careful what number you put into the kill command, it will happily kill anything you tell it to. If you make a mistake you may have killed your window manager, your instant messenger or even something important like your twitter client.
Posted in AIR, command line, osx | No Comments »
My friend Sean says it best here
To Recap:
If you want to know what’s going on with me, it’s best to follow this link: My Twitter Stream.
Posted in asides, twitter | No Comments »
So I’ve spent a little more time thinking about this and have decided this utility would be better as a server utility that sits out in the cloud and monitors for my computer activity. If it doesn’t see activity for some set period it notifies twitter to re-enable SMS messages.
This takes care of any issues with me shutting down or closing my laptop/computer before my notifier can get its message out.
I’m thinking a python script, called by cron that checks for an indication that I’m active on my computer, if it doesn’t see the indication after some number of tries it turns SMS notifications on. That part seems pretty solid, what should I use on the laptop to signal my presence? If this was a Windows machine I’d be off and running but I’ve recently switched to a Mac and I don’t know the platform very well. Instant messenger sounds like something to tap into as it already has the concept of active/idle built into it, but I’m using Adium and it seems like Adium plug-ins are written in Objective-C which is totally foreign to me.
I think it’s time for some googling…
Posted in Technical, python, twitter | No Comments »
I just started twittering and have found that getting alerts on my phone is great, just not when I’m also at the computer.
So being a good geek I thought I’d automate the process of turning mobile alerts on or off based on my laptop status.
So far I’ve scraped the HTTP headers and post variables so I know how to login and turn updates on or off. Next I need to package up a small utility to automatically decide when to send the commands.
Posted in Code, Technical, Web, twitter | No Comments »