Monday, September 28, 2009

Demo Video Recorded for YouTube

I recorded a video of the iTunes DSM in action. I'm planning on posting it to YouTube to show how to use the program. In my testing, the program seems to be solid and ready for use.

I did use iTunes DSM on my own personal library finally and am pleased with the result. It's also convenient in that you can use the program on the other computers in the house and fix the orphaned files in the iTunes databases!

When I post the YouTube video I'll post it on here as well. I am still trying to figure out if I can host the program here on blogspot. I haven't really seen a way to do it yet.


Sunday, September 27, 2009

iTunes functionality in place.....for Windows

Using the previously mentioned components that I added, iTunes Duplicate Song Manager, can now locate orphaned files (those that have exclamation marks next to the song in iTunes) and remove those tracks. You can see the option added just above the clean music folder button.

The user can also just run the program and just clean the orphaned files, without having to scan for duplicates, so that's nice. The program also makes sure that the host operating system is Windows based, if not, the orphan file option is greyed out.

Finally, I've added a couple more links under the help menu.

I'm still wanting to add the orphaned files remove option to Mac but not really sure how to go about AppleScripts, so I'm sure that will be later. The program itself was having trouble running in Mac under java and I wasn't sure why at first. The SwingWorker package wasn't being found, turns out that Mac Leopard was using JRE 1.5 instead of the required 1.6, so if anyone else has problems using SwingWorker in OS X look for the Java Preferences application in Finder and edit the options in there.

In other news, my research paper is 4000 words, so that's nice too. Hope everyone had a good weekend.


Friday, September 25, 2009

iTunes functionality on the way

I know I haven't posted the project yet for download, and that's because I've been messing around with JACOB, Jacobgen, and the iTunes' COM. JACOB provides a way for the java virtual machine to interact with COM objects. This isn't really a java thing and so adding this functionality via JACBO brings java up to the likes of other development environments. You can find the JACOB project here...

it works for both windows 32 and 64 bit environments which is cool. Also on the sourceforge project page is jacobgen, which automatically creates .java files for the COM objects. So everything that the iTunes com offers, jacobgen will create java files with the corresponding methods to interact with it. Very Cool!!! I had some trouble getting it to work for a long time. There is an example batch file included in jacobgen that I had to edit.

Here is the batch file code I used to run jacobgen...

@echo off

REM run this from the root directory of the Jacobgen project
REM it will spit out the interface classes for a dll you pass in as a parameter
REM sample command line while sitting in the JACOBGEN project directory
REM The following command built a sample in the jacob directory I have
REM installed near my jacobgen project directory.
REM $ docs/run_jacobgen.bat -destdir:"..\jacob\samples" -listfile:"jacobgenlog.txt" "C:\Program Files\Microsoft Office\OFFICE11\MSWORD.OLB"
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_16
set JRE=%JAVA_HOME%\bin

set CLASSPATH=%CLASSPATH%;%JAVA_HOME%\lib\dt.jar;%JACOBGEN_HOME%\jacobgen.jar;%JACOBGEN_HOME%\lib\viztool.jar
REM put the dll in the path where we can find it

@echo on

echo %1
echo %2
echo %3
echo %4
echo %5

rem %JRE% -Xint com.jacob.jacobgen.Jacobgen %1 %2 %3 %4 %5

java -Xint com.jacob.jacobgen.Jacobgen %1 %2 %3 %4 %5


REM run.bat -destdir:"c:\jacob\itunes" -listfile:"jacobgenlog.txt" "C:\Program Files (x86)\itunes\itunes.exe"

To use the batch file. Open a command prompt and change directories until you get to the jacobgen directory. Place the batch file in the root jacobgen directory. Copy and paste the last line minus the letters REM into the command line and press enter. Jacobgen will place the created java files in the destdir. The main difference between my batch file and the example one is I use the java command.

Of course in the end, I didn't use the generated code. There is no documentation created with it obviously, and all kinds of errors were thrown in Netbeans. Instead, I downloaded this package and in conjunction with JACOB, I can now control iTunes. I already have my program identifying the audio file in the iTunes library that correspond to the duplicate files found when searching for files with iteration counts appended to the end, so in conjunction with deleting the actual files, I should now be able to remove them from the iTunes library.

My next idea is since I share music throughout my home network, deleting files from the folder from one computer's library will not be reflected in other iTunes libraries until a user tries to play a song that is removed and therefore orphaned. In essence I'm going to try to add an option that will locate orphaned files, even if they are not apparent to the user.

Tuesday, September 22, 2009

iTunes 9 and an Algorithm Update

I've been using iTunes 9 since it came out and recently I've been trying to get it to create duplicates like the previous versions did. It seems at least that iTunes is much smarter about songs that are already in your library and basically seem to stop duplicates from happening; however, I did find that songs you place in the "Automatically add to iTunes" folder will create duplicates if the song is already present. I'm not sure if that is by design or not, but in the end iTunes seems to be better at preventing duplicates from occurring.

What about duplicates that were already present?
iTunes doesn't do anything for those, it still treats previous duplicates as seperate songs and so are added to the library. So for me, the 220 or so actual duplicate songs that were already in my library are still there.

I also made an obvious change to the search algorithm. The algorithm used to scan every file in all the folders of a parent directory adding each one to an ArrayList, then duplicates would be found by comparing each file to every single file in the list. This was a long process and required a lot of computer resources. Instead, the algorithm still scans each directory under a parent directory, but gets the list of files only in one folder compares those files for duplicates, and then moves on to the next folder and checks that one folder for duplicates. This has the advantage of finding duplicates as the folders are searched rather than reading every directory first and then comparing every single file to each other. This works because as iTunes keeps folders organized, there is no way that duplicate song will end up anywhere but in the same folder as the original.

