Esempio n. 1
0
 public function dvr()
 {
     $stream = addslashes($this->input['stream']);
     $start_time = intval($this->input['starttime']);
     $duration = intval($this->input['duration']);
     $endtime = $start_time + $duration;
     if ($endtime > $this->mTimenow) {
         $endtime = $this->mTimenow;
     }
     $time_shift = $this->mChannelinfo['channel']['time_shift'];
     $shift_stime = $this->mTimenow - $time_shift * 3600000;
     if ($start_time < $shift_stime) {
         $start_time = $shift_stime;
     }
     $this->mChannelinfo['channel']['table_name'] = $this->mChannelinfo['channel']['table_name'] ? $this->mChannelinfo['channel']['table_name'] : 'dvr';
     $channel_stream = $this->mChannelinfo['channel']['code'] . '_' . $stream;
     $this->db = hg_ConnectDB();
     $sql = 'SELECT * FROM ' . DB_PREFIX . $this->mChannelinfo['channel']['table_name'] . " WHERE stream_name='{$channel_stream}' AND start_time >= {$start_time} AND start_time < {$endtime} ORDER BY start_time ASC ";
     $q = $this->db->query($sql);
     $ts = array();
     while ($r = $this->db->fetch_array($q)) {
         $ts[$r['level']][] = $r;
     }
     $ts = $this->get_dvr_ts($ts);
     $sdate = date('Y-m-d', $start_time / 1000);
     $edate = date('Y-m-d', $endtime / 1000);
     $shield_time_zone = $this->get_shield($sdate);
     if ($sdate != $edate) {
         $shield_time_zone = array_merge($shield_time_zone, $this->get_shield($edate));
     }
     $m3u8 = $this->build_m3u8($ts, '#EXT-X-ENDLIST', rtrim($this->mChannelinfo['channel']['config']['ts_host'], '/'), $shield_time_zone);
     $dir = DATA_DIR . $this->mChannelinfo['channel']['code'] . '/' . $stream . '/';
     hg_mkdir($dir);
     $m3u8name = $start_time . ',' . $duration . '.m3u8';
     $m3u8 = trim($m3u8);
     if (!$m3u8) {
         $this->header(404);
     }
     file_put_contents($dir . $m3u8name, $m3u8);
     $urls = $this->mChannelinfo['channel']['config']['out_host'] . $this->mChannelinfo['channel']['code'] . '/' . $stream . '/' . $m3u8name;
     $sm3u8 = $m3u8;
     if ($this->settings['ts_host']) {
         $m3u8 = str_replace($this->mChannelinfo['channel']['config']['ts_host'], $this->settings['ts_host'], $m3u8);
         file_put_contents($dir . 'm_' . $m3u8name, $m3u8);
         $urls .= "\n" . $this->mChannelinfo['channel']['config']['out_host'] . $this->mChannelinfo['channel']['code'] . '/' . $stream . '/m_' . $m3u8name;
     }
     if ($this->settings['open_push_cdn']) {
         include_once ROOT_PATH . 'lib/class/cdn.class.php';
         $cdn = new cdn();
         $cdn->push($urls, '');
     }
     if ($this->settings['m3u8_host'] == 'http://' . $this->input['host']) {
         echo $m3u8;
     } else {
         echo $sm3u8;
     }
 }
Esempio n. 2
0
 public function cdn_publish()
 {
     $rid = intval($this->input['id']);
     if (!$rid) {
         $this->errorOutput('NO_ID');
     }
     $content = $this->obj->get_all_content_by_relationid($rid, true);
     if (!$content) {
         $this->errorOutput('NO_CONTENT');
     }
     if ($this->settings['is_need_audit']) {
         if ($content['status'] != 1) {
             $this->errorOutput('NO_AUDIT');
         }
     }
     if (strstr($content['content_url'], "http") !== false) {
         include_once ROOT_PATH . 'lib/class/cdn.class.php';
         $cdn = new cdn();
         $cdn->push($content['content_url'], '', '');
     }
     $this->addItem(true);
     $this->output();
 }
