diff options
-rwxr-xr-x | docs/CHANGELOG | 2 | ||||
-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 | ||||
-rw-r--r-- | lib/init.php | 2 | ||||
-rw-r--r-- | login.php | 26 | ||||
-rw-r--r-- | play/index.php | 3 | ||||
-rw-r--r-- | templates/show_index.inc.php | 3 |
8 files changed, 78 insertions, 33 deletions
diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 2048349b..30cf67bf 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,8 @@ -------------------------------------------------------------------------- v.3.4-Alpha2 + - Adjusted LastFM reporting to reduce lag betwen songs. You must + now currently be logged in for LastFM to report correctly - Fixed a potential PHP error when browsing the last page or a search with 0 results - Fixed rating search method 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 diff --git a/lib/init.php b/lib/init.php index 6efa68a2..fdbabe45 100644 --- a/lib/init.php +++ b/lib/init.php @@ -67,7 +67,7 @@ if (!count($results)) { } /** This is the version.... fluf nothing more... **/ -$results['version'] = '3.4-Alpha2 Build (002)'; +$results['version'] = '3.4-Alpha2 Build (003)'; $results['int_config_version'] = '5'; $results['raw_web_path'] = $results['web_path']; @@ -104,10 +104,13 @@ if ($_POST['username'] && $_POST['password']) { /* If the authentication was a success */ if ($auth['success']) { - // $auth->info are the fields specified in the config file - // to retrieve for each user - vauth_session_create($auth); + // $auth->info are the fields specified in the config file + // to retrieve for each user + vauth_session_create($auth); + // Generate the user we need for a few things + $user = User::get_from_username($username); + // // Not sure if it was me or php tripping out, // but naming this 'user' didn't work at all @@ -118,11 +121,24 @@ if ($auth['success']) { // Record the IP of this person! // if (Config::get('track_user_ip')) { - $user = User::get_from_username($username); $user->insert_ip_history(); - unset($user); } + // Reload the Preferences from the database + init_preferences(); + + // Do the handshake with LastFM if they are configured as such to let it know we might submit some stuff soon + if ($user->prefs['lastfm_user'] AND $user->prefs['lastfm_pass']) { + $lastfm = new scrobbler($user->prefs['lastfm_user'],$user->prefs['lastfm_pass']); + + /* Attempt handshake */ + $handshake = $lastfm->handshake(); + if (!$handshake) { + debug_event('LastFM','Handshake Failed: ' . $lastfm->error_msg,'3'); + } + } // if LastFM + + /* Make sure they are actually trying to get to this site and don't try to redirect them back into * an admin section **/ diff --git a/play/index.php b/play/index.php index 778dc043..10ab8208 100644 --- a/play/index.php +++ b/play/index.php @@ -308,6 +308,7 @@ while (!feof($fp) && (connection_status() == 0)) { // Make sure that a good chunk of the song has been played if ($bytesStreamed > $minBytesStreamed) { debug_event('Stats','Registering stats for ' . $song->title,'5'); + $user->update_stats($song->id); /* If this is a voting tmp playlist remove the entry */ if (is_object($tmp_playlist)) { @@ -315,7 +316,7 @@ if ($bytesStreamed > $minBytesStreamed) { $tmp_playlist->delete_track($song_id); } } -} +} // if enough bytes are streamed else { debug_event('stream',$bytesStreamed .' of ' . $song->size . ' streamed, less than ' . $minBytesStreamed . ' not collecting stats','5'); } diff --git a/templates/show_index.inc.php b/templates/show_index.inc.php index 765d89df..ade19a52 100644 --- a/templates/show_index.inc.php +++ b/templates/show_index.inc.php @@ -48,7 +48,10 @@ if (isset($_REQUEST['xspf']) && isset ($_REQUEST['play_info'])){ </div> <div id="recent_added"> <?php + $objects = Stats::get_newest('album'); + $headers = array('f_link'=>_('Newest Albums')); show_box_top(); + require_once Config::get('prefix') . '/templates/show_objects.inc.php'; show_box_bottom(); ?> </div> |