summaryrefslogtreecommitdiffstats
path: root/lib/class/user.class.php
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-08-09 14:34:06 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-08-09 14:34:06 +0000
commitab9aec092c66f090eb77ac6a53e37a02a9aecbbf (patch)
treedef7403f8336574be54346bfb81c0c8127f60a62 /lib/class/user.class.php
parent699a85cb82f5b8cec9439a29c2f3312ae84b77e0 (diff)
downloadampache-ab9aec092c66f090eb77ac6a53e37a02a9aecbbf.tar.gz
ampache-ab9aec092c66f090eb77ac6a53e37a02a9aecbbf.tar.bz2
ampache-ab9aec092c66f090eb77ac6a53e37a02a9aecbbf.zip
tweaked get_newest to operate a little different, tweaked lastfm (currently broken)
Diffstat (limited to 'lib/class/user.class.php')
-rw-r--r--lib/class/user.class.php58
1 files changed, 38 insertions, 20 deletions
diff --git a/lib/class/user.class.php b/lib/class/user.class.php
index fa498671..dce54353 100644
--- a/lib/class/user.class.php
+++ b/lib/class/user.class.php
@@ -573,30 +573,27 @@ class User {
*/
if (!empty($this->prefs['lastfm_user']) AND !empty($this->prefs['lastfm_pass'])) {
$song_info->format();
- $lastfm = new scrobbler($this->prefs['lastfm_user'],$this->prefs['lastfm_pass']);
- /* Attempt handshake */
- $handshake = $lastfm->handshake();
- /* We failed, try again */
- if (!$handshake) { sleep(1); $handshake = $lastfm->handshake(); }
+ // We're also going to need the session here
+ $data = $this->get_newest_session();
+
+ $lastfm = new scrobbler($this->prefs['lastfm_user'],$this->prefs['lastfm_pass']);
+ $lastfm->submit_host = $data['state']['lastfm']['submit_host'];
+ $lastfm->submit_port = $data['state']['lastfm']['submit_port'];
+ $lastfm->submit_url = $data['state']['lastfm']['submit_url'];
- if ($handshake) {
- if (!$lastfm->queue_track($song_info->f_artist_full,$song_info->f_album_full,$song_info->title,time(),$song_info->time)) {
- debug_event('LastFM','Error: Queue Failed: ' . $lastfm->error_msg,'3');
- }
+ if (!$lastfm->queue_track($song_info->f_artist_full,$song_info->f_album_full,$song_info->title,time(),$song_info->time)) {
+ debug_event('LastFM','Error: Queue Failed: ' . $lastfm->error_msg,'3');
+ }
- $submit = $lastfm->submit_tracks();
+ $submit = $lastfm->submit_tracks();
- /* Try again if it fails */
- if (!$submit) { sleep(1); $submit = $lastfm->submit_tracks(); }
-
- if (!$submit) {
- debug_event('LastFM','Error Submit Failed: ' . $lastfm->error_msg,'3');
- }
- } // if handshake
- else {
- debug_event('LastFM','Error: Handshake failed with LastFM: ' . $lastfm->error_msg,'3');
- }
+ /* Try again if it fails */
+ if (!$submit) { sleep(1); $submit = $lastfm->submit_tracks(); }
+
+ if (!$submit) {
+ debug_event('LastFM','Error Submit Failed: ' . $lastfm->error_msg,'3');
+ }
} // record to LastFM
} // update_stats
@@ -1121,6 +1118,27 @@ class User {
return true;
} // rebuild_all_preferences
+
+ /**
+ * get_newest_session
+ * This will find the latest active session for this user and return an array from the serialized value
+ */
+ public function get_newest_session() {
+
+ $username = Dba::escape($this->username);
+ $time = time();
+
+ $sql = "SELECT `value` FROM `session` WHERE `username`='$username' AND `expire` > '$time' ORDER BY `expire` DESC";
+ $db_results = Dba::query($sql);
+
+ $row = Dba::fetch_assoc($db_results);
+ $string = trim($row['value']);
+
+ $value = unseralize($string);
+
+ return $value;
+
+ } // get_newest_session
} //end user class