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.

No comments:

Post a Comment