Example #1
0
 /**
  * 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 whose crap to update.
  */
 public function set_handshake($user_id)
 {
     $scrobbler = new scrobbler($this->username, $this->password, '', '', '', '', 'turtle.libre.fm');
     $data = $scrobbler->handshake();
     if (!$data) {
         debug_event($this->name, '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;
 }
    $result = date("(m.d.y g:i:sa) ") . $result;
    $sql = "UPDATE grammafone_users SET as_lastresult=\"{$result}\" WHERE user_id={$user_id}";
    if (mysql_query($sql)) {
        return TRUE;
    }
}
if (isset($_SERVER['argv'][1])) {
    $sql = "SELECT as_username,as_password FROM grammafone_users WHERE as_password!=\"\" AND as_username!=\"\" AND user_id=" . $_SERVER['argv'][1];
    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);
    $as = new scrobbler($row['as_username'], $row['as_password']);
    if (mysql_num_rows($result) > 0) {
        $wait = 60;
        $success = FALSE;
        while (!$success && $wait <= 7200) {
            if ($as->handshake()) {
                //echo "Handshake Success\n";
                updateScrobblerResult($_SERVER['argv'][1], "Handshake Successful");
                $success = TRUE;
            } else {
                //echo "Handshake Failed (waiting $wait seconds): ".$as->getErrorMsg()."\n";
                updateScrobblerResult($_SERVER['argv'][1], "Handshake Failed: " . $as->getErrorMsg());
                sleep($wait);
                $wait = $wait * 2;
            }
        }
        $sql = "SELECT * FROM grammafone_audioscrobbler WHERE user_id=" . $_SERVER['argv'][1];
        $wait = 60;
        $success = FALSE;
        while (!$success && $wait <= 7200) {
            $result = mysql_query($sql);