public function gen_afterPageBuild(X_Page_ItemList_PItem $list, Zend_Controller_Action $controller)
 {
     if (!$this->isDefaultRenderer()) {
         return;
     }
     X_Debug::i("Plugin triggered");
     $request = $controller->getRequest();
     $responseType = 'u:BrowseResponse';
     $num = count($list->getItems());
     if ($this->request['browseflag'] == 'BrowseMetadata') {
         $parentID = $this->_getParent($controller->getRequest());
         $item = new X_Page_Item_PItem('fake-item', "Container");
         $item->setLink(array_merge(array('controller' => $controller->getRequest()->getControllerName(), 'action' => $controller->getRequest()->getActionName()), $controller->getRequest()->getParams()));
         $item->setDescription("Fake description");
         $didl = X_Upnp::createMetaDIDL($item, $parentID, $num, $controller->getRequest()->getControllerName(), $controller->getRequest()->getActionName(), $controller->getRequest()->getParam('p', 'null'));
     } elseif ($this->request['browseflag'] == 'BrowseDirectChildren') {
         $parentID = $this->request['objectid'];
         $didl = X_Upnp::createDIDL($list->getItems(), $parentID, $num, $controller->getRequest()->getControllerName(), $controller->getRequest()->getActionName(), $controller->getRequest()->getParam('p', 'null'));
     }
     $xmlDIDL = $didl->saveXML();
     X_Debug::i("DIDL response: {$xmlDIDL}");
     // Build SOAP-XML reply from DIDL-XML and send it to upnp device
     $domSOAP = X_Upnp::createSOAPEnvelope($xmlDIDL, $num, $num, $responseType, $parentID);
     $soapXML = $domSOAP->saveXML();
     // turn off viewRenderer and Layout, add Content-Type and set response body
     $this->_render($soapXML, $controller);
 }
 private function _prepareVideo(X_Page_ItemList_PItem $items, Zend_Gdata_Media_Feed $feed, $locationPrefix)
 {
     foreach ($feed as $yvideo) {
         /* @var $yvideo Zend_Gdata_YouTube_VideoEntry */
         if ($yvideo->getVideoDuration() == 0) {
             continue;
         }
         // no duration = no video
         $item = new X_Page_Item_PItem('youtube-video-' . $yvideo->getVideoId(), $yvideo->getVideoTitle() . ' [' . X_Env::formatTime($yvideo->getVideoDuration()) . ']');
         $thumb = $yvideo->getVideoThumbnails();
         @($thumb = $thumb[0]['url']);
         $item->setDescription($yvideo->getVideoDescription())->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setIcon('/images/youtube/icons/video.png')->setThumbnail($thumb)->setCustom(__CLASS__ . ':location', "{$locationPrefix}/{$yvideo->getVideoId()}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$locationPrefix}/{$yvideo->getVideoId()}")), 'default', false)->setGenerator(__CLASS__);
         $items->append($item);
     }
 }
 /**
  * Fetch videos in $category and $itemPage
  */
 protected function fetchVideos(X_Page_ItemList_PItem $items, $catPage, $category, $itemPage)
 {
     // FIXME we shouldn't use paginator. We could use db for pagination
     // it's faster
     $videos = Application_Model_VideosMapper::i()->fetchByCategory($category);
     $totalPageCount = $this->helpers()->paginator()->getPages($videos);
     if ($this->helpers()->paginator()->hasPrevious($videos, $itemPage)) {
         $item = new X_Page_Item_PItem($this->getId() . '-previousvidpage', X_Env::_("p_onlinelibrary_previouspage", $itemPage - 1, $totalPageCount));
         $item->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', "{$catPage}/" . X_Env::encode($category) . "/" . ($itemPage - 1))->setLink(array('l' => X_Env::encode("{$catPage}/" . X_Env::encode($category) . "/" . ($itemPage - 1))), 'default', false);
         $items->append($item);
     }
     foreach ($this->helpers()->paginator()->getPage($videos, $itemPage) as $video) {
         /* @var $video Application_Model_Video */
         $item = new X_Page_Item_PItem($this->getId() . '-' . $video->getId(), $video->getTitle() . " [" . ucfirst($video->getHoster() . "]"));
         $item->setIcon("/images/icons/hosters/{$video->getHoster()}.png")->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$catPage}/" . X_Env::encode($category) . "/{$itemPage}/" . $video->getId())->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$catPage}/" . X_Env::encode($category) . "/{$itemPage}/" . $video->getId())), 'default', false);
         if (trim($video->getDescription()) != '') {
             $item->setDescription(trim($video->getDescription()));
         }
         if (trim($video->getThumbnail()) != '') {
             $item->setThumbnail(trim($video->getThumbnail()));
         }
         $items->append($item);
     }
     if ($this->helpers()->paginator()->hasNext($videos, $itemPage)) {
         $item = new X_Page_Item_PItem($this->getId() . '-previousvidpage', X_Env::_("p_onlinelibrary_nextpage", $itemPage + 1, $totalPageCount));
         $item->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setCustom(__CLASS__ . ':location', "{$catPage}/" . X_Env::encode($category) . "/" . ($itemPage + 1))->setLink(array('l' => X_Env::encode("{$catPage}/" . X_Env::encode($category) . "/" . ($itemPage + 1))), 'default', false);
         $items->append($item);
     }
 }
 private function _fetchVideos(X_Page_ItemList_PItem $items, $letter, $thread)
 {
     X_Debug::i("Fetching videos for {$letter}/{$thread}");
     $baseUrl = $this->config('base.url', 'http://www.jigoku.it/anime-streaming/');
     $baseUrl .= "{$thread}";
     $htmlString = $this->_loadPage($baseUrl, true);
     $dom = new Zend_Dom_Query($htmlString);
     // xpath index stars from 1
     $results = $dom->queryXpath('//div[@class="elenco"]//td[@class="serie"]/a');
     X_Debug::i("Links found: " . $results->count());
     //$found = false;
     for ($i = 0; $i < $results->count(); $i++, $results->next()) {
         $current = $results->current();
         $label = trim(trim($current->textContent), chr(0xc2) . chr(0xa0));
         if ($label == '') {
             $label = X_Env::_('p_jigoku_nonamevideo');
         }
         $href = $current->getAttribute('href');
         // href format: /anime-streaming/b-gata-h-kei/8306/episodio-2/
         @(list(, , $epId, $epName) = explode('/', trim($href, '/')));
         // works even without the $epName
         $href = "{$epId}:{$epName}";
         //$found = true;
         X_Debug::i("Valid link found: {$href}");
         $item = new X_Page_Item_PItem($this->getId() . "-{$label}", $label);
         $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$letter}/{$thread}/{$href}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$letter}/{$thread}/{$href}")), 'default', false);
         if (APPLICATION_ENV == 'development') {
             $item->setDescription("{$letter}/{$thread}/{$href}");
         }
         $items->append($item);
     }
     /*
     if (!$found) {
     	$item = new X_Page_Item_PItem($this->getId().'-ops', X_Env::_('p_animedb_opsnovideo'));
     	$item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
     		->setLink(X_Env::completeUrl(
     			//$urlHelper->url()
     		));
     	$items->append($item);
     }
     */
 }
 private function _fetchVideos(X_Page_ItemList_PItem $items, $sortType, $subType, $page, $serie, $thread)
 {
     X_Debug::i("Fetching videos for {$sortType}/{$subType}/{$page}/{$serie}/{$thread}");
     $url = $this->config('index.video.url', 'http://www.icefilms.info/membersonly/components/com_iceplayer/video.php?vid=') . $thread;
     $htmlString = $this->_loadPage($url);
     //$htmlString = str_replace(array("\n", "\r", "\t", chr(0xC2), chr(0xA0), chr(157)), '', $htmlString);
     X_Debug::i($htmlString);
     $catPattern = '/(*ANY)<div class\\=ripdiv><b>([^\\<]+)<\\/b>/';
     //$urlPattern = '/url\=http\:\/\/www.megaupload.com\/\?d\=([^\&]+)&([^\>]+)>([^\<]+)</';
     $urlPattern = '/onclick\\=\\\'go\\(([0-9]+)\\)\\\'\\>([^\\<]+)</';
     $matches = array();
     $links = array();
     if (preg_match_all($catPattern, $htmlString, $matches, PREG_OFFSET_CAPTURE)) {
         for ($i = 0; $i < count($matches[0]); $i++) {
             //$links[$matches[1][$i][0]] = array();
             $catLabel = $matches[1][$i][0];
             if (array_key_exists($i + 1, $matches[0])) {
                 if (!preg_match_all($urlPattern, substr($htmlString, $matches[0][$i][1], $matches[0][$i + 1][1] - $matches[0][$i][1]), $lMatches, PREG_SET_ORDER)) {
                     X_Debug::e("Pattern failure: {$urlPattern}");
                     continue;
                 }
             } else {
                 if (!preg_match_all($urlPattern, substr($htmlString, $matches[0][$i][1]), $lMatches, PREG_SET_ORDER)) {
                     X_Debug::e("Pattern failure: {$urlPattern}");
                     continue;
                 }
             }
             //X_Debug::i(var_export($lMatches, true));
             foreach ($lMatches as $lm) {
                 //@list(, $muId, , $label) = $lm;
                 @(list(, $muId, $label) = $lm);
                 // $muId now is a videoId of Icefilms
                 $label = "{$label} ({$catLabel})";
                 //$videoId = self::TYPE_MEGAUPLOAD.":$muId";
                 $videoId = $muId;
                 $item = new X_Page_Item_PItem($this->getId() . "-megaupload", "{$label}");
                 $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$sortType}/{$subType}/{$page}/{$serie}/{$thread}/{$videoId}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$sortType}/{$subType}/{$page}/{$serie}/{$thread}/{$videoId}")), 'default', false);
                 if (APPLICATION_ENV == 'development') {
                     $item->setDescription("{$sortType}/{$subType}/{$page}/{$serie}/{$thread}/{$videoId}");
                 }
                 $items->append($item);
             }
         }
     } else {
         X_Debug::i("Pattern failure {$catPattern} or no video found");
     }
 }
