Its inspired by the Limewire program source. The code is open source and written in Java and therefore much of the iTunes code is now based on that code. Here's the code I'm using to remove orphaned tracks. First you need the iTunes Jar file from limewire. You can download the source and it's included in the folder: limewire/lib/jars/windows
Then use this code..
ActiveXComponent iTunesCom = new ActiveXComponent(ItunesMediator.ITUNES_ACTIVEX_NAME);
Dispatch iTunesController = iTunesCom.getObject();
IiTunes it = new IiTunes(iTunesController);
IITLibraryPlaylist pl = it.getLibraryPlaylist();
IITTrackCollection coll = pl.getTracks();
ArrayList orphanedFiles = new ArrayList();
int count = coll.getCount();
for(int i=1; i<=count; i++){ if(mon.isCanceled()){ break; } IITTrack track = coll.getItem(i); if(track.getKind() == ITTrackKind.ITTrackKindFile){ IITFileOrCDTrack file = new IITFileOrCDTrack(track); if(file != null && file.getLocation().equals("")){ orphanedFiles.add(file); } } mon.setProgress( (int)(((double)i / (double)count) * 50) ); }
No messy QueryInterface method stuff. Since there was no JavaDoc on the iTunes jar and the jar itself is a Jar, it took forever before I just tried this. But it works. Hope this helps anyone else looking for info on this.
Brian
No comments:
Post a Comment