public static function getAlbumSearchResultsWithSongs($query, $limit = null, $page = null) { if (empty($query)) { return false; } $return = self::apiCall('getAlbumSearchResults', array('query' => $query, 'limit' => $limit, 'page' => $page)); if (isset($return['decoded']['result']['albums'])) { foreach ($return['decoded']['result']['albums'] as &$albm) { $albm['Songs'] = self::getAlbumSongs($albm['AlbumID']); $albm['SongCount'] = count($albm['Songs']); } return $return['decoded']['result']['albums']; } else { gsAPI::$lastError = $return['raw']; return false; } }
public function markSongComplete($songID, $streamKey, $streamServerID) { if (!$songID) { trigger_error(__FUNCTION__ . " requires a valid songID.", E_USER_ERROR); } if (!$streamKey) { trigger_error(__FUNCTION__ . " requires a valid streamKey.", E_USER_ERROR); } if (!$streamServerID) { trigger_error(__FUNCTION__ . " requires a valid streamServerID.", E_USER_ERROR); } if (!$this->session) { trigger_error(__FUNCTION__ . " requires a valid session. No session was found.", E_USER_ERROR); } $return = self::apiCall('markSongComplete', array('songID' => $songID, 'streamKey' => $streamKey, 'streamServerID' => $streamServerID, 'sessionID' => $this->session)); if (isset($return['decoded']['result']['success']) && $return['decoded']['result']['success']) { return $return['decoded']['result']; } else { gsAPI::$lastError = $return['raw']; return false; } }
public static function addClientIP($ip = null) { if (empty($ip)) { $ip = $_SERVER['REMOTE_ADDR']; } if (empty(self::$headers)) { self::$headers = array("X-Client-IP: " . $ip); } else { $newHeaders = array(); foreach (self::$headers as $header) { if (strpos($header, 'X-Client-IP:') !== 0) { $newHeaders[] = $header; } } $newHeaders[] = "X-Client-IP: " . $ip; self::$headers = $newHeaders; } }
<?php header('Content-Type: text/plain'); require_once INCLUDES_DIR . 'cron_security.inc.php'; ob_start(); require_once INCLUDES_DIR . 'mysql.inc.php'; include_once GSAPI_DIR . 'gsAPI.php'; echo 'Pruning of playlist songs starting at ', date('r'), PHP_EOL; $select = $GFM_MySQLi->query('SELECT `songid` FROM `playlists`'); $songids = array(); while ($songid = $select->fetch_row()) { $songids[] = $songid[0]; } $select->free(); $delete = $GFM_MySQLi->prepare('DELETE FROM `playlists` WHERE `songid` = ?'); $delete->bind_param('i', $songid); $GSAPI = new gsAPI(GS_WS_KEY, GS_SECRET); $goodsongids = $GSAPI->getSongsInfo($songids, true); if (count($goodsongids) < 1) { echo 'No songs returned from Grooveshark! Aborting'; } else { echo "Song ID's to delete:", PHP_EOL; foreach ($songids as $songid) { if (!array_key_exists($songid, $goodsongids)) { echo $songid, PHP_EOL; $delete->execute(); } } } file_put_contents(LOGS_DIR . 'prunetables.log', ob_get_contents()); ob_end_flush();
private static function performSearch($method, $query, $country = null, $max = null) { $results = array(); for ($page = 1; $page <= 2; $page++) { switch ($method) { case "getSongSearchResults": $searchResults = parent::getSongSearchResults($query, $country, $max ? $max : 91, ($page - 1) * 90); break; case "getArtistSearchResults": case "getAlbumSearchResults": $searchResults = call_user_func(array(parent::getInstance(), $method), $query, $max ? $max : 91, ($page - 1) * 90); break; default: return false; break; } if ($searchResults === false || count($searchResults) < 1) { break; } if (count($searchResults) > 90 && (!$max || $max > 100)) { array_pop($searchResults); //we need to check if there are more results } self::appendResults($searchResults, $results); if (count($searchResults) < 90 || $max && count($results) > $max) { break; } } if ($max) { return array_slice($results, 0, $max, true); } else { return $results; } }
private function getUserIDFromUsername($username = null) { if ($username) { $this->setUsername($username); } if ($this->getUsername()) { $return = parent::apiCall('getUserIDFromUsername', array('username' => $this->getUsername())); if (isset($return['decoded']['result']['UserID'])) { $this->setUserID((int) $return['decoded']['result']['UserID']); return $this->userid; } else { return false; } } else { return false; } }
echo 'Update Playlists cron starting at ', date('r'), PHP_EOL; require_once INCLUDES_DIR . 'mysql.inc.php'; 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;
<?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);
public function getSongs($fetch = true) { if ($this->songs || !$fetch) { return $this->songs; } $this->songs = parent::getPlaylistSongs($this->getPlaylistID()); return $this->songs; }