Example #6
0
 /**
  * Fill an X_Page_ItemList_PItem object ($items) with a 
  * simple list of static values
  * @param X_Page_ItemList_PItem $items
  * @param array $menuEntries an array of menu entries, keys are locations and values are label keys 
  * @param string $keyPrefix a string prepended to all items key 
  * @param string $locationPrefix a string prepended to all items location
  * @return X_Page_ItemList_PItem
  */
 static function fillStaticMenu(X_Page_ItemList_PItem $items, $menuEntries = array(), $keyPrefix = '', $locationPrefix = '')
 {
     foreach ($menuEntries as $location => $labelKey) {
         $entry = new X_Page_Item_PItem("{$keyPrefix}-{$location}", X_Env::_($labelKey));
         $entry->setDescription(APPLICATION_ENV == 'development' ? "{$locationPrefix}{$location}" : null);
         $entry->setGenerator(__METHOD__)->setIcon('/images/icons/folder_32.png')->setCustom(__METHOD__ . ":location", "{$locationPrefix}{$location}")->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setLink(array('l' => X_Env::encode("{$locationPrefix}{$location}")), 'default', false);
         $items->append($entry);
     }
     return $items;
 }
 /**
  * Add megavideo id to jdownloader download queue
  * @param string $provider
  * @param string $location
  * @param string $pid
  * @param Zend_Controller_Action $controller
  * @return X_Page_ItemList_PItem
  */
 public function getSelectionItems($provider, $location, $pid, Zend_Controller_Action $controller)
 {
     // we want to expose items only if pid is this plugin
     if ($this->getId() != $pid) {
         return;
     }
     X_Debug::i('Plugin triggered');
     $action = $controller->getRequest()->getParam("{$this->getId()}:action", '');
     /* @var $jdownloader X_VlcShares_Plugins_Helper_JDownloader */
     $jdownloader = $this->helpers('jdownloader');
     // IF action = 'start, stop or pause'
     // execute the action and return confirm, then exit
     if ($action != '') {
         try {
             if ($action == "start") {
                 $jdownloader->sendRawCommand(X_VlcShares_Plugins_Helper_JDownloader::CMD_ACTION_START);
                 $link = new X_Page_Item_PItem($this->getId() . '-started', X_Env::_('p_jdownloader_selection_started'));
                 $link->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('action' => 'share', 'pid' => null, "{$this->getId()}:action" => null), 'default', false);
                 return new X_Page_ItemList_PItem(array($link));
             }
             if ($action == "pause") {
                 $jdownloader->sendRawCommand(X_VlcShares_Plugins_Helper_JDownloader::CMD_ACTION_PAUSE);
                 $link = new X_Page_Item_PItem($this->getId() . '-started', X_Env::_('p_jdownloader_selection_paused'));
                 $link->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('action' => 'share', 'pid' => null, "{$this->getId()}:action" => null), 'default', false);
                 return new X_Page_ItemList_PItem(array($link));
             }
             if ($action == "stop") {
                 $jdownloader->sendRawCommand(X_VlcShares_Plugins_Helper_JDownloader::CMD_ACTION_STOP);
                 $link = new X_Page_Item_PItem($this->getId() . '-started', X_Env::_('p_jdownloader_selection_stopped'));
                 $link->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('action' => 'share', 'pid' => null, "{$this->getId()}:action" => null), 'default', false);
                 return new X_Page_ItemList_PItem(array($link));
             }
         } catch (Exception $e) {
             // connection problems or timeout
             $link = new X_Page_Item_PItem($this->getId() . '-error', X_Env::_('p_jdownloader_selection_error_network'));
             $link->setDescription($e->getMessage());
             $link->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('action' => 'share', 'pid' => null, "{$this->getId()}:action" => null), 'default', false);
             return new X_Page_ItemList_PItem(array($link));
         }
     } else {
         // else only confirm the addict
         /* @var $megavideo X_VlcShares_Plugins_Helper_Megavideo */
         $megavideo = $this->helpers('megavideo');
         try {
             $megavideo->getServer();
         } catch (Exception $e) {
             // not loaded location yet
             X_Debug::i("Force location loading");
             $providerObj = X_VlcShares_Plugins::broker()->getPlugins($provider);
             if ($providerObj instanceof X_VlcShares_Plugins_ResolverInterface) {
                 $providerObj->resolveLocation($location);
             }
         }
         $url = null;
         try {
             $url = "http://www.megavideo.com/?v=" . $megavideo->getId();
         } catch (Exception $e) {
             // TODO please, rewrite this piece of code
             // it's really a shame
             // let's try to get the url from the hoster
             try {
                 switch ($provider) {
                     // special cases
                     case 'onlinelibrary':
                         // hoster/id is stored inside db
                         $exploded = explode('/', $location);
                         $exploded = array_pop($exploded);
                         $video = new Application_Model_Video();
                         Application_Model_VideosMapper::i()->find($exploded, $video);
                         $hoster = $video->getHoster();
                         $videoId = $video->getIdVideo();
                         break;
                     default:
                         // we try to get information by location decoding
                         // many plugins use a /-divided location with last param in the format of HOSTER:VIDEOID
                         $exploded = explode('/', $location);
                         $exploded = array_pop($exploded);
                         $exploded = explode(':', $exploded, 2);
                         @(list($hoster, $videoId) = $exploded);
                         break;
                 }
                 // lets search a valid hoster
                 $url = $this->helpers()->hoster()->getHoster($hoster)->getHosterUrl($videoId);
             } catch (Exception $e) {
                 // simply: provider isn't compatible
                 // trying direct download
                 $pObj = X_VlcShares_Plugins::broker()->getPlugins($provider);
                 if ($pObj instanceof X_VlcShares_Plugins_ResolverInterface) {
                     $url = $pObj->resolveLocation($location);
                     if (!X_Env::startWith($url, "http://") && !X_Env::startWith($url, "https://")) {
                         // not valid, revert changes
                         $url = null;
                     }
                 }
             }
         }
         try {
             if ($url === null) {
                 throw new Exception();
             }
             X_Debug::i("Appending {{$url}} to the queue");
             $jdownloader->addLink($url);
             $link = new X_Page_Item_PItem($this->getId() . '-added', X_Env::_('p_jdownloader_selection_added'));
         } catch (Zend_Http_Client_Adapter_Exception $e) {
             // connection problems or timeout
             $link = new X_Page_Item_PItem($this->getId() . '-error', X_Env::_('p_jdownloader_selection_error_network'));
             $link->setDescription($e->getMessage());
         } catch (Exception $e) {
             // wrapper/other error
             X_Debug::e("Trying to add a new download to JDowloader, but location isn't a megavideo url or there is an error");
             $link = new X_Page_Item_PItem($this->getId() . '-error', X_Env::_('p_jdownloader_selection_error_invalid'));
             $link->setDescription($e->getMessage());
         }
         $link->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setLink(array('action' => 'mode', $this->getId() => null, 'pid' => null), 'default', false);
         return new X_Page_ItemList_PItem(array($link));
     }
 }
 private function _fetchVideos(X_Page_ItemList_PItem $items, $resourceType, $pageN, $resourceGroup, $resourceId)
 {
     X_Debug::i("Fetching videos for {$resourceType}, {$pageN}, {$resourceGroup}, {$resourceId}");
     // as first thing we have to recreate the resource url from resourceId
     $url = sprintf(self::URL_BASE, $resourceId);
     $page = X_PageParser_Page::getPage($url, X_PageParser_Parser_StreamingOnlineVideos::instance());
     $this->preparePageLoader($page);
     foreach ($page->getParsed() as $link) {
         $videoId = $link['videoId'];
         $hosterId = $link['hosterId'];
         $videoCode = $link['link'];
         $videoLabel = trim("{$link['label']} [{$link['hosterId']}]");
         //$videoThumb = $link['thumbnail'];
         $item = new X_Page_Item_PItem("{$this->getId()}-hoster-{$hosterId}-{$videoId}", $videoLabel);
         $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$resourceType}/{$pageN}/{$resourceGroup}/{$resourceId}/{$videoCode}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$resourceType}/{$pageN}/{$resourceGroup}/{$resourceId}/{$videoCode}")), 'default', false);
         if (APPLICATION_ENV == 'development') {
             $item->setDescription("{$resourceType}/{$pageN}/{$resourceGroup}/{$resourceId}/{$videoCode}");
         }
         /*
         if ( $videoThumb ) {
         	$item->setThumbnail($videoThumb);
         }
         */
         $items->append($item);
     }
 }