I'm still planning on releasing the program here real soon. I have decided that it will be free. I have placed a button for donations on the program and on this blog, if you are feeling generous, I could use a cup of coffee every now and then! I will also post a video on youtube on how to use the program. I'm hoping to do this this week.


Sunday, September 20, 2009

Bug fixing

I've been updating the program more this weekend. There were a few sizable bugs I found. One of the major ones occurred when the user didn't select every song to be cleaned, rather a few of the songs. Instead of deleting the selected songs, the program would delete the number of selected songs starting from the top of the list. For example, if I picked three songs sprinkled throughout the list, the program would delete three songs starting from the top. In the end it was a minor fix and that portion is working correctly.

I've come across the Swing Worker class in Java. Swing Worker provides a way to utilize threads in the background so that the main gui thread is not bogged down with operations not directly related to the gui. In essence, the program appears to run much faster and smoother. Also a part of the Swing Worker class, the user can now cancel functions and more easily restart searches.

I have also tweaked the algorithm that finds duplicate songs. I still have artist, title, and album matching turned off as it greatly increases the computations. The program does still search filenames that end in iterations though.

Warning messages now appear if selections haven't been made and there are a couple title menu options as well namely, exit and about.

I have named this version currently version .1. I'm not really sure to version conventions, though I know v1, v2, etc are full released versions and everything in between usually refer to minor releases or bug fixes. Basically, I picked an arbitrary number and went from there.

I included a few screenshots, notice the cancel button and the title menus.

What's Next?
I'm looking into logging, to keep a record of what happens. Also a major convience to the program would be to not only remove the file itself but also remove the song from the itunes library, but that's a ways off, as communicating through com's in windows isn't really java's thing. As of now, to the have the library updated, the user has to delete the songs from the library(not from the hard drive) and then reimport the songs, so that iTunes knows exactly what is in the folders. That's all to come and until then...toodles.


Wednesday, September 16, 2009

GUI Update Again

Had some time to work on the iTunes duplicate song manager program today "betwixt" the paper and other homework. It is now much easier to actually see that the program is doing something while its processing in the background. The screenshot above shows the added progress bar and the current file or directory the program is scanning. Still not quite ready for an alpha release or anything but it's getting there.

Tuesday, September 15, 2009

GUI update

I've been working frantically on the program the last two days because I have to start writing the paper here soon and I felt I needed a working program in order to start on the paper. Enjoy!

It's important to note that while I have the functionality built into it, I have it disabled at the time, but the program identifies duplicates by filename only. If you want to be sure that a song's and duplicate's title, artist, album, etc are the same, for now it must be checked by hand. Also the eagle-eyed of you may notice some missing icons on the file dialog box, this appears to be a bug with Java and Windows 7 as it occurs in netbeans and other java projects I've worked on.

I'm planning on releasing this for free. I might add a paypal donation thingy, but I'm not really worried about it at the time. Look for more updates later.


Monday, September 14, 2009

What's working so far

I had to work double time over the weekend to catch up on my project to meet some deadlines, but here is what is working so far.

Using Java, I am able to traverse all the subdirectories and files of a parent directory recursively, and filter out a subset of those files. For example the directory c:\music may have 100 directories and 5000 songs within them. The program can filter any type of file, which is usually mp3 in my testing, but it can also filter other audio files.

Once the program has found all of the files within all subdirectories, it attempts to find files that have an iteration count appended to the end of the filename. For example, Aerosmith's Dream On will be placed in the folder ..Aerosmith/Aerosmith's Greatest Hits/01 Dream On.mp3. The file is stored like this because iTunes keeps my library folders and files organized.

However, if I accidently add another copy of Dream On to my library, then iTunes will store the file 01 Dream On 1.mp3. iTunes has appended the iteration 1 to the end of the file. I am taking advantage of the appended number to help find duplicated files in the subdirectories.

There is a problem with searching for just numbers on the end of the filename, however; Suppose the name of the song is "You are the 1", iTunes will store this file as ../Artist/Album/01 You are the 1.mp3 and now the song has a number on the end of the filename that is not an iteration count. The trick is to remove the last two characters of the filename and check to see if that file exists and if it is in the list of files that were found within all of the subdirectories.

So far my program is able to accomplish both of these requirements. The program finds all the duplicates that have iteration counts from 1 to 9 and checks to make sure that the number at the end of the filename is truly an iteration count.

The screenshot is an output taken by my program that lists a portion of the duplicates in the library. You can see that a family of four, all using the same music directory, has added quite a few duplicate songs over the years!

What is the iTunes Duplicate Song Manager

I like for iTunes to keep my music library organized. There's an option in the iTunes preferences for that. There is also an option to automatically copy any song that is dragged into the library to the directory where you store your files.

I have one directory on a server that is shared throughout my house and that folder is the default folder for iTunes to store music on. For example, the address of the music folder is //server/music/all the folders where all the folders is what iTunes keeps organized. Problems arise when users add a song to their library that is already present, or they accidently buy a song we already have, or they've reinstalled itunes and accidently copy songs over and over as itunes rebuilds the library.

Fortunately their are a couple of iTunes conventions that I am taking advantage of to try and automate the process of removing duplicate songs from the music folder.

The Goal of iTunes Duplicate Song Manager:
To create an automated process to automatically remove duplicated song files from the iTunes library folder and safely move them to a backup folder. This program will be written in Java to facilitate both Windows and Macs.

This project is also being used to help fulfill requirements in my Software Engineering masters program I am taking at the University of West Florida. The program caters to those who already work full time and allows students to finish their masters within 1 year. I have a similar project going on for another requirement at another blog as well.