Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Other Topics > Computer Technical Help
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2007, 01:24 AM
LuckOfTheDraw LuckOfTheDraw is offline
Senior Member
 
Join Date: Jun 2006
Location: tonight... you.
Posts: 1,491
Default Need help javascripting for iTunes

First of all, I'm trying to find a script that will create a playlist for each album I have on my iPod.

I've read somewhere that there is a sample script provided in the iTunes Windows COM SDK that will do this for the songs in my main library. Unfortunately, I can't seem to find the SDK. It appears apple doesn't offer it any longer on its website.

I figure I could write my own script, however, I don't know how to tell it to access the iPod library opposed to the main library. Here's some sample script I found, which works, to clarify what I'm talking about.


/* Rename me to NoArtPlaylist.js
Double Click in Explorer to run

Script by Otto - http://ottodestruct.com */

var iTunesApp = WScript.CreateObject("iTunes.Application");
var tracks = iTunesApp.LibraryPlaylist.Tracks;
var numTracks = tracks.Count;
var i;
NoArtPlaylist = iTunesApp.CreatePlaylist("No Artwork");

for (i = 1; i <= numTracks; i++)
{
var currTrack = tracks.Item(i);
if ( currTrack.Artwork.Count == 0 )
NoArtPlaylist.AddTrack(currTrack);
}


This would create a playlist in iTunes for all of the songs that don't have artwork. Pretty useless, but that's not the point. See the line "var tracks = iTunesApp.LibraryPlaylist.Tracks;"? This creates a list of all of the tracks in my main iTunes library. Does anyone know what I would use instead of "LibraryPlaylist" to load the list from my iPod library? I've tried guessing a few, but they all cause a null object error.

Any and all help would be appreciated.

Edit: In the meantime, I'm going to write the script for to work with my main library playlist.
Reply With Quote
  #2  
Old 04-12-2007, 02:53 AM
LuckOfTheDraw LuckOfTheDraw is offline
Senior Member
 
Join Date: Jun 2006
Location: tonight... you.
Posts: 1,491
Default Re: Need help javascripting for iTunes

I found a solution. I can highlight the songs I want to do whatever to, and it doesn't matter where the songs are (on my computer or iPod or whatever).
Reply With Quote
  #3  
Old 04-12-2007, 05:42 AM
LuckOfTheDraw LuckOfTheDraw is offline
Senior Member
 
Join Date: Jun 2006
Location: tonight... you.
Posts: 1,491
Default Re: Need help javascripting for iTunes

Well, I finally got it to work. Since I couldn't find the SDK, I had to wade my way through the references in a MS Visual C# compiler I got a while back. I'm retarded and it took me entirely too long to find a way to reference the iPod as the source, but I'm rusty even when it comes to easiest of "programming".

Anyways, if anyone wants it, here it is. Just save it as a .js file in notepad and double click it. If you're wondering why I went through the trouble, I just got a new radio for my car and it has a built in iPod dock (not just a front aux input). So, the deck actually controls how I search through songs. Unfortunately, it doesn't really do a good job of it. It searches either by playlist, artist OR album, but wont let you go to an artist and then search through that artist's albums. It's a real pain the ass. If you've selected a certain artist and you tell it to start searching through albums, it just starts over at the first album overall, alhpabetically. Now I have a separate playlist for each album, and I'll search through by playlist.

One final note. It's late and I'm lazy, so I'm not going to fix it, but I just realized that it may screw up if you have any files with no information under the artist tag. Not sure, but probably will error.

Oh yeah. And, to use it, obviously have the songs selected first.



var iTunesApp = WScript.CreateObject("iTunes.Application");

var tracks = iTunesApp.SelectedTracks;

if (!tracks)
{
WScript.Echo("You did not select any songs. Javascript ended.")
}
else
{

var source = tracks.Item(1).Playlist.Source;

var numTracks = tracks.Count;

var i;


var albumArray = new Array();

for (i = 1; i <= numTracks; i++)
{
var currTrack = tracks.Item(i);
var artist = currTrack.Artist;
var album = currTrack.Album;

if ((album != undefined) && (album != ""))
{
if (albumArray[artist + " - " + album] == undefined)
{

albumArray[artist + " - " + album] = new Array();
}

albumArray[artist + " - " + album].push(currTrack);


}
}

for (var albumName in albumArray)
{
var trackArray = albumArray[albumName];
albumPlaylist = iTunesApp.CreatePlaylistInSource(albumName, source);

for (var x = 0; x < trackArray.length; x++)
{
var currTrack = trackArray[x];
albumPlaylist.AddTrack(currTrack);
}
}
}
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:59 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.