diff options
author | flashk <flashk@ampache> | 2007-12-29 20:54:20 +0000 |
---|---|---|
committer | flashk <flashk@ampache> | 2007-12-29 20:54:20 +0000 |
commit | cbda7ff555d3a2d95991304cc24045191ffe260c (patch) | |
tree | b7c0baea036d6fee474a36cd1dbaa096d93493b6 /lib/class | |
parent | b1d25fc28f25691333bff62b38d0e2650fa8ce8b (diff) | |
download | ampache-cbda7ff555d3a2d95991304cc24045191ffe260c.tar.gz ampache-cbda7ff555d3a2d95991304cc24045191ffe260c.tar.bz2 ampache-cbda7ff555d3a2d95991304cc24045191ffe260c.zip |
Added ability to export catalog to iTunes database
Fixed sql error when creating catalog
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/catalog.class.php | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 3f854b11..0320c1d6 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -247,8 +247,8 @@ class Catalog { if (!$key) { $key = ' '; } //FIXME // Ok we're good to go ahead and insert this record - $sql = "INSERT INTO `catalog` (`name`,`path`,`catalog_type`,`rename_pattern`,`sort_pattern`,`gather_types`,`key`) " . - "VALUES ('$name','$path','$catalog_type','$rename_pattern','$sort_pattern','$gather_types','$key')"; + $sql = "INSERT INTO `catalog` (`name`,`path`,`add_path`,`catalog_type`,`rename_pattern`,`sort_pattern`,`gather_types`,`key`) " . + "VALUES ('$name','$path','','$catalog_type','$rename_pattern','$sort_pattern','$gather_types','$key')"; $db_results = Dba::query($sql); $insert_id = Dba::insert_id(); @@ -2367,39 +2367,52 @@ class Catalog { @discussion it exports all songs in the database to the given export type. */ function export($type){ - - if ($type=="itunes"){ - - $sql = "SELECT id FROM song ORDER BY album"; - $db_results = mysql_query($sql, dbh()); - while ($results = mysql_fetch_array($db_results)) { - $song = new Song($results['id']); - $song->format_song(); - - $xml = array(); - $xml['key']= $results['id']; - $xml['dict']['Track ID']= $results['id']; - $xml['dict']['Name'] = utf8_encode($song->title); - $xml['dict']['Artist'] = utf8_encode($song->f_artist_full); - $xml['dict']['Album'] = utf8_encode($song->f_album_full); - $xml['dict']['Genre'] = $song->f_genre; - $xml['dict']['Total Time'] = $song->time; - $xml['dict']['Track Number'] = $song->track; - $xml['dict']['Year'] = $song->year; - $xml['dict']['Date Added'] = date("Y-m-d\TH:i:s\Z",$song->addition_time); - $xml['dict']['Bit Rate'] = intval($song->bitrate/1000); - $xml['dict']['Sample Rate'] = $song->rate; - $xml['dict']['Play Count'] = $song->played; - $xml['dict']['Track Type'] = "URL"; - $xml['dict']['Location'] = $song->get_url(); - - $result .= xml_from_array($xml,1,'itunes'); + // Select all songs in catalog + if($this->id) { + $sql = "SELECT id FROM song WHERE catalog = '$this->id' ORDER BY album,track"; + } else { + $sql = "SELECT id FROM song ORDER BY album,track"; } - return $result; + $db_results = Dba::query($sql); + + if ($type=="itunes"){ + + echo xml_get_header('itunes'); + + while ($results = Dba::fetch_assoc($db_results)) { + $song = new Song($results['id']); + $song->format(); + + $xml = array(); + $xml['key']= $results['id']; + $xml['dict']['Track ID']= intval($results['id']); + $xml['dict']['Name'] = $song->title; + $xml['dict']['Artist'] = $song->f_artist_full; + $xml['dict']['Album'] = $song->f_album_full; + $xml['dict']['Genre'] = $song->f_genre; + $xml['dict']['Total Time'] = intval($song->time) * 1000; // iTunes uses milliseconds + $xml['dict']['Track Number'] = intval($song->track); + $xml['dict']['Year'] = intval($song->year); + $xml['dict']['Date Added'] = date("Y-m-d\TH:i:s\Z",$song->addition_time); + $xml['dict']['Bit Rate'] = intval($song->bitrate/1000); + $xml['dict']['Sample Rate'] = intval($song->rate); + $xml['dict']['Play Count'] = intval($song->played); + $xml['dict']['Track Type'] = "URL"; + $xml['dict']['Location'] = $song->get_url(); + + echo xml_from_array($xml,1,'itunes'); + + // flush output buffer + ob_flush(); + flush(); + + } // while result + + echo xml_get_footer('itunes'); + + } // itunes - } - } // export } // end of catalog class |