require_once GSAPI_DIR . 'gsAPI.php';
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;
Beispiel #2
0
<?php

session_start();
// Make sure to validate and cleanse this and stuff.
$songID = $_POST['song'];
// Load up API wrapper
require "gsAPI.php";
$gsapi = new gsAPI('API-USERNAME', 'API-KEY');
gsAPI::$headers = array("X-Client-IP: " . $_SERVER['REMOTE_ADDR']);
// Session caching stuff
if (isset($_SESSION['gsSession']) && !empty($_SESSION['gsSession'])) {
    $gsapi->setSession($_SESSION['gsSession']);
} else {
    $_SESSION['gsSession'] = $gsapi->startSession();
}
if (!$_SESSION['gsSession']) {
    die("noSession");
}
if (isset($_SESSION['gsCountry']) && !empty($_SESSION['gsCountry'])) {
    $gsapi->setCountry($_SESSION['gsCountry']);
} else {
    $_SESSION['gsCountry'] = $gsapi->getCountry();
}
if (!$_SESSION['gsCountry']) {
    die("noCountry");
}
// Make request to Grooveshark and return data as JSON
$streamInfo = $gsapi->getStreamKeyStreamServer($songID, false);
echo json_encode($streamInfo);