示例#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;
 }
示例#2
0
 /**
  * get_session
  * This call the getSession method and properly updates the preferences as needed.
  * This requires a userid so it knows whose crap to update.
  */
 public function get_session($user_id, $token)
 {
     $scrobbler = new scrobbler($this->api_key, $this->scheme, $this->api_host, '', $this->secret);
     $session_key = $scrobbler->get_session_key($token);
     if (!$session_key) {
         debug_event($this->name, 'getSession Failed: ' . $scrobbler->error_msg, '3');
         return false;
     }
     $this->challenge = $session_key;
     // Update the preferences
     Preference::update('lastfm_challenge', $user_id, $session_key);
     debug_event($this->name, 'getSession Successful', '3');
     return true;
 }
        return $row;
    }
}
function updateScrobblerResult($user_id, $result)
{
    $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;
            }
        }