Esempio n. 3
0
 /**
  * 文件不存在时转向到此方法 创建缩略图
  *
  * 源文件不存在 显示默认图  font/indexbg.jpg
  * 应用自定义默认图放在 font/{$app_uniqueid}/indexbg.jpg
  *
  * @param host string
  * @param refer_to string required 文件路径
  *      如material/news/img/100x75/2012/05/20120529143609jSG7.jpg?21jj
  */
 function create()
 {
     $url = urldecode($this->input['refer_to']);
     $host = urldecode($this->input['host']);
     //$url = 'material/news/img/100x75/2012/05/20120529143609jSG7.jpg?21jj';
     if (empty($url) || empty($host)) {
         $this->readfile(CUR_CONF_PATH . 'font/indexbg.jpg', 'indexbg.jpg');
     } else {
         preg_match_all('/^\\/(.*?\\/.*?\\/)?(.*?\\/img\\/)([0-9]*)[x|-]([0-9]*)\\/(\\d{0,4}\\/\\d{0,2}\\/)(.*?)(\\.[a-zA-Z0-9_]*)(\\?\\w*)?/i', $url, $out);
         $tmp = explode('/', $out[2][0]);
         if ($tmp[0] == 'material') {
             $app_uniqueid = $tmp[1];
         } else {
             $app_uniqueid = $tmp[0];
         }
         $info = array('host' => $host, 'dir' => $out[2][0], 'filepath' => $out[5][0], 'filename' => $out[6][0], 'type' => $out[7][0], 'app_uniqueid' => $app_uniqueid);
         $size = array('label' => $out[3][0] . 'x' . $out[4][0], 'width' => $out[3][0], 'height' => $out[4][0], 'other_dir' => $out[5][0]);
         $IMG_DIR = $this->settings['imgdirs']['http://' . $info['host'] . '/'];
         if (!$IMG_DIR) {
             $IMG_DIR = IMG_DIR;
         }
         $filepath = $IMG_DIR . $info['dir'] . $info['filepath'] . $info['filename'] . ".json";
         $water_url = $position = "";
         if (file_exists($filepath)) {
             $json = json_decode(file_get_contents($filepath), true);
             //$water = $json['water'];   //原图加水印 缩略图不重复加水印
         }
         $path = $IMG_DIR . $info['dir'];
         $file = $path . $info['filepath'] . $info['filename'] . $info['type'];
         if (!file_exists($file) || !is_file($file)) {
             //文件不存在 显示默认图  font/indexbg.jpg
             //应用自定义默认图放在 font/{$app_uniqueid}/indexbg.jpg
             $default_img = CUR_CONF_PATH . 'font/indexbg.jpg';
             if (file_exists(CUR_CONF_PATH . 'font/' . $info['app_uniqueid'] . '/indexbg.jpg')) {
                 $default_img = CUR_CONF_PATH . 'font/' . $info['app_uniqueid'] . '/indexbg.jpg';
             }
             $this->readfile($default_img, 'indexbg.jpg');
         }
         $isSucc = hg_mk_images($file, $info['filename'] . $info['type'], $IMG_DIR . $info['dir'], $size, $water);
         if ($isSucc) {
             if (file_exists($filepath)) {
                 $thumb = json_decode(file_get_contents($filepath), true);
             } else {
                 $thumb = array();
             }
             $path = rtrim(realpath($path), '/') . '/';
             //记录绝对路径
             $thumb_tmp = $path . $size['label'] . "/" . $info['filepath'] . $info['filename'] . $info['type'];
             if (is_array($thumb['thumb']) && !in_array($thumb_tmp, $thumb['thumb']) || empty($thumb['thumb'])) {
                 // 判断这个列表不不存文件中
                 $thumb['thumb'][] = $thumb_tmp;
             }
             hg_file_write($filepath, json_encode($thumb));
             $header_url = 'http://' . $info['host'] . "/" . $info['dir'] . $size['label'] . "/" . $info['filepath'] . $info['filename'] . $info['type'];
             if ($this->settings['realtime_refresh_cdn'] && $this->settings['App_cdn']) {
                 include_once ROOT_PATH . 'lib/class/cdn.class.php';
                 $cdn = new cdn();
                 $cdn->push($header_url, '');
             }
             $file = $path . $size['label'] . "/" . $info['filepath'] . $info['filename'] . $info['type'];
             $this->readfile($file, $info['filename'] . $info['type'], $info['type']);
         } else {
             //缩略图创建失败  显示原图
             $this->readfile($file, $info['filename'] . $info['type']);
         }
     }
 }