private function open_popup_for_filter($current_url, $key) { $key = (string) $media_url->category_id; $doc = HD::http_get_document($current_url . '/' . $key); $pop_up_items = array(); $xml = simplexml_load_string($doc); foreach ($xml->Directory as $c) { $key = (string) $c->attributes()->key; $prompt = (string) $c->attributes()->prompt; if ($key != 'all' && $key != 'folder' && !$prompt) { $pop_up_items[] = array(GuiMenuItemDef::caption => (string) $c->attributes()->title, GuiMenuItemDef::action => ActionFactory::open_folder($this->get_right_media_url($media_url, $key), $key)); } } $action = ActionFactory::show_popup_menu($pop_up_items); }
public function get_all_folder_items(MediaURL $media_url, &$plugin_cookies) { // hd_print(__METHOD__); //hd_print(__METHOD__ . ':' . print_r($media_url, true)); $doc = HD::http_get_document(EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $media_url->category_id . '/' . $media_url->filter_name); $xml = simplexml_load_string($doc); $items = array(); $cache_keys = array(); foreach ($xml->Directory as $c) { $thumb = (string) $c->attributes()->thumb; $url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/photo/:/transcode?width=' . THUMB_WIDTH . '&height=' . THUMB_HEIGHT . '&url=' . EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $thumb; // $urlb = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . (string)$c->attributes()->thumb; // hd_print(__METHOD__ . ':EmplexerConfig::getInstance()->useCache= ' . EmplexerConfig::getInstance()->useCache . ' tipo = ' . gettype(EmplexerConfig::getInstance()->useCache)); // if (EmplexerConfig::getInstance()->useCache === 'false'){ // hd_print('Entrou.... ' ); // $url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this). $thumb; // } $bgImage = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $c->attributes()->art; $caption = (string) $c->attributes()->ratingKey . '.jpg'; if ($thumb) { EmplexerArchive::getInstance()->setFileToArchive($caption, $url); } $items[] = array(PluginRegularFolderItem::media_url => $this->get_right_media_url($media_url, $c), PluginRegularFolderItem::caption => (string) $c->attributes()->title, PluginRegularFolderItem::view_item_params => array(ViewItemParams::icon_path => EmplexerArchive::getInstance()->getFileFromArchive($caption, $url), ViewItemParams::item_detailed_icon_path => EmplexerArchive::getInstance()->getFileFromArchive($caption, $url), ViewItemParams::icon_keep_aspect_ratio => false)); } // hd_print(__METHOD__ .':'. print_r($items, true)); return $items; }
public function showPopUpMenu($url) { hd_print(__METHOD__); $doc = HD::http_get_document($url); // hd_print(print_r($doc,true)); $pop_up_items = array(); $xml = simplexml_load_string($doc); // hd_print(print_r($xml, true)); $pop_up_items = array(); foreach ($xml->Directory as $c) { $key = (string) $c->attributes()->key; $prompt = (string) $c->attributes()->prompt; hd_print("key==={$key}"); if ($key != 'all' && $key != 'folder' && !$prompt) { $pop_up_items[] = array(GuiMenuItemDef::caption => (string) $c->attributes()->title); } } $chucks = array_chunk($pop_up_items, $this->maxSize); $result = array(); $a = $this->addNextToChunk($chucks, $chucks[0], 0); hd_print('a ==== ' . print_r($a, true)); $result[] = $chucks[0]; $result[] = array(GuiMenuItemDef::is_separator => true); $result[] = array(GuiMenuItemDef::caption => $this->nextText, GuiMenuItemDef::action => ActionFactory::show_popup_menu($this->addNextToChunk($chucks, $chucks[0], 0))); $action = ActionFactory::show_popup_menu($chucks[1]); // hd_print(print_r($action, true)); // hd_print(print_r($chucks, true)); hd_print('result = ' . print_r($result, true)); return $action; }
public function get_all_folder_items(MediaURL $media_url, &$plugin_cookies) { hd_print(__METHOD__); //hd_print(__METHOD__ . ':' . print_r($media_url, true)); $doc = HD::http_get_document(EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $media_url->category_id . '/' . $media_url->filter_name); $xml = simplexml_load_string($doc); $items = array(); $cache_keys = array(); foreach ($xml->Directory as $c) { $items[] = array(PluginRegularFolderItem::media_url => $this->get_right_media_url($media_url, $c), PluginRegularFolderItem::caption => (string) $c->attributes()->title, PluginRegularFolderItem::view_item_params => array()); } hd_print(__METHOD__ . ':' . print_r($items, true)); return $items; }
public function get_all_folder_items(MediaURL $media_url, &$plugin_cookies) { // hd_print(__METHOD__); // hd_print (__METHOD__ . ':' . print_r($media_url, true)); if (!isset($media_url->filter_name)) { $doc = HD::http_get_document(EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $media_url->key); } else { $doc = HD::http_get_document(EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $media_url->key . '/' . ${$media_url}->filter_name); } // $doc = HD::http_get_document(EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $media_url->key ); $xml = simplexml_load_string($doc); $items = array(); /* TODO adicionar backgound com o art vindo do plex $bg = array( ViewParams::background_order =>'before_all', ViewParams::background_path => $bgImage ); $viewParams = PluginRegularFolderItem::view_params; array_push($view_params, $bg ); PluginRegularFolderItem::view_params => $viewParams; */ foreach ($xml->Directory as $c) { // hd_print(__METHOD__); // hd_print(__METHOD__ . ':' . print_r($xml, true)); $thumb = (string) $c->attributes()->thumb ? (string) $c->attributes()->thumb : (string) $xml->attributes()->thumb; $url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/photo/:/transcode?width=' . THUMB_WIDTH . '&height=' . THUMB_HEIGHT . '&url=' . EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $thumb; if (EmplexerConfig::getInstance()->useCache === 'false') { $url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $thumb; } // $url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) .'/photo/:/transcode?width=150&height=222&url=' . EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . (string)$c->attributes()->thumb; $urlb = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . (string) $c->attributes()->thumb; $bgImage = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . $c->attributes()->art; $ratingKey = $c->attributes()->ratingKey ? (string) $c->attributes()->ratingKey : (string) $xml->attributes()->key; $caption = $ratingKey . '.jpg'; if ($thumb) { EmplexerArchive::getInstance()->setFileToArchive($caption, $url); } $remainingEpisodes = (int) $c->attributes()->leafCount - (int) $c->attributes()->viewedLeafCount; $items[] = array(ViewParams::background_order => 'before_all', ViewParams::background_path => $bgImage, PluginRegularFolderItem::media_url => EmplexerVideoList::get_media_url_str((string) $c->attributes()->key), PluginRegularFolderItem::caption => (string) $c->attributes()->title . ' (' . (string) $remainingEpisodes . ')', PluginRegularFolderItem::view_item_params => array(ViewItemParams::icon_path => EmplexerArchive::getInstance()->getFileFromArchive($caption, $url), ViewItemParams::item_detailed_icon_path => EmplexerArchive::getInstance()->getFileFromArchive($caption, $url), ViewItemParams::item_caption_wrap_enabled => false)); } // hd_print(print_r($items, true)); return $items; }
public function handle_user_input(&$user_input, &$plugin_cookies) { hd_print(__METHOD__); hd_print(__METHOD__ . ":" . print_r($user_input, true)); if ($user_input->control_id == 'pop_up') { $media_url = MediaURL::decode($user_input->selected_media_url); $key = (string) $media_url->category_id; // hd_print("key = $key"); if ($key) { $url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $key; /*$popUp = new EmplexerPopUp(4); $action = $popUp->showPopUpMenu($url);*/ $doc = HD::http_get_document(EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this) . '/library/sections/' . $key); $pop_up_items = array(); $xml = simplexml_load_string($doc); $defaultFilter = 'all'; if ($media_url->type == 'show') { $defaultFilter = isset($plugin_cookies->defaultShowFilter) ? $plugin_cookies->defaultShowFilter : 'all'; } if ($media_url->type == 'movie') { $defaultFilter = isset($plugin_cookies->defaultMovieFilter) ? $plugin_cookies->defaultMovieFilter : 'all'; } foreach ($xml->Directory as $c) { $key = (string) $c->attributes()->key; $prompt = (string) $c->attributes()->prompt; $is_secondary = (string) $c->attributes()->secondary; if ($key != $defaultFilter && $key != 'folder' && !$prompt) { // if ($key != 'all' ){ $pop_up_items[] = array(GuiMenuItemDef::caption => (string) $c->attributes()->title, GuiMenuItemDef::action => ActionFactory::open_folder($this->get_right_media_url_for_pop_up($media_url, $key, $is_secondary != null), $key)); } } hd_print(__METHOD__ . ' pop_up_items:' . print_r($pop_up_items, true)); $action = ActionFactory::show_popup_menu($pop_up_items); // hd_print(__METHOD__ . ': ' . print_r($action, true)); return $action; } else { return null; } } if ($user_input->control_id == 'savePref') { hd_print(__METHOD__ . ':' . print_r($user_input, true)); hd_print(__METHOD__ . ':' . print_r($plugin_cookies, true)); EmplexerSetupScreen::savePreferences($user_input, $plugin_cookies); } }
public static function get_archive($id, $url_prefix) { $archive = ArchiveCache::get_archive_by_id($id); if (!is_null($archive)) { return $archive; } $version_url = $url_prefix . '/versions.txt'; try { $doc = HD::http_get_document($version_url); } catch (Exception $e) { $doc = null; } $version_by_name = array(); $total_size = 0; if (is_null($doc)) { hd_print("Failed to fetch archive versions.txt from {$version_url}."); } else { $tok = strtok($doc, "\n"); while ($tok !== false) { $pos = strrpos($tok, ' '); if ($pos === false) { hd_print("Invalid line in versions.txt for archive '{$id}'."); continue; } $name = trim(substr($tok, 0, $pos)); $version = trim(substr($tok, $pos + 1)); $version_by_name[$name] = $version; $tok = strtok("\n"); } hd_print("Archive {$id}: " . count($version_by_name) . " files."); $size_url = $url_prefix . '/size.txt'; $doc = HD::http_get_document($size_url); if (is_null($doc)) { hd_print("Failed to fetch archive size.txt from {$size_url}."); $version_by_name = array(); } else { $total_size = intval($doc); hd_print("Archive {$id}: size = {$total_size}"); } } $archive = new DefaultArchive($id, $url_prefix, $version_by_name, $total_size); ArchiveCache::set_archive($archive); return $archive; }
public function downloadToCache($fileName, $fileUrl) { if (EmplexerConfig::getInstance()->hasPersistFs) { hd_print(__METHOD__); // fwrite($this->fileDescriptor, "c|$fileName|$fileUrl"); $file_path = "/persistfs/plugins_archive/emplexer/emplexer_default_archive/{$fileName}"; // $file_path = "/D/emplexer/emplexer_default_archive/$fileName"; if (!file_exists($file_path)) { //$this->open(); // exec("echo 'c|$fileName|$fileUrl' > /tmp/emplexer.fifo"); //fwrite($this->fileDescriptor, "c|$fileName|$fileUrl\n"); //hd_print(__METHOD__ . " Escrevi com c|$fileName|$fileUrl" ); $opts = array(CURLOPT_BINARYTRANSFER => true, CURLOPT_HEADER => false); $doc = HD::http_get_document($fileUrl, $opts); $file = fopen($file_path, 'x'); fwrite($file, $doc); fclose($file); unset($doc); $doc = null; } } }
public function downLoadSubtitleFromPlex(&$user_input, &$plugin_cookies, $video_url, $languageCode = 'por') { $media_url = MediaURL::decode($user_input->selected_media_url); $base_url = EmplexerConfig::getInstance()->getPlexBaseUrl($plugin_cookies, $this); $url = $base_url . $media_url->detail_info_key; $xml = HD::getAndParseXmlFromUrl($url); $subtitleFileName = str_replace(array(".mkv", ".avi", ".mp4"), '.srt', HD::nfsUrlToSystemPath($video_url)); foreach ($xml->Video->Media->Part->Stream as $stream) { //is subtitle? //is languageCode == $languageCode? //Subtititle dosen't exists local? if ($stream->attributes()->streamType == "3" && $stream->attributes()->languageCode == $languageCode && !file_exists($subtitleFileName)) { //download the subtitle hd_print(__METHOD__ . ' não existe legenda local e existe no plex a legenda com o código: ' . $languageCode . ' vou baixar e colocar com o nome ' . $subtitleFileName); $subtitleUrl = $base_url . $stream->attributes()->key; $subData = HD::http_get_document($subtitleUrl); file_put_contents($subtitleFileName, $subData); } } }
private function fetch_document($url) { $doc = HD::http_get_document($url, $this->http_opts); // assert($doc != null). return $doc; }
/** * make the platlist and save on plugin/www */ protected function makePlayList($musics) { hd_print(__METHOD__ . ':' . print_r($musics, true)); $file = '/tmp/www/plugins/emplexer/emplexer_playlist.m3u'; $m3u = fopen($file, 'w'); fwrite($m3u, "#EXTM3U\n"); $count = 0; foreach ($musics as $key => $value) { $count++; fwrite($m3u, "#EXTINF:{$count}, {$key}\n"); fwrite($m3u, "{$value}\n"); } fclose($m3u); $playlistUrl = "http://127.0.0.1/plugins/emplexer/emplexer_playlist.m3u"; //logo a playlist só pra efeito de posterior debug hd_print(__METHOD__ . (print HD::http_get_document($playlistUrl, true))); return $playlistUrl; }
public static function getAndParseXmlFromUrl($url) { $time_start = microtime(true); $get_start = microtime(true); $doc = HD::http_get_document($url); $get_end = microtime(true); $parse_start = microtime(true); $xml = HD::parse_xml_document($doc); $parse_end = microtime(true); $time_end = microtime(true); $time = $time_end - $time_start; $get_time = $get_end - $get_start; $parse_time = $parse_end - $parse_start; hd_print(__METHOD__ . ':' . " xml obtained in {$get_time} seconds and parsed in {$parse_time} seconds total ={$time}"); return $xml; }
public function doSavePrefs(&$user_input, &$plugin_cookies) { hd_print(__METHOD__); $url = $this->base_url . "/:/plugins/" . $user_input->identifier . "/prefs/set?"; $notValidKeys = array('identifier', 'handler_id', 'control_id', 'selected_control_id', 'parent_media_url', 'selected_media_url', 'sel_ndx'); foreach ($user_input as $key => $value) { if (!in_array($key, $notValidKeys)) { $url .= "&" . $key . '=' . urlencode($value); } } $url = str_replace('?&', '?', $url); hd_print("savePref url = {$url}"); HD::http_get_document($url); }