Ejemplo n.º 1
0
 private function getLinkByRecId($rec_id)
 {
     $item = self::getById($rec_id);
     $master = new StreamRecorder();
     try {
         $res = $master->play($rec_id, 0, false, $item['storage_name']);
     } catch (Exception $e) {
         trigger_error($e->getMessage());
     }
     $res['local'] = 0;
     if (!empty($res['cmd'])) {
         preg_match("/\\.(\\w*)\$/", $res['cmd'], $ext_arr);
         $res['to_file'] = System::transliterate($item['id'] . '_' . Itv::getChannelNameById($item['ch_id']) . '_' . $item['program']);
         $res['to_file'] .= '.' . $ext_arr[1];
     }
     if (!empty($_REQUEST['download'])) {
         $downloads = new Downloads();
         $res['cmd'] = $downloads->createDownloadLink('pvr', $rec_id, Stb::getInstance()->id);
     }
     return $res;
 }
Ejemplo n.º 2
0
 public function createLink()
 {
     preg_match("/\\/media\\/(\\d+).mpg(.*)/", $_REQUEST['cmd'], $tmp_arr);
     $media_id = $tmp_arr[1];
     $params = $tmp_arr[2];
     $forced_storage = $_REQUEST['forced_storage'];
     $disable_ad = $_REQUEST['disable_ad'];
     $link = $this->getLinkByVideoId($media_id, intval($_REQUEST['series']), $forced_storage);
     if ($_REQUEST['download']) {
         if (preg_match('/\\.(\\w*)$/', $link['cmd'], $match)) {
             $extension = $match[1];
         }
         $downloads = new Downloads();
         $link['cmd'] = $downloads->createDownloadLink('vclub', $media_id, Stb::getInstance()->id, intval($_REQUEST['series'])) . (isset($extension) ? '&ext=.' . $extension : '');
     } else {
         $link['cmd'] = $link['cmd'] . $params;
     }
     if (Config::get('enable_tariff_plans')) {
         $user = User::getInstance(Stb::getInstance()->id);
         $options = $user->getServicesByType('option');
         if ($options && array_search('disable_vclub_ad', $options) !== false) {
             $disable_ad = true;
         }
     }
     $moderator = $this->db->from('moderators')->where(array('mac' => Stb::getInstance()->mac))->use_caching()->get()->first();
     if (!$disable_ad) {
         $disable_ad = !empty($moderator) && $moderator['status'] == 1 && $moderator['disable_vclub_ad'] == 1 || !empty($_REQUEST['download']);
     }
     $vclub_ad = new VclubAdvertising();
     if (!$disable_ad && empty($link['error'])) {
         $video = Video::getById($media_id);
         $picked_ad = $vclub_ad->getOneWeightedRandom($video['category_id']);
         if (!empty($picked_ad)) {
             $link['cmd'] = $_REQUEST['cmd'];
             $link = array(array('id' => 0, 'ad_id' => $picked_ad['id'], 'ad_must_watch' => $picked_ad['must_watch'], 'type' => 'ad', 'cmd' => $picked_ad['url']), $link);
         }
     }
     var_dump($link);
     return $link;
 }
