/** * update_user_stats * updates the playcount mojo for this specific user */ public function update_stats($media_type, $media_id, $agent = '', $location = array(), $noscrobble = false) { debug_event('user.class.php', 'Updating stats for {' . $media_type . '/' . $media_id . '} {' . $agent . '}...', 5); $media = new $media_type($media_id); $media->format(); $user = $this->id; // We shouldn't test on file only if (!strlen($media->file)) { return false; } if (!$noscrobble) { $this->set_preferences(); // If pthreads available, we call save_songplay in a new thread to quickly return if (class_exists("Thread", false)) { debug_event('user.class.php', 'Calling save_mediaplay plugins in a new thread...', 5); $thread = new scrobbler_async($GLOBALS['user'], $media); if ($thread->start()) { //$thread->join(); } else { debug_event('user.class.php', 'Error when starting the thread.', 1); } } else { User::save_mediaplay($GLOBALS['user'], $media); } } else { debug_event('user.class.php', 'Scrobbling explicitly skipped', 5); } $media->set_played($user, $agent, $location); return true; }
/** * update_user_stats * updates the playcount mojo for this specific user */ public function update_stats($song_id, $agent = '') { debug_event('user.class.php', 'Updating stats for {' . $song_id . '} {' . $agent . '}...', '5'); $song_info = new Song($song_id); $song_info->format(); $user = $this->id; if (!strlen($song_info->file)) { return false; } $this->set_preferences(); // If pthreads available, we call save_songplay in a new thread to quickly return if (class_exists("Thread", false)) { debug_event('user.class.php', 'Calling save_songplay plugins in a new thread...', '5'); $thread = new scrobbler_async($GLOBALS['user'], $song_info); if ($thread->start()) { //$thread->join(); } else { debug_event('user.class.php', 'Error when starting the thread.', '1'); } } else { User::save_songplay($GLOBALS['user'], $song_info); } // Do this last so the 'last played checks are correct' Stats::insert('song', $song_id, $user, $agent); Stats::insert('album', $song_info->album, $user, $agent); Stats::insert('artist', $song_info->artist, $user, $agent); return true; }