public function testAction() { $this->doNotRender(); set_time_limit(0); ini_set('memory_limit', '-1'); Debug::setEchoMode(); Debug::log('Donezo!'); }
/** * Individual Record Fetching (Retired) */ public static function fetch(Song $song) { $base_url = 'https://pony.fm/api/v1/tracks/radio-details/'; $song_hash = self::_getHash($song); $url = $base_url . $song_hash . '?client=ponyvillelive'; \PVL\Debug::log('Hash Search: ' . $url); $result_raw = @file_get_contents($url); if ($result_raw) { $result = json_decode($result_raw, TRUE); \PVL\Debug::print_r($result); return $result; } return NULL; }
public function testAction() { $this->doNotRender(); set_time_limit(0); ini_set('memory_limit', '-1'); Debug::setEchoMode(); // -------- START HERE -------- // \PVL\CentovaCast::sync(); Debug::log('CCast Sync Complete'); $station = \Entity\Station::getRepository()->findOneBy(array('name' => 'PonyvilleFM')); $tracks = \PVL\CentovaCast::fetchTracks($station); Debug::print_r($tracks); // -------- END HERE -------- // Debug::log('Done!'); }
protected static function _querySearch($song) { $base_url = 'https://eqbeats.org/tracks/search/json'; $url = $base_url . '?' . http_build_query(array('q' => $song->artist . ' ' . $song->title, 'client' => 'ponyvillelive')); Debug::log('Query Search: ' . $url); $result = file_get_contents($url); if ($result) { $rows = json_decode($result, TRUE); foreach ($rows as $row) { $song_hash = Song::getSongHash(array('artist' => $row['user']['name'], 'title' => $row['title'])); if (strcmp($song_hash, $song->id) == 0) { return $row; } } } return NULL; }
/** * Process a podcast source and return remote data from it. * * @return array|bool */ public function process() { Debug::log('Processing source: ' . $this->type); $source_info = self::getSourceInfo($this->type); if (!isset($source_info['adapter'])) { Debug::log('No suitable adapter found!'); return FALSE; } $source_settings = isset($source_info['settings']) ? $source_info['settings'] : array(); // Look for new news items. $class_name = '\\PVL\\NewsAdapter\\' . $source_info['adapter']; $news_items = $class_name::fetch($this->url, $source_settings); if (empty($news_items)) { Debug::log('No news items found! Adapter: ' . $class_name); return FALSE; } $new_episodes = array(); foreach ((array) $news_items as $item) { $guid = $item['guid']; $new_episodes[$guid] = array('guid' => $guid, 'timestamp' => $item['timestamp'], 'title' => self::cleanUpText($item['title']), 'body' => self::cleanUpText($item['body']), 'summary' => self::getSummary($item['body']), 'web_url' => $item['web_url'], 'thumbnail_url' => isset($item['thumbnail_url']) ? $item['thumbnail_url'] : NULL, 'banner_url' => isset($item['banner_url']) ? $item['banner_url'] : NULL); } Debug::print_r($new_episodes); return $new_episodes; }
/** * Process a single video stream's NowPlaying info. * * @param StationStream $stream * @param Station $station * @return array Structured NowPlaying Data */ public static function processVideoStream(StationStream $stream, Station $station, $force = false) { $current_np_data = (array) $stream->nowplaying_data; if (!$force && NOWPLAYING_SEGMENT % 2 == 0 && !empty($current_np_data)) { return $current_np_data; } // Process stream. $custom_class = Station::getStationClassName($station->name); $custom_adapter = '\\PVL\\VideoAdapter\\' . $custom_class; $np = StationStream::api($stream); if (class_exists($custom_adapter)) { $np_adapter = new $custom_adapter($stream, $station); $stream_np = $np_adapter->process(); } else { $adapters = array(new \PVL\VideoAdapter\Livestream($stream, $station), new \PVL\VideoAdapter\TwitchTv($stream, $station), new \PVL\VideoAdapter\UStream($stream, $station), new \PVL\VideoAdapter\StreamUp($stream, $station)); foreach ($adapters as $np_adapter) { if ($np_adapter->canHandle()) { $stream_np = $np_adapter->process(); break; } } } if (!empty($stream_np)) { $np = array_merge($np, $stream_np); $np['status'] = isset($np['meta']['status']) ? $np['meta']['status'] : 'offline'; Debug::log('Adapter Class: ' . get_class($np_adapter)); Debug::print_r($np); } else { $np['on_air'] = array('text' => 'Stream Offline'); $np['meta'] = array('status' => 'offline', 'listeners' => 0); $np['status'] = 'offline'; } $stream->nowplaying_data = $np; return $np; }
public function syncAction() { $this->acl->checkPermission('administer all'); $this->doNotRender(); \PVL\Debug::setEchoMode(TRUE); \PVL\Debug::startTimer('sync_task'); $type = $this->getParam('type', 'nowplaying'); switch ($type) { case "long": \PVL\SyncManager::syncLong(); break; case "medium": \PVL\SyncManager::syncMedium(); break; case "short": \PVL\SyncManager::syncShort(); break; case "nowplaying": default: $segment = $this->getParam('segment', 1); define('NOWPLAYING_SEGMENT', $segment); \PVL\SyncManager::syncNowplaying(true); break; } \PVL\Debug::endTimer('sync_task'); \PVL\Debug::log('Sync task complete. See log above.'); }
/** * Submit a URL request with a specified cache lifetime. * * @param null $c_opts * @param int $cache_time * @return string */ public static function request($c_opts = null) { // Compose cURL configuration array. if (is_null($c_opts)) { $c_opts = array(); } elseif (!is_array($c_opts)) { $c_opts = array('url' => $c_opts); } $c_defaults = array('method' => 'GET', 'useragent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2', 'timeout' => 10); $c_opts = array_merge($c_defaults, $c_opts); Debug::log('cURL Outgoing Request: ' . $c_opts['url']); Debug::startTimer('Make cURL Request'); $postfields = false; if (!empty($c_opts['params'])) { if (strtoupper($c_opts['method']) == 'POST') { $postfields = $c_opts['params']; } else { $c_opts['url'] = $c_opts['url'] . '?' . http_build_query($c_opts['params']); } } // Start cURL request. $curl = curl_init($c_opts['url']); // Handle POST support. if (strtoupper($c_opts['method']) == 'POST') { curl_setopt($curl, CURLOPT_POST, true); } if (!empty($c_opts['referer'])) { curl_setopt($curl, CURLOPT_REFERER, $c_opts['referer']); } if ($postfields) { curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $c_opts['timeout']); curl_setopt($curl, CURLOPT_TIMEOUT, $c_opts['timeout']); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_USERAGENT, $c_opts['useragent']); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($curl, CURLOPT_MAXREDIRS, 3); // Custom DNS management. curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($curl, CURLOPT_DNS_CACHE_TIMEOUT, 600); // Set custom HTTP headers. if (!empty($c_opts['headers'])) { curl_setopt($curl, CURLOPT_HTTPHEADER, $c_opts['headers']); } $return_raw = Utilities::curl_exec_utf8($curl); // End cURL request. Debug::endTimer('Make cURL Request'); // Log more detailed information to screen about resolution times. $conn_info = curl_getinfo($curl); $important_conn_info = array('url', 'http_code', 'total_time', 'namelookup_time', 'connect_time', 'pretransfer_time', 'starttransfer_time', 'redirect_time'); $debug_conn_info = array(); foreach ($important_conn_info as $conn_param) { $debug_conn_info[$conn_param] = $conn_info[$conn_param]; } Debug::print_r($debug_conn_info); $error = curl_error($curl); if ($error) { Debug::log("Curl error: " . $error); } return trim($return_raw); }