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);
            $songs = array();
            if (mysql_num_rows($result) > 0) {
                $now = time();
                while ($row = mysql_fetch_array($result)) {
                    $song = getSongInfo($row['song_id']);
                    $songs[] = $row['as_id'];