public function authenticateUser(gsUser $user)
 {
     if (!$this->session) {
         if (!$this->startSession()) {
             return false;
         }
     }
     if (!$user->getUsername() && !$user->getEmail() || !$user->getToken()) {
         return false;
     }
     $return = self::apiCall('authenticate', array('login' => $user->getUsername() ? $user->getUsername() : $user->getEmail(), 'password' => $user->getToken(), 'sessionID' => $this->session), true);
     if (isset($return['decoded']['result']['UserID']) && $return['decoded']['result']['UserID'] > 0) {
         $user->importUserData($return['decoded']['result']);
         $this->sessionUserid = $user->getUserID();
         return $user;
     } else {
         gsAPI::$lastError = $return['raw'];
         return false;
     }
 }
require_once GSAPI_DIR . 'gsUser.php';
$stationsresult = $GFM_MySQLi->query("SELECT id, callsign, playlistname, playlistid FROM stations WHERE enabled = 1");
$stations = array();
while ($station = $stationsresult->fetch_assoc()) {
    $stations[] = $station;
}
$stationsresult->free();
$songs = $GFM_MySQLi->prepare("SELECT songid FROM playlists WHERE station = ? ORDER BY id DESC LIMIT " . PLAYLIST_LIMIT);
$songs->bind_param('i', $stationid);
$songs->bind_result($songid);
$updateplaylistid = $GFM_MySQLi->prepare("UPDATE stations SET playlistid = ? WHERE id = ? LIMIT 1");
$updateplaylistid->bind_param('ii', $playlistid, $stationid);
$GSAPI = new gsAPI(GS_WS_KEY, GS_SECRET);
$GSAPI->startSession();
$GSAPI->getCountry('208.94.117.100');
$GSUser = new gsUser();
$GSUser->setUsername(GS_USERNAME);
$GSUser->setTokenFromPassword(GS_PASSWORD);
if (!$GSUser->authenticate()) {
    die('Authentication failed!');
}
foreach ($stations as $station) {
    echo PHP_EOL, 'Updating station ', $station['callsign'], PHP_EOL;
    $stationid = $station['id'];
    $songs->execute();
    $songsarray = array();
    while ($songs->fetch()) {
        $songsarray[] = $songid;
    }
    echo 'SongIDs: ', implode(', ', $songsarray), PHP_EOL;
    $playlistid = $station['playlistid'];