/** * @return X_RtmpDumpWeebTv */ public static function getInstance() { if (self::$instance === null) { self::$instance = new X_RtmpDumpWeebTv(); } return self::$instance; }
public function doStop($threadInfo) { // this should be "->shutdown()" X_RtmpDumpWeebTv::getInstance()->forceKill(); // wait few seconds sleep(2); //TODO tweak value better }
public function getLinkParams($linkId) { $channelParams = false; try { /* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */ $cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache'); $channelParams = unserialize($cacheHelper->retrieveItem("weebtv::{$linkId}")); X_Debug::i("Valid cache entry found: " . print_r($channelParams, true)); } catch (Exception $e) { // no cache plugin or no entry in cache, it's the same X_Debug::i("Cache disabled or no valid entry found"); } if (!$channelParams) { // get the cid from the page X_Debug::i("Fetching channel params for: {{$linkId}}"); $page = X_PageParser_Page::getPage(sprintf(self::URL_CHANNEL, $linkId), new X_PageParser_Parser_Preg('%<param name="movie" value="(?P<swf>.+?)" />.*?<param name="flashvars" value="&cid=(?P<cid>.+?)" />%s', X_PageParser_Parser_Preg::PREG_MATCH)); $this->preparePageLoader($page); $_channelParams = $page->getParsed(); $channelParams = array(); // clean params from useless keys foreach ($_channelParams as $key => $value) { if ($key == 'cid' || $key == 'swf') { $channelParams[$key] = $value; } } X_Debug::i("Params: " . print_r($channelParams, true)); unset($page); } $cid = @$channelParams['cid']; $swfUrl = @$channelParams['swf']; if (!$cid) { X_Debug::e("Cid not found for channel {{$linkId}}"); throw new Exception("Cid not found for channel {{$linkId}}"); } // store in cache if possible try { /* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */ $cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache'); $cacheHelper->storeItem("weebtv::{$linkId}", serialize($channelParams), 60); // store for the next 15 min X_Debug::i("Value stored in cache for 60 min: {key = weebtv::{$linkId}}"); } catch (Exception $e) { // no cache plugin, next time i have to repeat the request } // first get the playlist url from the page $authEnabled = $this->config('auth.enabled', false); $username = rawurlencode($this->config('auth.username', '')); $password = rawurlencode($this->config('auth.password', '')); $authString = ''; if ($authEnabled) { $authString = "&username={$username}&userpassword={$password}"; } // without encode $username = $this->config('auth.username', ''); $password = $this->config('auth.password', ''); $http = new Zend_Http_Client(self::URL_PARAMS . $authString, array('headers' => array('User-Agent' => 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'))); $http->setParameterPost('firstConnect', '1'); $http->setParameterPost('watchTime', '0'); $http->setParameterPost('cid', $cid); $http->setParameterPost('ip', 'NaN'); if ($authEnabled) { $http->setParameterPost('username', $username); $http->setParameterPost('password', $password); } $str = $http->request('POST')->getBody(); $params = array(); parse_str($str, $params); $rtmpParams = array(); $check = array('ticket' => 73, 'rtmp' => 10, 'time' => 16, 'playPath' => 11); foreach ($check as $label => $key) { if (isset($params[$key])) { $rtmpParams[$label] = $params[$key]; } } X_Debug::i("Fetched stream params for channel {{$linkId}}: " . print_r($rtmpParams, true)); $ticket = $rtmpParams['ticket']; if ($authEnabled) { $ticket .= ";{$username};{$password}"; } $hosterLocation = X_RtmpDumpWeebTv::buildUri(array('rtmp' => $rtmpParams['rtmp'] . '/' . $rtmpParams['playPath'], 'swfUrl' => rawurldecode($swfUrl), 'weeb' => $ticket, 'live' => '1')); X_Debug::i("Hoster location resolved: {$hosterLocation}"); return $hosterLocation; }