Ejemplo n.º 3
0
 /**
  * Return link for program
  *
  * @return array
  */
 public function createLink()
 {
     $res = array('id' => 0, 'cmd' => '', 'storage_id' => '', 'load' => '0', 'error' => '');
     preg_match("/\\/media\\/(\\d+).mpg/", $_REQUEST['cmd'], $tmp_arr);
     $program_id = $tmp_arr[1];
     $program = Epg::getById($program_id);
     try {
         $task = $this->getLessLoadedTaskByChId($program['ch_id']);
     } catch (StorageSessionLimitException $e) {
         $res['error'] = 'limit';
         $res['storage_name'] = $e->getStorageName();
         return $res;
     }
     $overlap = Config::getSafe('tv_archive_playback_overlap', 0) * 60;
     $overlap_start = Config::getSafe('tv_archive_playback_overlap_start', 0) * 60;
     $tz = new DateTimeZone(Stb::$server_timezone);
     $date = new DateTime(date('r', strtotime($program['time'])));
     $date->setTimeZone($tz);
     if ($overlap_start) {
         $date->sub(new DateInterval('PT' . $overlap_start . 'S'));
     }
     $date_now = new DateTime('now', new DateTimeZone(Stb::$server_timezone));
     $date_to = new DateTime(date('r', strtotime($program['time_to'])));
     $date_to->setTimeZone($tz);
     $dst_diff = $date->format('Z') - $date_now->format('Z');
     $storage = Master::getStorageByName($task['storage_name']);
     if (!$storage['flussonic_dvr'] && !$storage['wowza_dvr']) {
         if ($dst_diff > 0) {
             $date->add(new DateInterval('PT' . $dst_diff . 'S'));
             $date_to->add(new DateInterval('PT' . $dst_diff . 'S'));
         } elseif ($dst_diff < 0) {
             $dst_diff *= -1;
             $date->sub(new DateInterval('PT' . $dst_diff . 'S'));
             $date_to->sub(new DateInterval('PT' . $dst_diff . 'S'));
         }
     }
     $start_timestamp = $date->getTimestamp();
     $stop_timestamp = $date_to->getTimestamp() + $overlap;
     $channel = Itv::getChannelById($program['ch_id']);
     $filename = $date->format("Ymd-H");
     if ($channel['wowza_dvr']) {
         $filename .= '.mp4';
     } else {
         $filename .= '.mpg';
     }
     $res['storage_id'] = $storage['id'];
     $position = date("i", $start_timestamp) * 60 + date("s", $start_timestamp);
     if ($storage['flussonic_dvr']) {
         if (preg_match("/:\\/\\/([^\\/]*)\\/([^\\/]*).*(mpegts|m3u8)\$/", $channel['mc_cmd'], $match)) {
             if ($match[3] == 'mpegts') {
                 $res['cmd'] = 'http://' . $storage['storage_ip'] . '/' . $match[2] . '/archive/' . $start_timestamp . '/' . ($stop_timestamp - $start_timestamp) . '/mpegts';
             } else {
                 $res['cmd'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $storage['storage_ip'], $channel['mc_cmd']);
                 $res['cmd'] = preg_replace('/\\.m3u8/', '-' . $start_timestamp . '-' . ($stop_timestamp - $start_timestamp) . '.m3u8', $res['cmd']);
             }
             $res['cmd'] .= '?ch_id=' . $program['ch_id'] . '&token=' . $this->createTemporaryToken($this->stb->id) . '&start=' . $position . '&duration=' . ($stop_timestamp - $start_timestamp) . '&osd_title=' . urlencode($channel['name'] . ' — ' . $program['name']) . '&real_id=' . $program['real_id'];
             $res['download_cmd'] = 'http://' . $storage['storage_ip'] . '/' . $match[2] . '/archive-' . $start_timestamp . '-' . ($stop_timestamp - $start_timestamp) . '.ts';
         } else {
             $res['error'] = 'link_fault';
         }
     } elseif ($storage['wowza_dvr']) {
         if (preg_match("/:\\/\\/([^\\/]*)\\/.*\\.m3u8/", $channel['mc_cmd'], $match)) {
             $res['cmd'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $storage['storage_ip'], $channel['mc_cmd']);
             $res['cmd'] = preg_replace('/\\.m3u8.*/', '.m3u8?DVR&wowzadvrplayliststart=' . gmdate("YmdHis", $start_timestamp) . '&wowzadvrplaylistduration=' . ($stop_timestamp - $start_timestamp) * 1000, $res['cmd']) . '&ch_id=' . $program['ch_id'] . '&token=' . $this->createTemporaryToken("1") . '&start=' . $position . '&duration=' . ($stop_timestamp - $start_timestamp) . '&osd_title=' . urlencode($channel['name'] . ' — ' . $program['name']) . '&real_id=' . $program['real_id'];
             $res['download_cmd'] = false;
         } else {
             $res['error'] = 'link_fault';
         }
     } else {
         $res['cmd'] = Config::getSafe('tv_archive_player_solution', 'ffmpeg') . ' http://' . $storage['storage_ip'] . ':' . $storage['apache_port'] . '/stalker_portal/storage/get.php?filename=' . $filename . '&ch_id=' . $program['ch_id'] . '&token=' . $this->createTemporaryToken(true) . '&start=' . $position . '&duration=' . ($stop_timestamp - $start_timestamp) . '&osd_title=' . urlencode($channel['name'] . ' — ' . $program['name']) . '&real_id=' . $program['real_id'];
         if (!empty($_REQUEST['download'])) {
             $downloads = new Downloads();
             $res['download_cmd'] = $downloads->createDownloadLink('tv_archive', $program_id, Stb::getInstance()->id);
         } else {
             $res['download_cmd'] = false;
         }
     }
     $res['to_file'] = date("Ymd-H", $start_timestamp) . '_' . System::transliterate($channel['name'] . '_' . $program['name']) . '.mpg';
     var_dump($res);
     return $res;
 }