diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-11-21 06:53:20 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-11-21 06:53:20 +0000 |
commit | 8d914e47c9ecb0c99f63ba50936a09e2184eaf84 (patch) | |
tree | 31302f42d5399ed10af3c75c7faad5ed3b0d0bbe | |
parent | 794036ac1f462f302ce71e64132d981f69023e09 (diff) | |
download | ampache-8d914e47c9ecb0c99f63ba50936a09e2184eaf84.tar.gz ampache-8d914e47c9ecb0c99f63ba50936a09e2184eaf84.tar.bz2 ampache-8d914e47c9ecb0c99f63ba50936a09e2184eaf84.zip |
additional xml methods songs & album_songs, also implemented catalog add speed improvement from Karl Hungus
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 18 | ||||
-rw-r--r-- | lib/class/xmldata.class.php | 33 | ||||
-rw-r--r-- | modules/vauth/session.lib.php | 4 | ||||
-rw-r--r-- | server/xml.server.php | 19 |
5 files changed, 69 insertions, 6 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index df533d3b..f3522b56 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.4-Alpha3 + - Tweaked catalog add function to improve speed (Thx Karl Hungus) - Added XML API borrows authentication style from Last.FM's scrobbling, allows query of Ampache DB, returns XML see https://ampache.bountysource.com/wiki/xmlapi diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index a6dabbbe..76289677 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -380,6 +380,12 @@ class Catalog { Error::add('catalog_add',_('Error: Unable to open') . ' ' . $path); } + /* Change the dir so is_dir works correctly */ + if (!chdir($path)) { + debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); + Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); + } + /* Recurse through this dir and create the files array */ while ( false !== ( $file = readdir($handle) ) ) { @@ -388,11 +394,6 @@ class Catalog { debug_event('read',"Starting work on $file inside $path",'5','ampache-catalog'); - /* Change the dir so is_dir works correctly */ - if (!chdir($path)) { - debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); - Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); - } /* Create the new path */ $full_file = $path.$slash_type.$file; @@ -411,6 +412,13 @@ class Catalog { /* If it's a dir run this function again! */ if (is_dir($full_file)) { $this->add_files($full_file,$options); + + /* Change the dir so is_dir works correctly */ + if (!chdir($path)) { + debug_event('read',"Unable to chdir $path",'2','ampache-catalog'); + Error::add('catalog_add',_('Error: Unable to change to directory') . ' ' . $path); + } + /* Skip to the next file */ continue; } //it's a directory diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php index ba1bec3f..d63d9bfc 100644 --- a/lib/class/xmldata.class.php +++ b/lib/class/xmldata.class.php @@ -166,6 +166,39 @@ class xmlData { } // genres /** + * songs + * This returns an xml document from an array of song ids spiffy isn't it! + */ + public static function songs($songs) { + + if (count($songs) > self::$limit) { + $songs = array_slice($songs,0,self::$limit); + } + + // Foreach the ids! + foreach ($songs as $song_id) { + $song = new Song($song_id); + $song->format(); + + $string .= "<song id=\"$song->id\">\n" . + "\t<title><![CDATA[$song->title]]></title>\n" . + "\t<artist id=\"$song->artist\"><![CDATA[$song->f_artist_full]]></artist>\n" . + "\t<album id=\"$song->album\"><![CDATA[$song->f_album_full]]></album>\n" . + "\t<genre id=\"$song->genre\"><![CDATA[$song->genre]]></genre>\n" . + "\t<track>$song->track</track>\n" . + "\t<time>$song->time</time>\n" . + "\t<url></url>\n" . + "</song>\n"; + + } // end foreach + + $final = self::_header() . $string . self::_footer(); + + return $final; + + } // songs + + /** * _header * this returns a standard header, there are a few types * so we allow them to pass a type if they want to diff --git a/modules/vauth/session.lib.php b/modules/vauth/session.lib.php index 16daf1cd..36931d68 100644 --- a/modules/vauth/session.lib.php +++ b/modules/vauth/session.lib.php @@ -128,6 +128,10 @@ function vauth_sess_gc($maxlifetime) { $sql = "DELETE FROM `session` WHERE `expire` < '" . time() . "'"; $db_results = Dba::query($sql); + // Randomly collect the api session table + $sql = "DELETE FROM `session_api` WHERE `expire` < '" . time() . "'"; + $db_results = Dba::query($sql); + return true; } // vauth_sess_gc diff --git a/server/xml.server.php b/server/xml.server.php index 38b6f0f5..74e6e1b6 100644 --- a/server/xml.server.php +++ b/server/xml.server.php @@ -70,7 +70,6 @@ switch ($_REQUEST['action']) { $albums = $artist->get_albums(); echo xmlData::albums($albums); - break; case 'albums': Browse::reset_filters(); @@ -83,6 +82,12 @@ switch ($_REQUEST['action']) { $albums = Browse::get_objects(); echo xmlData::albums($albums); break; + case 'album_songs': + $album = new Album($_REQUEST['filter']); + $songs = $album->get_songs(); + + echo xmlData::songs($songs); + break; case 'genres': Browse::reset_filters(); Browse::set_type('genre'); @@ -95,6 +100,18 @@ switch ($_REQUEST['action']) { echo xmlData::genres($genres); break; + case 'songs': + Browse::reset_filters(); + Browse::set_type('song'); + Browse::set_sort('title','ASC'); + + if ($_REQUEST['filter']) { + Browse::set_filter('alpha_match',$_REQUEST['filter']); + } + $songs = Browse::get_objects(); + + echo xmlData::songs($songs); + break; default: // Rien a faire break; |