/** * Download an url or retrieving from local file cache * * @param $url * @param array $options * @return array */ public function getContent($url, $options = []) { \App::dispatchEvent('download_cache_miss', ['url' => $url, 'options' => $options]); curl_setopt($this->_curl, CURLOPT_URL, $url); $content = curl_exec($this->_curl); return $content; }
public function fetchPlaylist($url) { $foundItems = []; $downloader = \App::getDownloader(); $page = $downloader->getCacheContent($url, ['prefix' => '/html', 'suffix' => '.html', 'gzip' => 1]); $document = \phpQuery::newDocument($page); $matches = $document->find('.item-song a.fn-name'); foreach ($matches as $item) { $href = pq($item)->attr('href'); $songItems = $this->fetchSong($href); if (count($songItems) > 0) { $item = $songItems[0]; $foundItems[] = $item; \App::dispatchEvent('playlist_fetch_song', array('id' => count($foundItems), 'item' => $item)); } } //\phpQuery::unloadDocuments(); return $foundItems; }
public function fetchPlaylist($url) { $foundItems = []; $downloader = \App::getDownloader(); $page = $downloader->getContent($url); $document = \phpQuery::newDocument($page); $metaTitle = $document->find('meta[property="og:title"]'); \App::dispatchEvent('playlist_fetch', array('title' => $metaTitle->attr("content"))); $matches = $document->find('.item-song a.fn-name'); foreach ($matches as $item) { $href = pq($item)->attr('href'); $songItems = $this->fetchSong($href); if (count($songItems) > 0) { $songItem = $songItems[0]; $foundItems[] = $songItem; \App::dispatchEvent('playlist_fetch_song', array('id' => count($foundItems), 'item' => $songItem)); } } //\phpQuery::unloadDocuments(); return $foundItems; }
public function testEvent() { App::registerEvent('testEvent', array($this, 'sampleEventHandler')); App::dispatchEvent('testEvent', array('var1' => 1, 'var2' => 2)); }