summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/class/scrobbler.class.php10
-rw-r--r--lib/class/tag.class.php37
-rw-r--r--lib/class/update.class.php16
-rw-r--r--lib/class/user.class.php8
-rw-r--r--lib/class/xmldata.class.php4
-rw-r--r--lib/preferences.php2
-rw-r--r--modules/plugins/Librefm.plugin.php217
-rw-r--r--modules/plugins/RioPlayer.plugin.php87
-rw-r--r--server/xml.server.php9
-rw-r--r--templates/header.inc.php2
10 files changed, 286 insertions, 106 deletions
diff --git a/lib/class/scrobbler.class.php b/lib/class/scrobbler.class.php
index 6c4b1e0f..f2b56c7c 100644
--- a/lib/class/scrobbler.class.php
+++ b/lib/class/scrobbler.class.php
@@ -30,12 +30,13 @@ class scrobbler {
public $submit_url;
public $queued_tracks;
public $reset_handshake = false;
+ public $scrobble_host = 'post.audioscrobbler.com';
/**
* Constructor
* This is the constructer it takes a username and password
*/
- public function __construct($username, $password,$host='',$port='',$url='',$challenge='') {
+ public function __construct($username, $password,$host='',$port='',$url='',$challenge='',$scrobble_host='') {
$this->error_msg = '';
$this->username = trim($username);
@@ -45,6 +46,7 @@ class scrobbler {
$this->submit_port = $port;
$this->submit_url = $url;
$this->queued_tracks = array();
+ if ($scrobble_host) { $this->scrobble_host = $scrobble_host; }
} // scrobbler
@@ -73,7 +75,7 @@ class scrobbler {
*/
public function handshake() {
- $as_socket = fsockopen('post.audioscrobbler.com', 80, $errno, $errstr, 2);
+ $as_socket = fsockopen($this->scrobble_host, 80, $errno, $errstr, 2);
if(!$as_socket) {
$this->error_msg = $errstr;
return false;
@@ -86,7 +88,7 @@ class scrobbler {
$get_string = "GET /?hs=true&p=1.2&c=apa&v=0.1&u=$username&t=$timestamp&a=$auth_token HTTP/1.1\r\n";
fwrite($as_socket, $get_string);
- fwrite($as_socket, "Host: post.audioscrobbler.com\r\n");
+ fwrite($as_socket, "Host: $this->scrobble_host\r\n");
fwrite($as_socket, "Accept: */*\r\n\r\n");
$buffer = '';
@@ -202,7 +204,7 @@ class scrobbler {
fwrite($as_socket, $action);
fwrite($as_socket, "Host: ".$this->submit_host."\r\n");
fwrite($as_socket, "Accept: */*\r\n");
- fwrite($as_socket, "User-Agent: Ampache/3.4\r\n");
+ fwrite($as_socket, "User-Agent: Ampache/3.6\r\n");
fwrite($as_socket, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($as_socket, "Content-length: ".strlen($query_str)."\r\n\r\n");
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php
index 44d91c9b..c6dcf13d 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -349,18 +349,20 @@ class Tag extends database_object {
/**
* get_object_tags
* Display all tags that apply to maching target type of the specified id
+ * UNUSED
*/
public static function get_object_tags($type, $id) {
if (!self::validate_type($type)) { return array(); }
+
+ $id = Dba::escape($id);
- $sql = "SELECT DISTINCT `tag_map`.`id`, `tag`.`name`, `tag_map`.`user` FROM `tag` " .
- "LEFT JOIN `tag_map` ON `tag_map`.`id`=`tag`.`map_id` " .
- "LEFT JOIN `$type` ON `$type`.`id`=`tag_map`.`object_id` " .
- "WHERE `tag_map`.`object_type`='$type'";
+ $sql = "SELECT `tag_map`.`id`, `tag`.`name`, `tag_map`.`user` FROM `tag` " .
+ "LEFT JOIN `tag_map` ON `tag_map`.`tag_id`=`tag`.`id` " .
+ "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id`='$id'";
$results = array();
- $db_results = Dba::query($sql);
+ $db_results = Dba::read($sql);
while ($row = Dba::fetch_assoc($db_results)) {
$results[] = $row;
@@ -371,6 +373,31 @@ class Tag extends database_object {
} // get_object_tags
/**
+ * get_tag_objects
+ * This gets the objects from a specified tag and returns an array of object ids, nothing more
+ */
+ public static function get_tag_objects($type,$tag_id) {
+
+ if (!self::validate_type($type)) { return array(); }
+
+ $tag_id = Dba::escape($id);
+
+ $sql = "SELECT DISTINCT `tag_map`.`object_id` FROM `tag_map` " .
+ "WHERE `tag_map`.`tag_id`='$tag_id' AND `tag_map`.`object_type`='$type'";
+ $db_results = Dba::read($sql);
+
+ $results = array();
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['object_id'];
+ }
+
+ return $results;
+
+
+ } // get_tag_objects
+
+ /**
* get_tags
* This is a non-object non type depedent function that just returns tags
* we've got, it can take filters (this is used by the tag cloud)
diff --git a/lib/class/update.class.php b/lib/class/update.class.php
index 57283f56..5a36b253 100644
--- a/lib/class/update.class.php
+++ b/lib/class/update.class.php
@@ -1762,7 +1762,23 @@ class Update {
*/
public static function update_360001() {
+ // Remove any RIO related information from the database as the plugin has been removed
+ $sql = "DELETE FROM `update_info` WHERE `key` LIKE 'Plugin_Ri%'";
+ $db_results = Dba::write($sql);
+
+ $sql = "DELETE FROM `preference` WHERE `name` LIKE 'rio_%'";
+ $db_results = Dba::write($sql);
+
+ $sql = "SELECT `id` FROM `user`";
+ $db_results = Dba::query($sql);
+
+ User::fix_preferences('-1');
+
+ while ($r = Dba::fetch_assoc($db_results)) {
+ User::fix_preferences($r['id']);
+ } // while we're fixing the useres stuff
+ // self::set_version('db_version','360001');
} // update_360001
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index a8d58ed4..0b5f6c44 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -561,6 +561,14 @@ class User extends database_object {
}
} // end if is_installed
+ // Check and see if librefm is loaded and run scrobblizing
+ if (Plugin::is_installed('Libre.FM')) {
+ $librefm = new Plugin('Librefm');
+ if ($lastfm->_plugin->load($this->prefs,$this->id)) {
+ $lastfm->_plugin->submit($song_info,$this->id);
+ }
+ } // end if is_installed
+
// Do this last so the 'last played checks are correct'
Stats::insert('song',$song_id,$user);
Stats::insert('album',$song_info->album,$user);
diff --git a/lib/class/xmldata.class.php b/lib/class/xmldata.class.php
index c9a11112..5fa58e71 100644
--- a/lib/class/xmldata.class.php
+++ b/lib/class/xmldata.class.php
@@ -179,7 +179,6 @@ class xmlData {
$tags = array_splice($tags,self::$offset,self::$limit);
}
-
$string = '';
foreach ($tags as $tag_id) {
@@ -190,12 +189,11 @@ class xmlData {
"\t<albums>" . intval($counts['album']) . "</albums>\n" .
"\t<artists>" . intval($counts['artist']) . "</artists>\n" .
"\t<songs>" . intval($counts['songs']) . "</songs>\n" .
- "\t<videos>" . intval($counts['video']) . "</video>\n" .
+ "\t<videos>" . intval($counts['video']) . "</videos>\n" .
"\t<playlists>" . intval($count['playlist']) . "</playlists>\n" .
"\t<stream>" . intval($count['live_stream']) . "</stream>\n" .
"</tag>\n";
} // end foreach
-
$final = self::_header() . $string . self::_footer();
diff --git a/lib/preferences.php b/lib/preferences.php
index 1e721216..26e8c422 100644
--- a/lib/preferences.php
+++ b/lib/preferences.php
@@ -58,6 +58,7 @@ function update_preferences($pref_id=0) {
$value = Stream::validate_bitrate($value);
break;
/* MD5 the LastFM & MyStrands so it's not plainTXT */
+ case 'librefm_pass':
case 'lastfm_pass':
/* If it's our default blanking thing then don't use it */
if ($value == '******') { unset($_REQUEST[$name]); break; }
@@ -244,6 +245,7 @@ function create_preference_input($name,$value) {
echo "</select>\n";
break;
case 'lastfm_pass':
+ case 'librefm_pass':
echo "<input type=\"password\" size=\"16\" name=\"$name\" value=\"******\" />";
break;
case 'playlist_method':
diff --git a/modules/plugins/Librefm.plugin.php b/modules/plugins/Librefm.plugin.php
new file mode 100644
index 00000000..3702a0ec
--- /dev/null
+++ b/modules/plugins/Librefm.plugin.php
@@ -0,0 +1,217 @@
+<?php
+/*
+
+ Copyright (c) Ampache.org
+ All rights reserved.
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License v2
+ as published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+*/
+
+class Ampachelibrefm {
+
+ public $name ='Libre.FM';
+ public $description ='Records your played songs to your Libre.FM Account';
+ public $url ='';
+ public $version ='000001';
+ public $min_ampache ='350001';
+ public $max_ampache ='360008';
+
+ // These are internal settings used by this class, run this->load to
+ // fill em out
+ private $username;
+ private $password;
+ private $hostname;
+ private $port;
+ private $path;
+ private $challenge;
+
+ /**
+ * Constructor
+ * This function does nothing...
+ */
+ public function __construct() {
+
+ return true;
+
+ } // Pluginlibrefm
+
+ /**
+ * install
+ * This is a required plugin function it inserts the required preferences
+ * into Ampache
+ */
+ public function install() {
+
+ // Check and see if it's already installed (they've just hit refresh, those dorks)
+ if (Preference::exists('librefm_user')) { return false; }
+
+ Preference::insert('librefm_user','Libre.FM Username','','25','string','plugins');
+ Preference::insert('librefm_pass','Libre.FM Password','','25','string','plugins');
+ Preference::insert('librefm_port','Libre.FM Submit Port','','25','string','internal');
+ Preference::insert('librefm_host','Libre.FM Submit Host','','25','string','internal');
+ Preference::insert('librefm_url','Libre.FM Submit URL','','25','string','internal');
+ Preference::insert('librefm_challenge','Libre.FM Submit Challenge','','25','string','internal');
+
+ return true;
+
+ } // install
+
+ /**
+ * uninstall
+ * This is a required plugin function it removes the required preferences from
+ * the database returning it to its origional form
+ */
+ public function uninstall() {
+
+ Preference::delete('librefm_pass');
+ Preference::delete('librefm_user');
+ Preference::delete('librefm_url');
+ Preference::delete('librefm_host');
+ Preference::delete('librefm_port');
+ Preference::delete('librefm_challenge');
+
+ } // uninstall
+
+ /**
+ * submit
+ * This takes care of queueing and then submiting the tracks eventually this will make sure
+ * that you've haven't
+ */
+ public function submit($song,$user_id) {
+
+ // Before we start let's pull the last song submited by this user
+ $previous = Stats::get_last_song($user_id);
+
+ $diff = time() - $previous['date'];
+
+ // Make sure it wasn't within the last min
+ if ($diff < 60) {
+ debug_event('librefm','Last song played within ' . $diff . ' seconds, not recording stats','3');
+ return false;
+ }
+
+ if ($song->time < 30) {
+ debug_event('librefm','Song less then 30 seconds not queueing','3');
+ return false;
+ }
+
+ // Make sure there's actually a username and password before we keep going
+ if (!$this->username || !$this->password) { return false; }
+
+ // Create our scrobbler with everything this time and then queue it
+ $scrobbler = new scrobbler($this->username,$this->password,$this->hostname,$this->port,$this->path,$this->challenge);
+
+ // Check to see if the scrobbling works
+ if (!$scrobbler->queue_track($song->f_artist_full,$song->f_album_full,$song->title,time(),$song->time,$song->track)) {
+ // Depending on the error we might need to do soemthing here
+ return false;
+ }
+
+ // Go ahead and submit it now
+ if (!$scrobbler->submit_tracks()) {
+ debug_event('librefm','Error Submit Failed: ' . $scrobbler->error_msg,'3');
+ if ($scrobbler->reset_handshake) {
+ debug_event('librefm','Re-running Handshake due to error','3');
+ $this->set_handshake($user_id);
+ // Try try again
+ if ($scrobbler->submit_tracks()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ debug_event('librefm','Submission Successful','5');
+
+ return true;
+
+ } // submit
+
+ /**
+ * set_handshake
+ * This runs a handshake and properly updates the preferences as needed, it returns the data
+ * as an array so we don't have to requery the db. This requires a userid so it knows who's
+ * crap to update
+ */
+ public function set_handshake($user_id) {
+
+ $scrobbler = new scrobbler($this->username,$this->password);
+ $data = $scrobbler->handshake();
+
+ if (!$data) {
+ debug_event('librefm','Handshake Failed: ' . $scrobbler->error_msg,'3');
+ return false;
+ }
+
+ $this->hostname = $data['submit_host'];
+ $this->port = $data['submit_port'];
+ $this->path = $data['submit_url'];
+ $this->challenge = $data['challenge'];
+
+ // Update the preferences
+ Preference::update('librefm_port',$user_id,$data['submit_port']);
+ Preference::update('librefm_host',$user_id,$data['submit_host']);
+ Preference::update('librefm_url',$user_id,$data['submit_url']);
+ Preference::update('librefm_challenge',$user_id,$data['challenge']);
+
+ return true;
+
+ } // set_handshake
+
+ /**
+ * load
+ * This loads up the data we need into this object, this stuff comes from the preferences
+ * it's passed as a key'd array
+ */
+ public function load($data,$user_id) {
+
+ if (strlen(trim($data['librefm_user']))) {
+ $this->username = trim($data['librefm_user']);
+ }
+ else {
+ debug_event('librefm','No Username, not scrobbling','3');
+ return false;
+ }
+ if (strlen(trim($data['librefm_pass']))) {
+ $this->password = trim($data['librefm_pass']);
+ }
+ else {
+ debug_event('librefm','No Password, not scrobbling','3');
+ return false;
+ }
+
+ // If we don't have the other stuff try to get it before giving up
+ if (!$data['librefm_host'] || !$data['librefm_port'] || !$data['librefm_url'] || !$data['librefm_challenge']) {
+ debug_event('librefm','Running Handshake, missing information','3');
+ if (!$this->set_handshake($user_id)) {
+ debug_event('librefm','Handshake failed, you lose','3');
+ return false;
+ }
+ }
+ else {
+ $this->hostname = $data['librefm_host'];
+ $this->port = $data['librefm_port'];
+ $this->path = $data['librefm_url'];
+ $this->challenge = $data['librefm_challenge'];
+ }
+
+
+ return true;
+
+ } // load
+
+
+} // end Ampachelibrefm
+?>
diff --git a/modules/plugins/RioPlayer.plugin.php b/modules/plugins/RioPlayer.plugin.php
deleted file mode 100644
index f6dae7c3..00000000
--- a/modules/plugins/RioPlayer.plugin.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-/*
-
- Copyright (c) 2001 - 2006 Ampache.org
- All rights reserved.
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License v2
- as published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
-*/
-
-class AmpacheRioPlayer {
-
- var $name ='Rio Player';
- var $description ='Sets up ampache so a Rio Player can access it';
- var $url ='';
- var $version ='000001';
- var $min_ampache ='333001';
- var $max_ampache ='333005';
-
- /**
- * Constructor
- * This function does nothing...
- */
- function PluginRioPlayer() {
-
- return true;
-
- } // PluginLastfm
-
- /**
- * install
- * This is a required plugin function it inserts the required preferences
- * into Ampache
- */
- function install() {
-
- /* We need to insert the new preferences */
-
- $sql = "INSERT INTO preferences (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
- "VALUES ('rio_querylimit','3000','Rio Player Query Limit','100','integer','system')";
- $db_results = mysql_query($sql,dbh());
-
- $sql = "INSERT INTO preferences (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
- "VALUES ('rio_track_stats','0','Rio Player Track Stats','100','boolean','system')";
- $db_results = mysql_query($sql,dbh());
-
- $sql = "INSERT INTO preferences (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
- "VALUES ('rio_user','','Rio Player Global User','100','string','system')";
- $db_results = mysql_query($sql,dbh());
-
- $sql = "INSERT INTO preferences (`name`,`value`,`description`,`level`,`type`,`catagory`) " .
- "VALUES ('rio_global_stats','0','Rio Player Group Stats','100','boolean','system')";
- $db_results = mysql_query($sql,dbh());
-
- fix_all_users_prefs();
-
- } // install
-
- /**
- * uninstall
- * This is a required plugin function it removes the required preferences from
- * the database returning it to its origional form
- */
- function uninstall() {
-
- /* We need to remove the preivously added preferences */
-
- $sql = "DELETE FROM preferences WHERE name='rio_querylimit' OR name='rio_track_stats' OR name='rio_user' OR name='rio_global_stats'";
- $db_results = mysql_query($sql,dbh());
-
- fix_all_users_prefs();
-
- } // uninstall
-
-} // end AmpacheRioPlayer
-?>
diff --git a/server/xml.server.php b/server/xml.server.php
index 1813592e..bbe3cab2 100644
--- a/server/xml.server.php
+++ b/server/xml.server.php
@@ -199,8 +199,7 @@ switch ($_REQUEST['action']) {
echo xmlData::tags(array($uid));
break;
case 'tag_artists':
- $tag = new tag($_REQUEST['filter']);
- $tags = Tag::get_object_tags('artist',$tag->id);
+ $artists = Tag::get_tag_objects('artist',$_REQUEST['filter']);
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
@@ -209,8 +208,7 @@ switch ($_REQUEST['action']) {
echo xmlData::artists($artists);
break;
case 'tag_albums':
- $genre = new Genre($_REQUEST['filter']);
- $albums = $genre->get_albums();
+ $albums = Tag::get_tag_objects('album',$_REQUEST['filter']);
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
@@ -219,8 +217,7 @@ switch ($_REQUEST['action']) {
echo xmlData::albums($albums);
break;
case 'tag_songs':
- $genre = new Genre($_REQUEST['filter']);
- $songs = $genre->get_songs();
+ $songs = Tag::get_tag_objects('song',$_REQUEST['filter']);
xmlData::set_offset($_REQUEST['offset']);
xmlData::set_limit($_REQUEST['limit']);
diff --git a/templates/header.inc.php b/templates/header.inc.php
index 1566aa44..81199087 100644
--- a/templates/header.inc.php
+++ b/templates/header.inc.php
@@ -24,7 +24,7 @@ if (INIT_LOADED != '1') { exit; }
$web_path = Config::get('web_path');
$htmllang = str_replace("_","-",Config::get('lang'));
$location = get_location();
-$dir = is_rtl() ? "rtl" : "ltr";
+$dir = is_rtl(Config::get('lang')) ? "rtl" : "ltr";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $htmllang; ?>" lang="<?php echo $htmllang; ?>" dir="<?php echo $dir;?>">