Example #9
0
 protected function getDisableCacheButton()
 {
     $link = new X_Page_Item_PItem('core-cache-disable', X_Env::_('p_cache_disablebutton', date('d/m/Y H:i', $this->inCache->getCreated())));
     $link->setDescription(X_Env::_('p_cache_disablebutton_desc'))->setType(X_Page_Item_PItem::TYPE_CONTAINER)->setLink(array($this->getId() => '0'), 'default', false);
     return $link;
 }
 private function _fetchVideos(X_Page_ItemList_PItem $items, $resourceType, $resourceGroup, $page, $resourceId)
 {
     X_Debug::i("Fetching videos for {$resourceType}, {$resourceGroup}, {$page}, {$resourceId}");
     // as first thing we have to recreate the resource url from resourceId
     $url = self::URL_BASE;
     // in _fetchResources we converted / in : inside $resourceId and removed the last /
     // so to come back to the real address we have to undo this changes
     $url .= str_replace(':', '/', $resourceId) . '/';
     // now url is something like http://film-stream.tv/01/01/2010/resource-name/
     // loading page
     $htmlString = $this->_loadPage($url);
     // it's useless to execute pattern search in the whole page
     // so we stip from $htmlString only the usefull part
     $mainContentStart = '<div id="maincontent">';
     $mainContentEnd = '<div id="sidebar">';
     $mainContentStart = strpos($htmlString, $mainContentStart);
     if ($mainContentStart === false) {
         $mainContentStart = 0;
     }
     $mainContentEnd = strpos($htmlString, $mainContentEnd, $mainContentStart);
     // substr get a substring of $htmlString from $mainContentStart position to $mainContentEnd position - $mainContentStart position (is the fragment length)
     $htmlString = $mainContentEnd === false ? substr($htmlString, $mainContentStart) : substr($htmlString, $mainContentStart, $mainContentEnd - $mainContentStart);
     // let's define some pattern
     // $ytPattern will try to intercept
     // youtube trailer link
     // <param name="movie" value="http://www.youtube.com/v/VIDEOID?version=3">
     // match[1] = video id
     $ytPattern = '/<param name\\=\\"movie\\" value\\=\\"http\\:\\/\\/www\\.youtube\\.com\\/v\\/([^\\?\\"\\&]+)([^\\>]*)>/';
     $matches = array();
     // first let's search for youtube videos
     if (preg_match_all($ytPattern, $htmlString, $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $videoId = self::VIDEO_YOUTUBE . ':' . $match[1];
             $videoLabel = X_Env::_("p_filmstream_video_youtubetrailer");
             $item = new X_Page_Item_PItem("{$this->getId()}-youtube-{$videoId}", $videoLabel);
             $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$resourceType}/{$resourceGroup}/{$page}/{$resourceId}/{$videoId}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$resourceType}/{$resourceGroup}/{$page}/{$resourceId}/{$videoId}")), 'default', false);
             if (APPLICATION_ENV == 'development') {
                 $item->setDescription("{$resourceType}/{$resourceGroup}/{$page}/{$resourceId}/{$videoId}");
             }
             $items->append($item);
         }
     } else {
         X_Debug::e("Youtube pattern failure {{$ytPattern}}");
     }
     $matches = array();
     if (preg_match_all('/href\\=\\"(?P<LINK>[^\\"]+)"([^\\>]*)>(?P<LABEL>[^\\<]+)<\\/a>/', $htmlString, $matches, PREG_SET_ORDER)) {
         X_Debug::i(var_export($matches, true));
         foreach ($matches as $match) {
             try {
                 $link = $match['LINK'];
                 $hoster = $this->helpers()->hoster()->findHoster($link);
                 $videoLabel = trim(strip_tags($match['LABEL'])) . " [" . ucfirst($hoster->getId()) . "]";
                 $videoId = "{$hoster->getId()}:{$hoster->getResourceId($link)}";
                 $item = new X_Page_Item_PItem("{$this->getId()}-hoster-{$videoId}", $videoLabel);
                 $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$resourceType}/{$resourceGroup}/{$page}/{$resourceId}/{$videoId}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$resourceType}/{$resourceGroup}/{$page}/{$resourceId}/{$videoId}")), 'default', false);
                 if (APPLICATION_ENV == 'development') {
                     $item->setDescription("{$resourceType}/{$resourceGroup}/{$page}/{$resourceId}/{$videoId}");
                 }
                 $items->append($item);
             } catch (Exception $e) {
                 // no hoster for the link, skipped
             }
         }
     } else {
         X_Debug::e("General pattern failure");
     }
 }
 private function _fetchVideos(X_Page_ItemList_PItem $items, $type, $letter, $thread)
 {
     X_Debug::i("Fetching videos for {$type}/{$letter}/{$thread}");
     if ($type == self::TYPE_SERIES_PERGENRE || $type == self::TYPE_SERIES_PERLETTER) {
         return $this->_fetchVideosAPI($items, $type, $letter, $thread);
     }
     $baseUrl = $this->config('base.url', self::BASE_URL);
     // threads for movies have / -> : conversion
     $_thread = str_replace(':', '/', $thread);
     $baseUrl .= "{$type}/{$_thread}";
     $htmlString = $this->_loadPage($baseUrl, true);
     // XPATH doesn't work well. Maybe for kanji inside the page, so i use regex
     $cleaned = stristr(strstr($htmlString, 'Episodes:'), '</table>', true);
     $regexp = "<a\\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\\/a>";
     if (preg_match_all("/{$regexp}/siU", $cleaned, $matches, PREG_SET_ORDER)) {
         //X_Debug::i(var_export($matches, true));
         foreach ($matches as $match) {
             // $match[2] = link address
             // $match[3] = link text
             $label = $match[3];
             if ($label == '') {
                 $label = X_Env::_('p_animeftw_nonamevideo');
             }
             $href = $match[2];
             // href format: http://www.animeftw.tv/videos/baccano/ep-3
             if (X_Env::startWith($href, $this->config('base.url', self::BASE_URL))) {
                 $href = substr($href, strlen($this->config('base.url', self::BASE_URL)));
             }
             // href format: videos/baccano/ep-3
             @(list(, , $epName) = explode('/', trim($href, '/')));
             // works even without the $epName
             $href = $epName;
             //$found = true;
             X_Debug::i("Valid link found: {$href}");
             $item = new X_Page_Item_PItem($this->getId() . "-{$label}", $label);
             $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$type}/{$letter}/{$thread}/{$href}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$type}/{$letter}/{$thread}/{$href}")), 'default', false);
             if (APPLICATION_ENV == 'development') {
                 $item->setDescription("{$type}/{$letter}/{$thread}/{$href}");
             }
             $items->append($item);
         }
     }
 }
 /**
  * Find links using an alternative way
  * @author Valerio Moretti
  */
 private function _parseAlternativeScaper($htmlString, X_Page_ItemList_PItem $items, $category, $letter, $thread)
 {
     //mi suddivido il post in righe
     $htmlRows = explode('<br />', $htmlString);
     /*
     //qua volevo selezionarmi solo il codice del post per rendere il tutto piu' veloce
     //pero' sbaglio qualcosa e non mi funziona
     
     $dom = new Zend_Dom_Query($htmlString);
     $content = $dom->queryXpath('//ol[@id="posts"]/li[1]//div[@class="content"]');
     $htmlPost = $content->current();
     
     $htmlRows = explode('<br />', $htmlPost);
     */
     //analizzo riga per riga
     foreach ($htmlRows as $row) {
         //la mia ignoranza del Xpath e' immensa e questo e' l'unico modo che ho trovato per farlo funzionare
         $row = '<root>' . $row . '</root>';
         $dom = new Zend_Dom_Query($row);
         // xpath index stars from 1
         $results = $dom->queryXpath('//a');
         X_Debug::i("Links found: " . $results->count());
         $found = false;
         $title = '';
         //il testo del primo link della riga
         for ($i = 0; $i < $results->count(); $i++, $results->next()) {
             $current = $results->current();
             $label = trim(trim($current->nodeValue), chr(0xc2) . chr(0xa0));
             if ($label == '') {
                 $label = X_Env::_('p_animedb_nonamevideo');
             }
             if ($title == '') {
                 $title = $label;
             }
             $href = $current->getAttribute('href');
             try {
                 $hoster = $this->helpers()->hoster()->findHoster($href);
             } catch (Exception $e) {
                 // no hoster = no valid href
                 continue;
             }
             $href = "{$hoster->getId()}:{$hoster->getResourceId($href)}";
             $label = $label == $title ? $label : $title . ' | ' . $label;
             $label .= " [" . ucfirst($hoster->getId()) . "]";
             $found = true;
             X_Debug::i("Valid link found: {$href}");
             $item = new X_Page_Item_PItem($this->getId() . "-{$label}", $label);
             $item->setIcon('/images/icons/folder_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$category}/{$letter}/{$thread}/{$href}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$category}/{$letter}/{$thread}/{$href}")), 'default', false);
             if (APPLICATION_ENV == 'development') {
                 $item->setDescription("{$category}/{$letter}/{$thread}/{$href}");
             }
             $items->append($item);
         }
     }
 }
 private function _fetchVideos(X_Page_ItemList_PItem $items, $sortType, $subType, $page, $thread)
 {
     X_Debug::i("Fetching videos for {$sortType}/{$subType}/{$page}/{$thread}");
     $url = $this->config('index.video.url', 'http://www.gogocinema.com/movie.php?movie_id=') . $thread;
     $htmlString = $this->_loadPage($url);
     $htmlString = str_replace(array("\n", "\r", "\t", chr(0xc2), chr(0xa0), chr(157)), '', $htmlString);
     //X_Debug::i($htmlString);
     //$megavideoPattern = '/href\=\"http:\/\/megavideo\.com\/\?([^\"]+)\" /';
     //$megavideoPattern = '/<tr bgcolor\=\"#043F6E\"><td>\# ([^\"]+)\<\/td><\/tr><tr><td align\=\"center\"><a style\=\"color\:\#FFFFFF\;\" href\=\"http:\/\/megavideo\.com\/\?([^\"]+)\" target\=\"\_blank\">/';
     //$youtubePattern = '/<tr bgcolor\=\"#043F6E\"><td>\# ([^\"]+)\<\/td><\/tr><tr><td align\=\"center\"><a style\=\"color\:\#FFFFFF\;\" href\=\"http\:\/\/youtube\.com\/watch\?v\=([^\"]+)\" target\=\"\_blank\">/';
     $globalPattern = '/<tr bgcolor\\=\\"#043F6E\\"><td>\\# (?P<label>[^\\"]+)\\<\\/td><\\/tr><tr><td align\\=\\"center\\"><a style\\=\\"color\\:\\#FFFFFF\\;\\" href\\=\\"(?P<link>[^\\"]+)\\" target\\=\\"\\_blank\\">/';
     $movietitlePattern = '/<td class\\=\\"movietitle\\" colspan \\= \\"3\\"><a href\\=\\"movie\\.php\\?movie_id=([^\\"]+)\\" style=\\"color\\:\\#E95C24\\;\\">([^\\"]+)<\\/a>/';
     $matches = array();
     if (preg_match($movietitlePattern, $htmlString, $matches)) {
         $movieTitle = "{$matches[2]}: ";
     } else {
         $movieTitle = '';
     }
     $matches = array();
     if (preg_match_all($globalPattern, $htmlString, $matches, PREG_SET_ORDER)) {
         X_Debug::i("Megavideo videos found: " . count($matches));
         X_Debug::i(var_export($matches, true));
         foreach ($matches as $video) {
             //@list(,$label, $videoId) = $video;
             $label = $video['label'];
             $link = $video['link'];
             try {
                 $hoster = $this->helpers()->hoster()->findHoster($link);
                 $label = strip_tags($label) . " [" . ucfirst($hoster->getId()) . "]";
                 //$videoId = self::TYPE_MEGAVIDEO.":$videoId";
                 $videoId = "{$hoster->getId()}:{$hoster->getResourceId($link)}";
                 $item = new X_Page_Item_PItem($this->getId() . "-{$hoster->getId()}", "{$movieTitle}{$label}");
                 $item->setIcon('/images/icons/file_32.png')->setType(X_Page_Item_PItem::TYPE_ELEMENT)->setCustom(__CLASS__ . ':location', "{$sortType}/{$subType}/{$page}/{$thread}/{$videoId}")->setLink(array('action' => 'mode', 'l' => X_Env::encode("{$sortType}/{$subType}/{$page}/{$thread}/{$videoId}")), 'default', false);
                 if (APPLICATION_ENV == 'development') {
                     $item->setDescription("{$sortType}/{$subType}/{$page}/{$thread}/{$videoId}");
                 }
                 $items->append($item);
             } catch (Exception $e) {
                 // no valid hoster for this link
             }
         }
     } else {
         X_Debug::i("Megavideo videos NOT found: " . var_export($matches, true));
         X_Debug::i("No megavideo links found");
     }
     /*
     $matches = array();
     if ( preg_match_all($youtubePattern, $htmlString, $matches, PREG_SET_ORDER) ) {
     	X_Debug::i("Youtube videos found: ".count($matches));
     	
     	foreach ($matches as $video) {
     		
     		@list(,$label,$videoId) = $video;
     		
     		$label = strip_tags($label);
     		$videoId = self::TYPE_YOUTUBE.":$videoId";
     		
     		$item = new X_Page_Item_PItem($this->getId()."-youtube", "$movieTitle$label");
     		$item->setIcon('/images/icons/file_32.png')
     			->setType(X_Page_Item_PItem::TYPE_ELEMENT)
     			->setCustom(__CLASS__.':location', "$sortType/$subType/$page/$thread/$videoId")
     			->setLink(array(
     				'action'	=> 'mode',
     				'l'	=>	X_Env::encode("$sortType/$subType/$page/$thread/$videoId")
     			), 'default', false);
     			
     		if ( APPLICATION_ENV == 'development' ) {
     			$item->setDescription("$sortType/$subType/$page/$thread/$videoId");
     		}
     			
     		$items->append($item);
     		
     	}
     	
     }
     */
 }