Example #1
0
 public function delete()
 {
     //获取需要删除的视频信息
     $params = array('id' => $this->input['id'], 'a' => 'show');
     $vodinfo = $this->request_livmedia($params);
     $filepath = array();
     if (is_array($vodinfo) && !empty($vodinfo)) {
         foreach ($vodinfo as $val) {
             $fileext = pathinfo($val['source_filename']);
             $filepath[$val['id']] = array('source' => $val['source_path'] . '/' . $val['source_filename'], 'mp4' => $val['source_path'] . '/' . $val['source_filename'], 'm3u8' => '/' . $val['video_path'], 'png' => $val['source_path'] . '/' . $fileext['filename'] . '_n1_onefalse.' . $fileext['extension'] . '1.png');
             //file_put_contents(CACHE_DIR.'debug.txt', var_export($this->user['extend'],1));exit;
         }
     }
     if (!$filepath) {
         $this->errorOutput('无效视频数据');
     }
     //删除视频信息
     $params = array('id' => $filepath ? implode(',', array_keys($filepath)) : '', 'a' => 'delete');
     $responce = $this->request_livmedia($params);
     $responce = $responce[0];
     //删除又拍视频物理文件
     $this->addLogs('删除视频', $responce, null, '云平台视频删除');
     if (is_array($responce) && !empty($responce)) {
         foreach ($responce['id'] as $video_id) {
             if ($filepath[$video_id]) {
                 foreach ($filepath[$video_id] as $t => $file) {
                     if ($t == 'm3u8') {
                         $fileurl = 'http://' . $this->user['extend']['domain']['value'] . '/' . $file;
                         $ts_str = file_get_contents($fileurl);
                         preg_match_all('/^\\/.*?.ts$/mi', $ts_str, $ts_array);
                         if (is_array($ts_array)) {
                             $ts_array = $ts_array[0];
                             foreach ($ts_array as $ts) {
                                 $this->deleteFile($ts);
                             }
                         }
                         $this->deleteFile($file);
                     } else {
                         $this->deleteFile($file);
                     }
                 }
             }
             @unlink(CACHE_DIR . $video_id . '.data');
             //删除任务临时文件
         }
         analytic_statistics('delete', $this->user['user_id']);
     }
     $this->addItem($responce);
     $this->output();
 }
Example #2
0
 public function _upload_callback()
 {
     $reponses = $this->input['return_type'] == 'sync' ? $_GET : $_POST;
     //接受回调返回的数据
     log2file($this->user, 'debug', '上传回调数据', $this->input, $reponses);
     if ($reponses['code'] != '200') {
         if ($this->input['return_type']) {
             switch ($this->input['return_type']) {
                 case 'sync':
                     if ($this->input['return_url']) {
                         $url_info = parse_url(urldecode($this->input['return_url']));
                         //header('HTTP/1.1 302 Moved Permanently');
                         header("Location:" . $url_info['scheme'] . '://' . $url_info['host'] . $url_info['path'] . '?' . ($url_info['query'] ? $url_info['query'] . '&' : '') . 'data=' . urlencode(json_encode($reponses)));
                         exit;
                     } elseif ($this->input['data_format'] == 'jsonp') {
                         exit($this->input['func_name'] . '(' . json_encode($reponses) . ')');
                     } else {
                         exit(json_encode($reponses));
                     }
                 case 'asyn':
                 default:
                     exit;
             }
         } else {
             log2file($this->user, 'error', '上传失败', $this->input, $reponses);
             exit;
         }
         //file_put_contents(CACHE_DIR . 'callback_error.txt', var_export($_POST, 1), FILE_APPEND);
     }
     $reponses['access_token'] = $this->input['access_token'];
     //视频入库
     $ext_param = parseQueryString(rawurldecode($reponses['ext-param']));
     $reponses['ext-param'] = $ext_param;
     $filepath = pathinfo($reponses['url']);
     $params = array('title' => $ext_param['title'] ? $ext_param['title'] : '精彩视频', 'chain_m3u8' => DEFAULT_M3U8, 'access_token' => $this->input['access_token'], 'status' => 0, 'source_filename' => basename($reponses['url']), 'source_path' => $filepath['dirname'], 'a' => 'create');
     $curl = new curl($this->settings['App_livmedia']['host'], $this->settings['App_livmedia']['dir'] . 'admin/');
     $curl->initPostData();
     $curl->setSubmitType('post');
     foreach ($params as $key => $val) {
         $curl->addRequestData($key, $val);
     }
     $result = $curl->request('vod_update.php');
     log2file($this->user, 'debug', '视频数据入库', $params, $result);
     $result = $result[0];
     if ($result['error'] == 'repeat') {
         log2file($this->user, 'error', '重复回调', $params, $reponses);
         return;
     }
     $reponses['video_id'] = $video_id = $result['id'];
     //更新视频库数据,同时提交转码
     $result = $this->transcode($reponses);
     //file_put_contents(CACHE_DIR . 't.txt', var_export($reponses, 1), FILE_APPEND);
     if ($result) {
         foreach ($result as $key => $tid) {
             $this->cache_task2file($video_id, 'write', $tid, true);
         }
     }
     analytic_statistics('upload', $this->user['user_id']);
     //上传回调应用
     if ($video_id && $reponses['ext-param']['client_id']) {
         unset($params['a']);
         $params['id'] = $video_id;
         //同步返回
         if ($this->input['return_type'] == 'sync') {
             if ($this->input['return_url']) {
                 $url_info = parse_url(urldecode($this->input['return_url']));
                 //header('HTTP/1.1 302 Moved Permanently');
                 header("Location:" . $url_info['scheme'] . '://' . $url_info['host'] . $url_info['path'] . '?' . ($url_info['query'] ? $url_info['query'] . '&' : '') . 'data=' . urlencode(json_encode($params)));
                 exit;
             } elseif ($this->input['data_format'] == 'jsonp') {
                 exit($this->input['func_name'] . '(' . json_encode($params) . ')');
             } else {
                 exit(json_encode($params));
             }
         }
         //异步
         if ($this->input['return_type'] == 'asyn') {
             //先记录到数据库 通过计划任务调用
             $data = array('client_id' => $reponses['ext-param']['client_id'], 'data' => json_encode($params), 'update_time' => TIMENOW);
             $sql = 'INSERT INTO ' . DB_PREFIX . 'app_upload_queue SET ';
             foreach ($data as $key => $value) {
                 $sql .= $key . '="' . addslashes($value) . '",';
             }
             //file_put_contents(CACHE_DIR . 'debug2.txt', $sql);
             $this->db->query(trim($sql, ','));
         }
     }
 }