diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-08-09 14:34:06 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-08-09 14:34:06 +0000 |
commit | ab9aec092c66f090eb77ac6a53e37a02a9aecbbf (patch) | |
tree | def7403f8336574be54346bfb81c0c8127f60a62 /lib/class | |
parent | 699a85cb82f5b8cec9439a29c2f3312ae84b77e0 (diff) | |
download | ampache-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')
-rw-r--r-- | lib/class/album.class.php | 5 | ||||
-rw-r--r-- | lib/class/scrobbler.class.php | 12 | ||||
-rw-r--r-- | lib/class/user.class.php | 58 |
3 files changed, 49 insertions, 26 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index b47e6b03..25e720f8 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -208,9 +208,10 @@ class Album { foreach ($data as $key=>$value) { $this->$key = $value; } /* Truncate the string if it's to long */ - $this->f_name = scrub_out(truncate_with_ellipsis($this->name,Config::get('ellipsis_threshold_album'))); + $this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipsis_threshold_album')); $this->f_name_link = "<a href=\"$web_path/albums.php?action=show&album=" . scrub_out($this->id) . "\" title=\"" . scrub_out($this->name) . "\">" . $this->f_name . "</a>"; - $this->f_title = $name; + $this->f_link = $this->f_name_link; + $this->f_title = $name; if ($this->artist_count == '1') { $artist = scrub_out(truncate_with_ellipsis(trim($this->artist_prefix . ' ' . $this->artist_name),Config::get('ellipsis_threshold_album'))); $this->f_artist = "<a href=\"$web_path/artists.php?action=show&artist=" . $this->artist_id . "\">" . $artist . "</a>"; diff --git a/lib/class/scrobbler.class.php b/lib/class/scrobbler.class.php index 352d51ae..8b8ca5a7 100644 --- a/lib/class/scrobbler.class.php +++ b/lib/class/scrobbler.class.php @@ -42,6 +42,10 @@ class scrobbler { $this->challenge = ''; $this->queued_tracks = array(); + $this->submit_host = $_SESSION['state']['lastfm']['submit_host']; + $this->submit_port = $_SESSION['state']['lastfm']['submit_port']; + $this->submit_url = $_SESSION['state']['lastfm']['submit_url']; + } // scrobbler /** @@ -77,7 +81,7 @@ class scrobbler { $username = rawurlencode($this->username); - $get_string = "GET /?hs=true&p=1.1&c=m3a&v=0.1&u=$username HTTP/1.1\r\n"; + $get_string = "GET /?hs=true&p=1.1&c=apa&v=0.1&u=$username HTTP/1.1\r\n"; fwrite($as_socket, $get_string); fwrite($as_socket, "Host: post.audioscrobbler.com\r\n"); @@ -108,9 +112,9 @@ class scrobbler { } if(preg_match('/http:\/\/(.*):(\d+)(.*)/', $response[2], $matches)) { - $this->submit_host = $matches[1]; - $this->submit_port = $matches[2]; - $this->submit_url = $matches[3]; + $_SESSION['state']['lastfm']['submit_host'] = $matches[1]; + $_SESSION['state']['lastfm']['submit_port'] = $matches[2]; + $_SESSION['state']['lastfm']['submit_url'] = $matches[3]; } else { $this->error_msg = 'Invalid POST URL returned, unable to continue'; return false; 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 |