Export Song List and select the XML format. This DOES NOT WORK on full library exports from iTunes but it may do in the future. It loads the data into an array structure as follows: Array { [0] => Array { [TRACK ID] => [NAME] => [ARTIST] => (may not exist) [ALBUM] => (may not exist) [GENRE] => (may not exist) [KIND] => [SIZE] => [TOTAL TIME] => [BIT RATE] => [SAMPLE RATE] => [PLAY COUNT] => } [1] => Array { . . . } ... } I have provided code to format it as HTML (very simple formatting) and a function to get the track length in mm:ss instead of milliseconds. S.T. 1/31/05 Added code to perform SQL queries */ $fid_log = fopen($log_filename,"w"); fwrite($fid_log,sprintf("ARTIST,NAME,PLAYLIST\t\tREASON FAILED\n")); $num_updated_records = 0; foreach($xml_files as $file) { $tracks = array(); $track_counter = -1; $action = ""; $k = ""; $content = ""; $mode = "GETTRACKINFO"; $play_order = array(); $playlist = array(); $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); xml_set_character_data_handler($xml_parser, "characterData"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { if (!xml_parse($xml_parser, $data, feof($fp))) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); } } xml_parser_free($xml_parser); //insert values into database usort($tracks, "track_cmp"); $tr_num = 0; mysql_select_db($database_experiment_admin, $experiment_admin); while($tr_num != count($tracks)) { $location_field = GetSQLValueString($tracks[$tr_num]["LOCATION"],"file"); $vals = ""; $vals = $vals."(". GetSQLValueString($tracks[$tr_num]["NAME"],"text").",". GetSQLValueString("iTunes Music Fragment","text").",". GetSQLValueString($playlist["NAME"],"text").",". GetSQLValueString($tracks[$tr_num]["ARTIST"],"text").",". GetSQLValueString($tracks[$tr_num]["ALBUM"],"text").",". GetSQLValueString($tracks[$tr_num]["GENRE"],"text").",". GetSQLValueString("mp3","text").",". GetSQLValueString($tracks[$tr_num]["SIZE"],"int").",". GetSQLValueString($tracks[$tr_num]["TOTAL TIME"],"time").",". GetSQLValueString($tracks[$tr_num]["YEAR"],"int").",". GetSQLValueString($tracks[$tr_num]["BIT RATE"],"int").",". GetSQLValueString($tracks[$tr_num]["SAMPLE RATE"],"int").",". $location_field."),"; //get rid of the trailing comma $vals = substr($vals,0,strlen($vals)-1); //do the sql $sql = "INSERT IGNORE INTO stimulus (name,description,playlist,artist,album,genre,file_format,size,duration,year,compression_bit_rate,sample_rate,location) VALUES ".$vals.";"; mysql_select_db($database_experiment_admin,$experiment_admin); mysql_query($sql) or die(mysql_error()); $insert_worked = mysql_affected_rows(); $success = TRUE; if($insert_worked) { //remove the new root location from the location string //so that source and destination strings can be built for copying //also remove quotes inserted into the string for SQL $relative_path_loc = substr($location_field,strlen($new_location_root)+1); $relative_path_loc = substr($relative_path_loc,0,strlen($relative_path_loc)-1); //copy the mp3 from directory $artist_folder = strtok($relative_path_loc,'/'); $album_folder = strtok('/'); $song = strtok('/'); $dir_exists = is_dir($dest_path.$artist_folder); if(!$dir_exists) { $dir_exists = mkdir($dest_path.$artist_folder); if(!$dir_exists) { $sucess = FALSE; $reason = "couldn't make artist directory"; } } if($dir_exists && !is_dir($dest_path.$artist_folder."/".$album_folder)) { $dir_exists = mkdir($dest_path.$artist_folder."/".$album_folder); if(!$dir_exists) { $success = FALSE; $reason = "couldn't make album directory"; } } if($dir_exists) { $success = copy($sfpath.$relative_path_loc,$dest_path.$relative_path_loc); if(!$success) $reason = "couldn't copy the audio file"; } } else { $success = FALSE; $reason = "couldn't insert record to table (duplicate entry?)"; } //if file copy didn't work, but a new record was inserted //delete that record if(!$success && $insert_worked) { $new_id = mysql_insert_id(); //remove the record from the database and output the unsuccessful record to a log file $sql = sprintf("delete from stimulus where stimulus_id = %d",$new_id); mysql_select_db($database_experiment_admin,$experiment_admin); mysql_query($sql) or die(mysql_error()); } if(!$success) fwrite($fid_log,sprintf("%s,%s,%s\t\t%s\n",$tracks[$tr_num]["ARTIST"],$tracks[$tr_num]["NAME"],$playlist["NAME"],$reason)); else $num_updated_records++; $tr_num++; } if($FORMAT_AS_HTML) { // simple HTML formatting print ("
Name | \n"); print ("Album | \n"); print ("Artist | \n"); print ("Play Count | \n"); print ("Track Length | \n"); print ("File Size | \n"); print ("||
" . $tracks[$i]["NAME"] . " | "); if (isset($tracks[$i]["ALBUM"])) { print ("" . $tracks[$i]["ALBUM"] . " | "); } else { print ("~ | "); } if (isset($tracks[$i]["ARTIST"])) { print ("" . $tracks[$i]["ARTIST"] . " | "); } else { print ("~ | "); } print ("" . $tracks[$i]["PLAY COUNT"] . " | "); print ("" . secs2minsasecs($tracks[$i]["TOTAL TIME"]) . " | "); print ("" . $tracks[$i]["SIZE"] . " bytes | "); print ("