This was harder than I thought.
I could not find an export command at all. Unfortunately getting the tracks from the podcast list automatically sorts everything oddly. I could not override that. So the best I can do is sort by release date.
Then you export the playlist. It looks in order to me. Just not sure it does what you want.
Save the code in the inset as podcastPlaylist.
js
Open iTunes, select the Podcasts you want to sort.
Open a command prompt where podcastPlaylist.
js is located.
Execute the command:
wscript podcastPlaylist.
js
Look for a Playlist named SortedPodcasts, drag to your thumb drive.
See it if works. If it still plays alphabetical we can alter the names too.
Code:
var iTunesApp = WScript.CreateObject("iTunes.Application");
var mainLibrary = iTunesApp.LibraryPlaylist;
var tracks = iTunesApp.SelectedTracks;
var numTracks = tracks.Count;
var podcastPlaylist = "";
var i, j;
var date;
var dates = new Array(numTracks);
var allTracks = new Array(numTracks);
var sortedDates;
/* This script assumes that you either deleted the previous SortedPodcast playlist
or that you would expect that a new version will appear with the same name.
This script also assumes that your iTunes is open and that you have the
podcasts or tracks you want put into order selected.
If they are podcasts, they are automatically sorted by download date, then the track
number is prepended and the track number is assigned, then the track is
copied to the SortedPodcasts playlist.
*/
/* Create the SortedPodcast playlist */
podcastPlaylist = iTunesApp.CreatePlaylist("SortedPodcasts");
/* Loop through the selected Tracks */
for (i = 1; i <= numTracks; i++)
{
var currTrack = tracks.Item(i);
allTracks[i] = currTrack;
/* Get the current track date */
date = currTrack.ReleaseDate;
dates[i] = getDate(date + "");
}
sortedDates = dates.sort();
for (i=0; i<numTracks; i++) {
for (j=1; j<=numTracks; j++) {
currTrack = allTracks[j];
if (getDate(currTrack.ReleaseDate + "") == sortedDates[i]) {
/* Set the Track Number */
currTrack.TrackNumber = i+1;
podcastPlaylist.AddTrack(currTrack);
}
}
}
WScript.Echo("Done");
/* Prepend 0s to numbers that are less than 10 */
function leadingZero(i)
{
if (i< 10){
i="0" + i;
}
return i+'';
}
function getMonth(monthString)
{
if (monthString == "Jan")
return "01";
if (monthString == "Feb")
return "02";
if (monthString == "Mar")
return "03";
if (monthString == "Apr")
return "04";
if (monthString == "May")
return "05";
if (monthString == "Jun")
return "06";
if (monthString == "Jul")
return "07";
if (monthString == "Aug")
return "08";
if (monthString == "Sep")
return "09";
if (monthString == "Oct")
return "10";
if (monthString == "Nov")
return "11";
if (monthString == "Dec")
return "12";
}
/* Convert a Date String to a numeric value */
function getDate(dateString)
{
var year, month, day, time;
var parts = dateString.split(" ");
year = parts[5] + "";
day = leadingZero(parts[2]) + "";
month = getMonth(parts[1]) + "";
return year + month + day + parts[3];
}