/** * 频道信号列表显示 * @name show * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $condition 检索条件 * @param $offset 分页参数 * @param $count 分页显示记录数 * @return $row array 所有频道信号内容信息 */ function show() { $condition = $this->get_condition(); $offset = $this->input['offset'] ? $this->input['offset'] : 0; $count = $this->input['count'] ? intval($this->input['count']) : 20; $data_limit = " LIMIT " . $offset . " , " . $count; $sql = "select * from " . DB_PREFIX . "stream "; $sql .= ' where 1 ' . $condition . " ORDER BY id DESC " . $data_limit; $q = $this->db->query($sql); $this->setXmlNode('stream', 'info'); while ($row = $this->db->fetch_array($q)) { $row['uri'] = unserialize($row['uri']); $row['other_info'] = unserialize($row['other_info']); foreach ($row['other_info'] as $key => $value) { $row['out_uri'][$value['name']] = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $row['ch_name'], 'stream_name' => $value['name']), 'channels', 'http://'); $row['stream_name'][] = $value['name']; } if (!$row['s_status']) { $row['s_status'] = "已停止"; } else { $row['s_status'] = "已启动"; } $this->addItem($row); //hg_pre($row); } $this->output(); }
public function update() { $id = intval($this->input['id']); if (!$id) { $this->errorOutput('请指定视频id'); } $condition = " WHERE v.id = {$id}"; //source 频道ID $sql = "SELECT v.id,v.starttime,v.source,v.duration,v.channel_id,c.code,c.save_time,c.main_stream_name,c.record_time,c.live_delay FROM " . DB_PREFIX . "vodinfo v LEFT JOIN " . DB_PREFIX . "channel c ON v.channel_id=c.id " . $condition; $row = $this->db->query_first($sql); if (!$row) { $this->errorOutput('指定视频不存在'); } if (TIMENOW - $row['starttime'] > $row['save_time'] * 3600) { $this->errorOutput('时移已经不存在'); } $ret = array(); $ret['stream'] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $row['code'], 'stream_name' => $row['main_stream_name']), 'internal'); $ret['starttime'] = $row['starttime'] + $row['record_time']; $ret['endtime'] = $ret['starttime'] + intval($row['duration'] / 1000); $ret['save_time'] = $row['save_time']; $ret['delay_time'] = $row['live_delay'] * 60; $this->curl->setSubmitType('post'); $this->curl->setReturnFormat('json'); $this->curl->initPostData(); foreach ($ret as $key => $value) { $this->curl->addRequestData($key, $value); } $this->curl->addRequestData('id', $id); $this->curl->addRequestData('channel_id', $row['channel_id']); $info = $this->curl->request('record.php'); $this->addItem($info); $this->output(); }
function show() { $gap = 20; //以秒为单位进行 $start_time = TIMENOW + 20; $sql = "select * from " . DB_PREFIX . "program_record where start_time=" . $start_time; $q = $this->db->query($sql); while ($row = $this->db->fetch_array($q)) { if ($row['rate'] && $row['rate'] > $row['toff']) { $new_time = $start_time + $row['rate']; $sql = "update " . DB_PREFIX . "program_record set start_time=" . $new_time . " where id=" . $row['id']; $this->db->query($sql); if ($row['channel_id']) { $channel[] = $row['channel_id']; } } } $channel = array_unique($channel); $channel_id = implode(",", $channel); $sql = "select id,code,up_name from " . DB_PREFIX . "channel where id IN (" . $channel_id . ")"; $q = $this->db->query($sql); $info = array(); while ($r = $this->db->fetch_array($q)) { $up_name = unserialize($r['up_name']); if ($up_name) { foreach ($up_name as $key => $value) { $bit = 200; if (strstr($value, 'sd')) { $bit = 400; } if (strstr($value, 'hd')) { $bit = 800; } if (strstr($value, 'cd')) { $bit = 1000; } $info[$r['id']] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $r['code'], 'stream_name' => $value)); } } } $this->addItem($info); $this->output(); }
/** * 显示录播节目单 */ function show() { $sql = "SELECT c.id, c.code, c.name,c.save_time,c.main_stream_name,c.stream_state,c.record_time,c.stream_id, pr.*,vs.sort_name\r\n\t\t\t\t\tFROM " . DB_PREFIX . "program_record pr \r\n\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "channel c \r\n\t\t\t\t\t\tON pr.channel_id=c.id \r\n\t\t\t\t\tLEFT JOIN " . DB_PREFIX . "vod_sort vs \r\n\t\t\t\t\t\tON pr.item=vs.id\r\n\t\t\t\tWHERE pr.is_record=0 AND (pr.start_time+pr.toff) < " . (TIMENOW - 40); //延迟30秒开始录制 $q = $this->db->query($sql); while ($row = $this->db->fetch_array($q)) { $return = array(); if (!$row['channel_id']) { continue; } $ret = array(); $ret['channel_id'] = $row['channel_id']; $ret['starttime'] = $row['start_time'] + $row['record_time']; $ret['endtime'] = $ret['starttime'] + $row['toff']; $ret['program'] = $row['title'] ? $row['title'] : $this->program_plan($ret['channel_id'], $ret['starttime'], $ret['endtime']); $row['program_name'] = $ret['program'] = $ret['program'] ? $ret['program'] : '精彩节目'; $ret['stream'] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $row['code'], 'stream_name' => $row['main_stream_name']), 'internal'); $ret['save_time'] = $row['save_time']; $ret['vod_sort_id'] = $row['item']; $ret['delay_time'] = $row['live_delay'] * 60; $ret['source'] = $row['channel_id']; $ret['is_allow'] = $row['is_mark']; $ret['force_codec'] = $row['force_codec']; if ($ret['endtime'] + $ret['delay_time'] > TIMENOW) { continue; } $sql = "select id, ch_name,other_info,s_status from " . DB_PREFIX . "stream where id=" . $row['stream_id']; $stream = $this->db->query_first($sql); if (!$row['stream_state']) { $ret = array('errortext' => '视频流未开启!'); } elseif (!$stream['s_status']) { $ret = array('errortext' => '视频上游流未开启!'); } else { $this->curl->setSubmitType('post'); $this->curl->setReturnFormat('json'); $this->curl->initPostData(); foreach ($ret as $key => $value) { $this->curl->addRequestData($key, $value); } if ($row['columnid']) { $this->curl->addRequestData('status', '2'); } $ret = $this->curl->request('record.php'); } $sql_update = "UPDATE " . DB_PREFIX . "program_record SET is_record=1 WHERE id=" . $row['id']; $state = 2; $error = $ret['errortext']; $week_day = unserialize($row['week_day']); if (is_array($week_day) && $week_day) { $week_now = date('N', $row['start_time']); $new_arr = array_flip($week_day); if (count($week_day) > $new_arr[$week_now] + 1) { $ks = $new_arr[$week_now] + 1; } else { $ks = 0; } $week_day = array_flip($new_arr); $next_week = $week_day[$ks] - $week_now > 0 ? $week_day[$ks] - $week_now : $week_day[$ks] - $week_now + 7; $start_time = $row['start_time'] + $next_week * 86400; $sql_update = "UPDATE " . DB_PREFIX . "program_record SET is_record=0,start_time=" . $start_time . " WHERE id=" . $row['id']; } if (!empty($ret['vodid'])) { $state = 1; $return = array('conid' => $ret['id'], 'admin_id' => $ret['admin_id'], 'admin_name' => $ret['admin_name'], 'columnid' => $row['columnid'], 'status' => $ret['status'] == 2 ? 1 : 0); } $this->db->query($sql_update); $log = array('record_id' => $row['id'], 'channel_id' => $row['channel_id'], 'channel_name' => $row['name'], 'program_name' => $row['program_name'], 'start_time' => $row['start_time'], 'vod_id' => $ret['id'], 'toff' => $row['toff'], 'item' => $row['item'], 'sortname' => $row['sort_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip(), 'state' => $state, 'error' => $error, 'auto' => 1); $createsql = "INSERT INTO " . DB_PREFIX . "program_record_log SET "; $space = ""; foreach ($log as $key => $value) { $createsql .= $space . $key . "=" . "'" . $value . "'"; $space = ","; } $this->db->query($createsql); if (!empty($return)) { $this->addItem($return); } } $this->output(); }
public function show() { $channel_id = $this->input['channel_id']; if (!$channel_id) { $this->errorOutput('未传入频道ID'); } $suffix = 'live.m3u8'; if ($this->input['source']) { $cond = ' AND open_ts=1'; if ($this->input['source'] == 2) { $suffix = 'live.mp4'; } } $sql = "select * from " . DB_PREFIX . "channel where id=" . $channel_id . $cond; $channel_info = $this->db->query_first($sql); $imgsize = $this->input['imgsize'] ? $this->input['imgsize'] : '450x341'; $info = array(); if (is_array($channel_info)) { $info['id'] = $channel_info['id']; $info['channel']['name'] = $channel_info['name']; $info['channel']['drm'] = $channel_info['drm']; $logo = hg_get_images($channel_info['logo'], UPLOAD_URL . CHANNEL_IMG_DIR, $this->settings['channel_img_size']); $info['channel']['logo'] = $logo['img']; $info['channel']['snap'] = MMS_CONTROL_LIST_PREVIEWIMG_URL . $channel_info['ch_id'] . '/' . $channel_info['main_stream_name'] . '/' . TIMENOW * 1000 . '/' . $imgsize . '.png'; $info['channel']['m3u8'] = isset($this->input['_config']) ? $this->config[$info['id']] : hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $channel_info['main_stream_name']), 'channels', 'http://', 'm3u8:'); $sql = "SELECT id,theme,start_time FROM " . DB_PREFIX . 'program WHERE channel_id =' . $channel_id . ' '; $sql .= ' AND start_time >= ' . TIMENOW . ' LIMIT 2'; $programq = $this->db->query($sql); $program = array(); while ($r = $this->db->fetch_array($programq)) { $program[$r['start_time']] = $r['theme']; } ksort($program); $p = array(); foreach ($program as $theme) { $p[] = $theme; } $info['channel']['cur_program'] = $p[0] ? $p[0] : '精彩节目'; $info['channel']['next_program'] = $p[1] ? $p[1] : '精彩节目'; //$info['ad'][] = array(); $sql = "select * from " . DB_PREFIX . "channel_stream where channel_id=" . $channel_id; $main_stream = $this->db->query($sql); $streams = array(); while ($r = $this->db->fetch_array($main_stream)) { /* if ($r['bitrate']) { $streams[$r['bitrate']] = array( 'url' => hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $r['out_stream_name'])), 'bit' => $r['bitrate'] ); } else { */ $streams[] = array('url' => hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $r['out_stream_name'])), 'bit' => $r['bitrate']); /* } */ } if ($streams) { krsort($streams); foreach ($streams as $key => $value) { $info['stream'][] = $value; } } } $this->addItem($info); $this->output(); }
/** * 创建频道 (当tvie为open时开始创建,创建顺序:延时层-->切播层-->输出层-->本地) * @name create * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $name string 频道名称 * @param $code string 台号 * @param $code_2 string 台号(修改用) * @param $logo string 台标 * @param $stream_id int 信号ID * @param $delay_id int 延时层ID * @param $chg_id int 切播层ID * @param $ch_id int 输出层ID * @param $save_time int 回看时间(小时) * @param $live_delay int 延时时间 (分钟) * @param $is_live tinyint 是否播控 (1-是 0-否) * @param $stream_name string 流名称 not null * @param $main_stream_name string 主信号名称 * @param $beibo string 备播信号 (暂最多支持2个) * @param $uri_in_num tinyint 输入流数目 * @param $uri_out_num tinyint 输出流数目 * @param $level tinyint 频道层数 * @param $open_ts tinyint 是否支持手机流 (1-是 0-否) * @param $record_time int 自动收录节目时间偏差设置 (±30秒 大于30秒就等于30秒,小于-30秒就等于-30秒) * @param $audio_only tinyint 记录是否是音频 (1-是 0-否 ) * @param $create_time int 创建时间 * @param $update_time int 更新时间 * @param $ip string 创建者ip * @param $channel_id int 频道ID * @param $delay_stream_id int 延时层流ID * @param $chg_stream_id int 切播层流ID * @param $out_stream_id int 输出层流ID * @param $stream_name string 流名称 * @param $out_stream_name string 输出流名称 * @param $is_main tinyint 是否主流 (1-是 0-否) * @param $bitrate int 码流 * @param $flag_stream 标识(单流改为多流) * @param $drm tyinint 防盗链设置 (1-启用 0-关闭) * @param $logo_info array logo素材信息 * @return $ret['id'] int 频道ID * @include tvie_api.php */ public function create() { $name = urldecode($this->input['name']); if (!$name) { $this->errorOutput('频道名称不能为空!'); } $code = urldecode($this->input['code']); if (!$code) { $this->errorOutput('台号不能为空!'); } $stream_id = $this->input['stream_id'] ? intval($this->input['stream_id']) : 0; $save_time = $this->input['save_time'] ? intval($this->input['save_time']) : 0; //回看时间 $live_delay = $this->input['live_delay'] ? intval($this->input['live_delay']) : 0; //延时时间 $is_live = intval($this->input['is_live']); //是否播控 1表示有播控 0表示无播控 $drm = intval($this->input['drm']); //防盗链设置 $stream_name = $this->input['stream_name']; if (!$stream_name) { $this->errorOutput('至少为频道选择一条流'); } $main_stream_name = $this->input['main_stream_name']; if ($this->input['beibo']) { if ($is_live && count($this->input['beibo']) > 2) { $this->errorOutput('最多两个备播信号,请重新选择!'); } foreach ($this->input['beibo'] as $value) { $beibo_key_value = explode('#', urldecode($value)); $beibo[$beibo_key_value[0]] = $beibo_key_value[1]; } $beibo = serialize($beibo); } $sql = "SELECT * FROM " . DB_PREFIX . "stream WHERE id=" . $stream_id; $streams = $this->db->query_first($sql); if (!$streams) { $this->errorOutput('所选信号不存在,请重新选择'); } $other_info = unserialize($streams['other_info']); if (!$other_info) { $this->errorOutput('所选信号没有信号流'); } $stream_name_arr = array(); foreach ($other_info as $v) { $stream_name_arr[$v['name']] = $v; } $stream_info = array(); foreach ($stream_name as $n) { if ($stream_name_arr[$n]) { $stream_info[] = $stream_name_arr[$n]; } } if (!$stream_info) { $this->errorOutput('所选流不存在或已被删除'); } //输入流的数目 $uri_in_num = count($stream_name); //层数目 if ($uri_in_num > 1) { $level = 1; } else { if (!$is_live) { $level = 1; } elseif (!$live_delay) { $level = 2; } else { $level = 3; } } //选择流与选择信号流的差集 $diff_stream_name = array_diff($stream_name_arr, $stream_name); //开启tvie if ($this->settings['tvie']['open']) { include CUR_CONF_PATH . 'lib/tvie_api.php'; $delay_tvie = new TVie_api($this->settings['tvie']['up_stream_server']); $delay_type = 'normal_virtual'; $chg_tvie = $delay_tvie; $out_tvie = new TVie_api($this->settings['tvie']['stream_server']); $first_stream = $stream_info[0]; //获取主信号流 unset($stream_info[0]); $delay_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $first_stream['name']), 'channels', 'tvie://'); if (is_array($first_stream['backstore'])) { $backstore = implode(',', $first_stream['backstore']); } else { $backstore = $first_stream['backstore']; } //32创建延时层 $delay_channel = $delay_tvie->create_channel('delay_' . $code, $name, $streams['server_id'], 1, $live_delay, $delay_type, $first_stream['name'], $first_stream['recover_cache'], $first_stream['source_name'], $delay_stream_uri, $first_stream['bitrate'], $first_stream['drm'], $first_stream['wait_relay'], $backstore); $delay_channel_id = $delay_channel['channel_id']; if (!$delay_channel_id) { $this->errorOutput('频道创建失败,原因:' . serialize($delay_channel) . $delay_channel['message'] . $delay_channel['errors']); } $ret_delay_channel_info = $delay_tvie->get_channel_by_id($delay_channel_id); $ret_delay_stream_info = $ret_delay_channel_info['channel']['streams']; $first_delay_stream_id = $ret_delay_stream_info[0]['id']; //延时层创建流 $stream_ids = array('delay_stream_id' => array($first_stream['name'] => $first_delay_stream_id)); if ($stream_info) { foreach ($stream_info as $key => $value) { $delay_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://'); if (is_array($value['backstore'])) { $backstore = implode(',', $value['backstore']); } else { $backstore = $value['backstore']; } $ret_delay_stream = $delay_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $delay_uri, $value['drm'], $backstore, $value['wait_relay'], 0, $value['bitrate'], $delay_channel_id); if ($ret_delay_stream['stream_id']) { $stream_ids['delay_stream_id'][$value['name']] = $ret_delay_stream['stream_id']; } } } //创建切播层 $chg_type = 'normal_virtual'; if (!$live_delay) { //没有延时,上游流地址直接是信号流地址 $chg_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $first_stream['name'])); } else { //有延时,上游流地址延迟层流地址 $chg_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $code, 'stream_name' => $first_stream['name'])); } if (is_array($first_stream['backstore'])) { $backstore = implode(',', $first_stream['backstore']); } else { $backstore = $first_stream['backstore']; } //32创建切播层 $chg_channel = $chg_tvie->create_channel('chg_' . $code, $name, $streams['server_id'], 0, 0, $chg_type, $first_stream['name'], $first_stream['recover_cache'], $first_stream['source_name'], $chg_stream_uri, $first_stream['bitrate'], $first_stream['drm'], $first_stream['wait_relay'], $backstore); $chg_channel_id = $chg_channel['channel_id']; if (!$chg_channel_id) { $delay_tvie->delete_channel($delay_channel_id); $this->errorOutput('频道创建失败,原因:' . $chg_channel['message'] . $chg_channel['errors']); } $ret_chg_channel_info = $chg_tvie->get_channel_by_id($chg_channel_id); $ret_chg_stream_info = $ret_chg_channel_info['channel']['streams']; $first_chg_stream_id = $ret_chg_stream_info[0]['id']; $stream_ids['chg_stream_id'][$first_stream['name']] = $first_chg_stream_id; //创建切播层流 $chg_url = array(); foreach ($stream_info as $key => $value) { if (!$live_delay) { //没有延时,上游流地址直接是信号流地址 $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://'); $chg_uri_http = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name'])); } else { //有延迟,上游流地址是延迟层流地址 $chg_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $code, 'stream_name' => $value['name']), 'channels', 'tvie://'); $chg_uri_http = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'delay_' . $code, 'stream_name' => $value['name'])); } $chg_url['tvie'][] = $chg_uri; $chg_url['http'][] = $chg_uri_http; if (is_array($value['backstore'])) { $backstore = implode(',', $value['backstore']); } else { $backstore = $value['backstore']; } $ret_chg_stream = $chg_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $chg_uri_http, $value['drm'], $backstore, $value['wait_relay'], 0, $value['bitrate'], $chg_channel_id); if ($ret_chg_stream['stream_id']) { $stream_ids['chg_stream_id'][$value['name']] = $ret_chg_stream['stream_id']; } } //32延时层或者切播层创建成功后,再向21创建输出层 $out_type = 'normal_virtual'; if (!$is_live) { //无切播层,直接信号流地址 $out_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $first_stream['name']), 'channels', 'tvie://'); } else { //有切播层,切播层流地址 $out_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $code, 'stream_name' => $first_stream['name']), 'channels', 'tvie://'); } if ($this->input['open_ts']) { $first_stream['backstore'] = array(0 => 'flv', 1 => 'ts'); } if (is_array($first_stream['backstore'])) { $backstore = implode(',', $first_stream['backstore']); } else { $backstore = $first_stream['backstore']; } $out_live_delay = $live_delay; if ($level != 1) { $out_live_delay = 0; } else { if (!$save_time) { $save_time = 1; } } //创建频道 $out_channel = $out_tvie->create_channel($code, $name, $streams['server_id'], $save_time, $out_live_delay, $out_type, $first_stream['name'], $first_stream['recover_cache'], $first_stream['source_name'], $out_stream_uri, $first_stream['bitrate'], $drm, $first_stream['wait_relay'], $backstore); $out_channel_id = $out_channel['channel_id']; //返回频道id if (!$out_channel_id) { //删除切播层、延时层 $delay_tvie->delete_channel($delay_channel_id); $chg_tvie->delete_channel($chg_channel_id); $this->errorOutput('频道创建失败,原因:' . $out_channel['message'] . $out_channel['errors']); } $ret_out_channel_info = $out_tvie->get_channel_by_id($out_channel_id); $ret_out_stream_info = $ret_out_channel_info['channel']['streams']; $first_out_stream_id = $ret_out_stream_info[0]['id']; $stream_ids['out_stream_id'][$first_stream['name']] = $first_out_stream_id; //创建输出层流 foreach ($stream_info as $key => $value) { if (!$is_live) { //无切播层,直接信号流地址 $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['name']), 'channels', 'tvie://'); } else { //有切播层,切播层流地址 $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $code, 'stream_name' => $value['name']), 'channels', 'tvie://'); } if ($this->input['open_ts']) { $value['backstore'] = array(0 => 'flv', 1 => 'ts'); } if (is_array($value['backstore'])) { $backstore = implode(',', $value['backstore']); } else { $backstore = $value['backstore']; } $ret_out_stream = $out_tvie->create_channel_stream($value['name'], $value['recover_cache'], $value['source_name'], $out_uri, $drm, $backstore, $value['wait_relay'], 0, $value['bitrate'], $out_channel_id); if ($ret_out_stream['stream_id']) { $stream_ids['out_stream_id'][$value['name']] = $ret_out_stream['stream_id']; } } } //录制节目时间偏差设置 if ($this->input['record_time'] >= 0) { if ($this->input['record_time'] > 30) { $record_time = 30; } else { $record_time = $this->input['record_time']; } } else { if ($this->input['record_time'] < -30) { $record_time = -30; } else { $record_time = $this->input['record_time']; } } $info = array('user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'code' => $code, 'code_2' => $code, 'name' => $name, 'delay_id' => $delay_channel_id, 'chg_id' => $chg_channel_id, 'ch_id' => $out_channel_id, 'is_live' => $is_live, 'drm' => $drm, 'open_ts' => $this->input['open_ts'], 'uri_in_num' => $uri_in_num, 'uri_out_num' => $uri_out_num, 'save_time' => $save_time ? $save_time : 0, 'live_delay' => $live_delay ? $live_delay : 0, 'stream_display_name' => $streams['s_name'], 'stream_mark' => $streams['ch_name'], 'level' => $level, 'beibo' => $beibo, 'stream_id' => $stream_id, 'main_stream_name' => $main_stream_name[0], 'stream_info_all' => serialize($stream_name), 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip(), 'record_time' => $record_time, 'audio_only' => $first_stream['audio_only']); $createsql = "INSERT INTO " . DB_PREFIX . "channel SET "; $space = ""; foreach ($info as $key => $value) { $createsql .= $space . $key . "=" . "'" . $value . "'"; $space = ","; } $ret = array(); $this->db->query($createsql); $ret['id'] = $this->db->insert_id(); //插入排序id //插入工作量统计 $statistic = new statistic(); $statistics_data = array('content_id' => $ret['id'], 'contentfather_id' => '', 'type' => 'insert', 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'app_uniqueid' => APP_UNIQUEID, 'module_uniqueid' => MODULE_UNIQUEID, 'before_data' => '', 'last_data' => $name, 'num' => 1); $statistic->insert_record($statistics_data); if ($_FILES['files']['tmp_name']) { include_once ROOT_PATH . 'lib/class/material.class.php'; $this->mMaterial = new material(); $file['Filedata'] = $_FILES['files']; $material = $this->mMaterial->addMaterial($file, $ret['id'], intval($this->input['mmid']), 'img4'); $logo_info['id'] = $material['id']; $logo_info['type'] = $material['type']; $logo_info['server_mark'] = $material['server_mark']; $logo_info['filepath'] = $material['filepath']; $logo_info['name'] = $material['name']; $logo_info['filename'] = $material['filename']; $logo_info['url'] = $material['url']; } $sql = "UPDATE " . DB_PREFIX . "channel SET order_id = " . $ret['id'] . ", logo_info = '" . serialize($logo_info) . "' WHERE id=" . $ret['id']; $this->db->query($sql); //流信息 $stream_info[] = $first_stream; $i = 0; $stream_num = count($stream_info) - 1; foreach ($stream_info as $k => $v) { $main_stream_info = array('channel_id' => $ret['id'], 'stream_id' => $stream_id, 'delay_stream_id' => $stream_ids['delay_stream_id'][$v['name']], 'chg_stream_id' => $stream_ids['chg_stream_id'][$v['name']], 'out_stream_id' => $stream_ids['out_stream_id'][$v['name']], 'stream_name' => $v['name'], 'out_stream_name' => $v['name'], 'is_main' => $main_stream_name[0] == $v['name'] ? 1 : 0, 'bitrate' => $v['bitrate'], 'flag_stream' => '', 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => hg_getip()); $cresql = "INSERT INTO " . DB_PREFIX . "channel_stream SET "; $space = ""; foreach ($main_stream_info as $key => $value) { $cresql .= $space . $key . "=" . "'" . $value . "'"; $space = ","; } $this->db->query($cresql); $i++; } $this->setXmlNode('channel', 'info'); $this->addItem($ret['id']); $this->output(); }
/** * 所有频道信息 * @name channelsInfo * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $condition 检索条件 * @param $offset 分页参数 * @param $count 分页显示记录数 * @return $info array 所有频道内容信息 */ public function channelsInfo($condition, $offset, $count) { $data_limit = " LIMIT " . $offset . " , " . $count; $sql = "SELECT c.*,s.*,s.id as s_id,c.id as c_id,c.ch_id as c_ch_id,c.save_time as c_save_time, c.live_delay as c_live_delay, s.ch_id as s_ch_id,s.save_time as s_save_time, s.live_delay as s_live_delay FROM " . DB_PREFIX . "channel c LEFT JOIN " . DB_PREFIX . "stream s on c.stream_id=s.id "; $sql .= " WHERE 1 " . $condition . " ORDER BY c.order_id DESC " . $data_limit; $q = $this->db->query($sql); $info = $channel_stream = array(); while ($row = $this->db->fetch_array($q)) { $row['id'] = $row['c_id']; $row['ch_id'] = $row['c_ch_id']; $row['save_time'] = $row['c_save_time']; $row['live_delay'] = $row['c_live_delay']; $row['logo_info'] = unserialize($row['logo_info']); if ($row['logo_info']) { $row['logo_url'] = hg_material_link($this->settings['material_server']['img4']['host'], $this->settings['material_server']['img4']['dir'], $row['logo_info']['filepath'], $row['logo_info']['filename']); } if (!$row['stream_state']) { // $row['stream_state'] = "启动流输出"; $row['stream_state_tag'] = 0; } else { // $row['stream_state'] = "停止流输出"; $row['stream_state_tag'] = 1; } $row['beibo'] = unserialize($row['beibo']); $row['uri'] = unserialize($row['uri']); $row['stream_info_all'] = unserialize($row['stream_info_all']); $row['other_info'] = unserialize($row['other_info']); $channel_streams = array(); if ($row['other_info']) { foreach ($row['other_info'] as $k => $v) { $channel_streams[$k]['id'] = $v['id']; $channel_streams[$k]['name'] = $v['name']; $channel_streams[$k]['code'] = $row['code']; $channel_streams[$k]['bitrate'] = $v['bitrate']; $channel_streams[$k]['open_ts'] = $row['open_ts']; $channel_streams[$k]['stream_mark'] = $row['stream_mark']; $channel_streams[$k]['out_stream_name'] = $v['out_stream_name']; } } $channel_stream[$row['id']] = $channel_streams; $info[$row['id']] = $row; } if ($info) { //基础流信息 $stream = $this->channelStreams(array_keys($info)); $stream_info = array(); foreach ($stream as $k => $v) { foreach ($channel_stream as $kk => $vv) { if ($k == $kk) { if ($v['name'] == $vv['stream_name']) { for ($i = 0; $i < count($v); $i++) { $stream_info[$k]['streams'][$i]['id'] = $v[$i]['id']; $stream_info[$k]['streams'][$i]['name'] = $v[$i]['stream_name']; $stream_info[$k]['streams'][$i]['out_stream_name'] = $v[$i]['out_stream_name']; $stream_info[$k]['streams'][$i]['uri'] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $vv[$i]['code'], 'stream_name' => $v[$i]['out_stream_name'])); $stream_info[$k]['streams'][$i]['stream_uri'] = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $vv[$i]['stream_mark'], 'stream_name' => $v[$i]['stream_name'])); if ($vv[$i]['open_ts']) { $stream_info[$k]['streams'][$i]['m3u8'] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $vv[$i]['code'], 'stream_name' => $v[$i]['out_stream_name']), 'channels', 'http://', 'm3u8:'); } $stream_info[$k]['streams'][$i]['is_main'] = $v[$i]['is_main']; $stream_info[$k]['streams'][$i]['bitrate'] = $v[$i]['bitrate']; } } } } } } //频道内容信息 $channel_info = array(); foreach ($info as $k => $v) { foreach ($stream_info as $kk => $vv) { if ($k == $kk) { $channel_info[$k] = array_merge($v, $vv); } } } return $channel_info; }
public function record() { include_once ROOT_PATH . 'lib/class/curl.class.php'; global $gGlobalConfig; $this->curl = new curl($gGlobalConfig['vodapi']['host'], $gGlobalConfig['vodapi']['dir'], $gGlobalConfig['vodapi']['token']); if (!$this->input['id']) { $this->errorOutput('你录个鬼啊?!什么都没有'); } $sql = "select * from " . DB_PREFIX . "program_record_log where id=" . $this->input['id']; $row = $this->db->query_first($sql); $sql = "select id,code,name,save_time,stream_info_all from " . DB_PREFIX . "channel where 1 and id=" . $row['channel_id']; $channel = $this->db->query_first($sql); $sql = "select other_info from " . DB_PREFIX . "stream where 1 "; $q = $this->db->query($sql); $stream = array(); while ($r = $this->db->fetch_array($q)) { $arr = unserialize($r['other_info']); $stream[$arr[0]['name']] = $arr[0]['bitrate']; } $ret = array(); $ret['channel_id'] = $row['channel_id']; $sql = "SELECT theme,subtopic FROM " . DB_PREFIX . "program WHERE id=" . $row['program_id']; $f = $this->db->query_first($sql); if (is_array($f)) { $ret['program'] = $f['subtopic'] ? $f['theme'] . ':' . $f['subtopic'] : $f['theme']; } else { $ret['program'] = '精彩节目'; } $ret['starttime'] = $row['start_time']; $ret['endtime'] = $row['start_time'] + $row['toff']; $up_name = unserialize($channel['stream_info_all']); $arr = array(); foreach ($up_name as $k => $v) { $arr[] = array('code' => $v, 'bit' => $stream[$v]); } $code = max($arr); $ret['stream'] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel['code'], 'stream_name' => $code['code']), 'internal'); $ret['save_time'] = $channel['save_time']; $ret['vod_sort_id'] = $row['item']; $ret['delay_time'] = $channel['live_delay'] * 60; if ($ret['endtime'] + $ret['delay_time'] > TIMENOW) { $this->errorOutput('超出延时!'); } //file_put_contents('2.php',json_encode($ret)); $this->curl->setSubmitType('post'); $this->curl->setReturnFormat('json'); $this->curl->initPostData(); foreach ($ret as $key => $value) { $this->curl->addRequestData($key, $value); } $ret = $this->curl->request('record.php'); //file_put_contents('1.php',json_encode($ret)); if ($ret['vodid']) { $sql = "update " . DB_PREFIX . "program_record_log SET vod_id='" . $ret['vodid'] . "',state=1 where channel_id=" . $row['channel_id'] . " and (start_time+toff)<" . TIMENOW . " and vod_id='0' and state=0"; $this->db->query($sql); $this->setXmlNode('program_record', 'info'); $this->addItem($ret); $this->output(); } else { $this->errorOutput('收录失败!'); } }
function show() { $this->channel_id = intval($this->input['channel_id']); $play_time = $this->input['play_time'] ? $this->input['play_time'] : 0; //是当前要播放的时间,我不想改了 if (!$this->channel_id) { $this->errorOutput(OBJECT_NULL); } $sql = "select * from " . DB_PREFIX . "channel where id=" . $this->channel_id; $channel_info = $this->db->query_first($sql); $info = array(); if (!$channel_info) { $this->errorOutput(OBJECT_NULL); } $channel_info['logo'] = hg_get_images($channel_info['logo'], UPLOAD_URL . CHANNEL_IMG_DIR, $this->settings['channel_img_size']); $channel_info['m3u8'] = isset($this->input['_config']) && $this->config[$this->channel_id] ? $this->config[$this->channel_id] . 'live.m3u8' : hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $channel_info['main_stream_name'], 'backtime' => 'Backtime'), 'channels', 'http://', 'm3u8:'); if (!isset($this->input['zone'])) { $dates = urldecode($this->input['dates']) ? urldecode($this->input['dates']) : date("Y-m-d", time()); if ($play_time) { $dates = date("Y-m-d", $play_time); } } else { $zone = intval($this->input['zone']); if ($zone) { $dates = date('Y-m-d', strtotime($zone . ' day')); } else { $dates = date('Y-m-d'); } } $this->play_time = $play_time; $sql = "select id,channel_id,start_time,toff,theme,subtopic,type_id,dates,weeks,describes from " . DB_PREFIX . "program where channel_id=" . $this->channel_id . " AND dates='" . $dates . "' ORDER BY start_time ASC "; $q = $this->db->query($sql); $this->m = 0; $program_plan = $this->getPlan($dates); $program = array(); $start = strtotime($dates . " 00:00:00"); $end = strtotime($dates . " 23:59:59"); $com_time = 0; while ($row = $this->db->fetch_array($q)) { $start_time = $row['start_time']; $end_time = $row['start_time'] + $row['toff']; $display = $lave_time = $now_play = $zhi_play = 0; if (!$com_time && $start_time > $start) { $plan = $this->verify_plan($program_plan, $start, $start_time); if ($plan) { foreach ($plan as $k => $v) { $program[] = $v; } } else { $program[] = $this->getInfo($start, $start_time, $dates); } } if ($com_time && $com_time > $start_time) { $plan = $this->verify_plan($program_plan, $com_time, $start_time); if ($plan) { foreach ($plan as $k => $v) { $program[] = $v; } } else { $program[] = $this->getInfo($com_time, $start_time, $dates); } } if ($start_time < TIMENOW) { $display = 1; } if ($start_time < TIMENOW && $end_time > TIMENOW) { $zhi_play = 1; $lave_time = $end_time - TIMENOW; if (!$this->m && !$play_time) { $now_play = $this->m = 1; } } if ($play_time && $start_time <= $play_time && $end_time > $play_time) { $now_play = 1; $lave_time = 0; } $row['start'] = date("H:i", $start_time); $row['end'] = date("H:i", $end_time); $row['zhi_play'] = $zhi_play; $row['now_play'] = $now_play; $row['display'] = $display; $row['lave_time'] = $lave_time; if (!$row['theme']) { $row['theme'] = '精彩节目'; } $row['stime'] = date("H:i", $start_time); $com_time = $end_time; $program[] = $row; } if ($com_time && $com_time < $end) { $plan = $this->verify_plan($program_plan, $com_time, $end); if ($plan) { foreach ($plan as $k => $v) { $program[] = $v; } } else { $program[] = $this->getInfo($com_time, $end, $dates); } } if (empty($program)) { $this->m = 0; $program = $this->copy_program($start, $end); } /* include(CUR_CONF_PATH . 'lib/program_screen.class.php'); $this->screen = new programScreen(); $cond = " AND channel_id=" . $this->channel_id . " AND date='" . $dates . "'"; $screen = $this->screen->show($cond); if(!empty($program) && !empty($screen)) //处理屏蔽节目 { foreach($program as $k => $v) { if(!$v['new']) { $start_time = $v['start_time']; $end_time = $v['start_time'] + $v['toff']; foreach($screen as $key => $value) { if($value['start_time'] == $start_time && ($value['start_time']+$value['toff']) == $end_time) { $program[$k]['screen_id'] = $value['id']; return false; } else { if($value['start_time'] >= $start_time && $value['start_time'] < $end_time) { $program[$k]['screen_id'] = $value['id']; } if($value['start_time'] < $start_time) { if(($value['start_time']+$value['toff']) > $start_time) { $program[$k]['screen_id'] = $value['id']; } } } } } } } */ foreach ($program as $key => $value) { if ($value['start_time'] < TIMENOW - $channel_info['save_time'] * 3600) { $value['display'] = 0; } $value['channel_name'] = $channel_info['name']; $value['channel_logo'] = $channel_info['logo']; $value['channel_id'] = $channel_info['id']; $value['m3u8'] = isset($this->input['_config']) && $this->config[$this->channel_id] ? $this->config[$this->channel_id] . $value['start_time'] . '000,' . $value['toff'] . '000.m3u8' : str_replace('Backtime', $value['start_time'] . '000,' . ($value['start_time'] + $value['toff']) . '000.m3u8', $channel_info['m3u8']); $this->addItem($value); } $this->output(); }
public function get_back($channel_id_back) { $sql = "select * from " . DB_PREFIX . "channel c left join " . DB_PREFIX . "channel_stream s on c.id=s.channel_id where c.id=" . $channel_id_back; $f = $this->db->query_first($sql); $url = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $f['stream_mark'], 'stream_name' => $f['out_stream_name'])); return $url; }
/** * 修改台号 (code 只修改输出层和本地) * @name channelCodeEdit * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $channel_id int 频道id * @param $code_2 string 台号 * @return $code_2 string 修改后台号 * @include tvie_api.php */ public function channelCodeEdit() { $channel_id = intval($this->input['channel_id']); if (!$channel_id) { $this->errorOutput('未传入频道ID'); } $code_2 = urldecode($this->input['code_2']); //频道信息 $sql = "SELECT * FROM " . DB_PREFIX . "channel WHERE id=" . $channel_id; $channel_info = $this->db->query_first($sql); $name = $channel_info['name']; $code = $channel_info['code']; $stream_id = $channel_info['stream_id']; $delay_id = $channel_info['delay_id']; $chg_id = $channel_info['chg_id']; $out_id = $channel_info['ch_id']; $level = $channel_info['level']; $open_ts = $channel_info['open_ts']; $live_delay = $channel_info['live_delay']; $save_time = $channel_info['save_time']; $drm = $channel_info['drm']; //频道流信息 $sql = "SELECT * FROM " . DB_PREFIX . "channel_stream WHERE channel_id IN(" . $channel_id . ")"; $q = $this->db->query($sql); $channel_stream = $channel_stream_name = array(); while ($row = $this->db->fetch_array($q)) { $channel_stream[$row['stream_name']] = $row; $channel_stream_name[] = $row['stream_name']; } //信号信息 $sql = "SELECT * FROM " . DB_PREFIX . "stream WHERE id=" . $stream_id; $streams = $this->db->query_first($sql); $other_info = unserialize($streams['other_info']); //channel_stream和stream 组成的数据 $stream_name_arr = array(); foreach ($other_info as $v) { $stream_name_arr[$v['name']] = $v; } $stream_info_merge = array(); foreach ($channel_stream_name as $n) { if ($stream_name_arr[$n]) { $stream_info_merge[$n] = $stream_name_arr[$n]; } } //合并数据 $stream_info = array(); foreach ($channel_stream as $k => $v) { $stream_info[] = array_merge($stream_info_merge[$k], $channel_stream[$k]); } //开启tvie if ($this->settings['tvie']['open']) { include CUR_CONF_PATH . 'lib/tvie_api.php'; $delay_type = 'normal_virtual'; $out_tvie = new TVie_api($this->settings['tvie']['stream_server']); //删除输出层 if ($code_2 && $code_2 != $code) { $ret_out = $out_tvie->delete_channel($out_id); $out_live_delay = $live_delay; if ($level != 1) { $out_live_delay = 0; } else { if (!$save_time) { $save_time = 1; } } //创建输出层 if ($ret_out['message'] == 'Handled') { //无切播层,直接信号流地址 if ($level == 1) { $out_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $stream_info[0]['out_stream_name']), 'channels', 'tvie://'); } else { $out_stream_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $channel_info['code_2'], 'stream_name' => $stream_info[0]['out_stream_name']), 'channels', 'tvie://'); } if ($open_ts) { $stream_info[0]['backstore'] = array(0 => 'flv', 1 => 'ts'); } if (is_array($stream_info[0]['backstore'])) { $backstore = implode(',', $stream_info[0]['backstore']); } else { $backstore = $stream_info[0]['backstore']; } $out_channel = $out_tvie->create_channel($code_2, $name, $streams['server_id'], $save_time, $out_live_delay, $delay_type, $stream_info[0]['out_stream_name'], $stream_info[0]['recover_cache'], $stream_info[0]['source_name'], $out_stream_uri, $stream_info[0]['bitrate'], $drm, $stream_info[0]['wait_relay'], $backstore); $out_channel_id = $out_channel['channel_id']; //返回频道id // unset($stream_info[0]); $ret_out_channel_info = $out_tvie->get_channel_by_id($out_channel_id); $ret_out_stream_info = $ret_out_channel_info['channel']['streams']; $first_out_stream_id = $ret_out_stream_info[0]['id']; $stream_ids = array($ret_out_stream_info[0]['name'] => $first_out_stream_id); if ($out_channel_id) { foreach ($stream_info as $value) { if ($level == 1) { $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $streams['ch_name'], 'stream_name' => $value['out_stream_name']), 'channels', 'tvie://'); } else { $out_uri = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => 'chg_' . $channel_info['code_2'], 'stream_name' => $value['out_stream_name']), 'channels', 'tvie://'); } if ($open_ts) { $value['backstore'] = array(0 => 'flv', 1 => 'ts'); } if (is_array($value['backstore'])) { $backstore = implode(',', $value['backstore']); } else { $backstore = $value['backstore']; } $out_create_stream = $out_tvie->create_channel_stream($value['out_stream_name'], $value['recover_cache'], $value['source_name'], $out_uri, $drm, $backstore, $value['wait_relay'], 0, $value['bitrate'], $out_channel_id); if ($out_create_stream['stream_id']) { $stream_ids[$value['out_stream_name']] = $out_create_stream['stream_id']; } } foreach ($stream_info as $value) { //更新channel_stream $updateSql = "UPDATE " . DB_PREFIX . "channel_stream SET stream_id=" . $stream_id . ", out_stream_id=" . $stream_ids[$value['out_stream_name']] . ", stream_name='" . $value['name'] . "', update_time=" . TIMENOW; $updateSql .= " WHERE channel_id=" . $channel_id . " AND stream_name='" . $value['name'] . "'"; $this->db->query($updateSql); if ($channel_info['stream_state']) { $out_tvie->stop_stream($stream_ids[$value['out_stream_name']]); $out_tvie->start_stream($stream_ids[$value['out_stream_name']]); } else { $out_tvie->start_stream($stream_ids[$value['out_stream_name']]); $out_tvie->stop_stream($stream_ids[$value['out_stream_name']]); } } $up_sql = "UPDATE " . DB_PREFIX . "channel SET ch_id=" . $out_channel_id . ", code='" . $code_2 . "' WHERE id=" . $channel_id; $this->db->query($up_sql); } if ($out_channel_id) { $this->addItem($code_2); } else { return; } } } else { $this->addItem($code); } } $this->output(); }
public function emergency_change() { $channel_id = intval($this->input['channel_id']); if (!$channel_id) { $this->errorOutput('请选择要切播的频道'); } $stream_id = intval($this->input['stream_id']); $source = trim(urldecode($this->input['source'])); $bkfile_id = intval($this->input['bkfile_id']); if (!$stream_id && !$source) { $this->errorOutput('请选择要切播到的流或备播文件'); } $sql = "select main_stream_name,stream_id,live_delay,is_live,stream_state, chg_id, chg2_stream_id from " . DB_PREFIX . "channel where id=" . $channel_id; $channel_info = $this->db->query_first($sql); if (!$channel_info['stream_state']) { $this->errorOutput('频道尚未对外输出流'); } if (!$channel_info['is_live']) { $this->errorOutput('该频道不支持播出控制'); } $sql = "select id, ch_name,other_info,s_status from " . DB_PREFIX . "stream where id IN (" . $channel_info['stream_id'] . ',' . $stream_id . ')'; $q = $this->db->query($sql); $stream_info = array(); while ($r = $this->db->fetch_array($q)) { if (!$r['s_status']) { continue; } $r['other_info'] = unserialize($r['other_info']); $stream_info[$r['id']] = $r; } $live_stream_info = $stream_info[$channel_info['stream_id']]['other_info']; if (!$live_stream_info) { $this->errorOutput('频道尚未对外输出流'); } $chg_type = 'stream'; $beibo_stream_info = $stream_info[$stream_id]['other_info']; if (!$beibo_stream_info) { if (!$source) { $this->errorOutput('切播信号未启动,无法切播'); } else { $chg_type = 'file'; } } //与主信号流一致,回到直播 if ($stream_id == $channel_info['stream_id']) { include CUR_CONF_PATH . 'lib/channel_change.class.php'; $channel_changes = new ChannelChange(); $ret = $channel_changes->channel_resume($channel_info['chg_id']); if ($ret != 1) { $msg = array(-1 => '无法连接切播服务', 0 => '切播失败'); $this->errorOutput($msg[$ret_name]); } $sql = "UPDATE " . DB_PREFIX . "channel SET chg2_stream_id=0 WHERE id=" . $channel_id; $this->db->query($sql); $ret = array('msg' => $ret_name, 'stream_id' => $stream_id, 'chg_type' => $chg_type); $this->addItem($ret); $this->output(); } if ($chg_type == 'stream' && $stream_id == $channel_info['chg2_stream_id']) { $ret = array('msg' => $ret_name, 'stream_id' => $stream_id, 'chg_type' => $chg_type); $this->addItem($ret); $this->output(); } if ($channel_info['chg2_stream_id'] && $stream_id != $channel_info['chg2_stream_id']) { $this->errorOutput('频道正在切播中, 请先回到直播'); } //匹配码流一致 $stream_to = array(); foreach ($live_stream_info as $key => $value) { if ($value['name'] != $channel_info['main_stream_name']) { continue; } $stream_to[$value['name']] = $source; if ($beibo_stream_info) { foreach ($beibo_stream_info as $k => $v) { if (abs($value['bitrate'] - $v['bitrate']) < 200) { $stream_to[$value['name']] = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $stream_info[$stream_id]['ch_name'], 'stream_name' => $v['name'])); break; } } } } if (0 && $channel_info['live_delay']) { //有延时就记录数据 $stream_uri = array(); foreach ($stream_name_beibo as $key => $value) { $stream_uri[] = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $beibo['ch_name'], 'stream_name' => $value), 'channels', 'tvie://'); } $change_time = TIMENOW + $channel_info['live_delay'] * 60; include CUR_CONF_PATH . 'lib/channel_change_plan.class.php'; $channel_plan = new ChannelChangePlan(); $ret = $channel_plan->change_plan_create($channel_id, $stream_id, $stream_name_down, $stream_uri, $channel_info['stream_state'], $change_time, '', ''); } else { if (!$stream_to[$channel_info['main_stream_name']]) { $this->errorOutput('未找到匹配的流'); } include CUR_CONF_PATH . 'lib/channel_change.class.php'; $channel_changes = new ChannelChange(); $ret_name = $channel_changes->channel_emergency_change($channel_info['chg_id'], 'file', $stream_to[$channel_info['main_stream_name']]); if ($ret_name != 1) { $msg = array(-1 => '无法连接切播服务', 0 => '切播失败'); $this->errorOutput($msg[$ret_name]); } $sql = "UPDATE " . DB_PREFIX . "channel SET chg2_stream_id=" . ($stream_id ? $stream_id : $bkfile_id) . ", chg_type='{$chg_type}' WHERE id=" . $channel_id; $this->db->query($sql); } $ret = array('msg' => $ret_name, 'stream_id' => $stream_id, 'chg_type' => $chg_type); $this->addItem($ret); $this->output(); }
/** * * 设置提交数据的切播地址 * @param unknown_type $channel2_id * @param unknown_type $type 1 - 直播, 2 -文件 , 3 - 时移 */ public function set_chg_uris($channel2_id, $type) { if ($type == 2) { $sql = "select * from " . DB_PREFIX . "backup WHERE id=" . $channel2_id; $backup_info = $this->db->query_first($sql); if ($backup_info['vodinfo_id']) { $file_stream_uri = $this->settings['vod_url'] . $backup_info['filepath'] . $backup_info['newname']; } else { $file_stream_uri = UPLOAD_BACKUP_MMS_URL . $backup_info['newname']; } return $file_stream_uri; } else { $sql = "SELECT * FROM " . DB_PREFIX . "channel WHERE id=" . $channel2_id; $channel_info = $this->db->query_first($sql); $stream_uri = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $channel_info['main_stream_name']), 'live', 'tvie://'); return $stream_uri; } }
/** * * 设置提交数据的切播地址 * @name set_chg_uris * @access private * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $channel2_id array 来源类型ID * @param $type array 来源类型 (1-直播 2-文件 3-时移) * @global $mChgUris array 流地址 * @return true */ private function set_chg_uris($channel2_id, $type) { $channel_id = $file_id = array(); foreach ($channel2_id as $i => $id) { if ($type[$i] == 2) { $file_id[] = $id; } else { $channel_id[] = $id; } } if ($channel_id && $type[$i]) { $condition = " WHERE id IN(" . implode(',', $channel_id) . ")"; $sql = "SELECT id,code,main_stream_name FROM " . DB_PREFIX . "channel " . $condition; $q = $this->db->query($sql); $stream_uri = array(); while ($row = $this->db->fetch_array($q)) { $stream_uri[$row['id']] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $row['code'], 'stream_name' => $row['main_stream_name']), 'live', 'tvie://'); } } if ($file_id) { $sql = "SELECT id,vodinfo_id,filepath,newname FROM " . DB_PREFIX . "backup WHERE id IN(" . implode(',', $file_id) . ")"; $f = $this->db->query($sql); $file_stream_uri = array(); while ($r = $this->db->fetch_array($f)) { if ($r['vodinfo_id']) { $file_stream_uri[$r['id']] = $this->settings['vod_url'] . $r['filepath'] . $r['newname']; } else { $file_stream_uri[$r['id']] = UPLOAD_BACKUP_MMS_URL . $r['newname']; } } } foreach ($channel2_id as $i => $id) { if ($type[$i] == 2) { $this->mChgUris[$i] = $file_stream_uri[$id]; } else { $this->mChgUris[$i] = $stream_uri[$id]; } } return true; }
/** * 单条信息 * @name detail * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $id int 频道ID * @return $row array 单条频道信息 */ public function detail() { $id = urldecode($this->input['id']); if (!$id) { $condition = ' ORDER BY id DESC LIMIT 1'; } else { $condition = ' WHERE id in(' . $id . ')'; } $sql = "SELECT * FROM " . DB_PREFIX . "channel " . $condition; $row = $this->db->query_first($sql); $this->setXmlNode('channel', 'info'); if (is_array($row) && $row) { $row['create_time'] = date('Y-m-d H:i:s', $row['create_time']); $row['update_time'] = date('Y-m-d H:i:s', $row['update_time']); //串联单的模块id $row['relate_module_id'] = intval($this->input['relate_module_id']); $row['beibo'] = $row['beibo'] ? unserialize($row['beibo']) : array(); //流信息 $sql = "SELECT * FROM " . DB_PREFIX . "channel_stream WHERE channel_id IN(" . $id . ")"; $f = $this->db->query($sql); $row['stream_uri'] = $row['out_streams'] = $row['out_streams_uri'] = $row['ts_uri'] = $row['out_stream_name'] = $row['stream_name'] = array(); while ($r = $this->db->fetch_array($f)) { $row['stream_uri'][$r['stream_name']] = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $row['stream_mark'], 'stream_name' => $r['stream_name'])); $row['out_streams'][$r['out_stream_name']] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $row['code'], 'stream_name' => $r['out_stream_name'])); $row['out_streams_uri'][] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $row['code'], 'stream_name' => $r['out_stream_name'])); $row['ts_uri'][$r['out_stream_name']] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $row['code'], 'stream_name' => $r['out_stream_name']), 'channels', 'http://', 'm3u8:'); $row['out_stream_name'][] = $r['out_stream_name']; $row['stream_name'][] = $r['stream_name']; $row['count'] = count($row['stream_name']); } //信号流信息 if ($row['stream_id']) { $sql = "SELECT * FROM " . DB_PREFIX . "stream WHERE id=" . $row['stream_id']; $q = $this->db->query_first($sql); $other_info = unserialize($q['other_info']); if ($other_info) { $row['stream_name_all'] = array(); foreach ($other_info as $key => $value) { $row['stream_name_all'][] = $value['name']; } } //logo显示 $row['logo_info'] = unserialize($row['logo_info']); $row['logo'] = $row['logo_info']['filename']; if ($row['logo_info']) { $row['logo_url'] = hg_material_link($this->settings['material_server']['img4']['host'], $this->settings['material_server']['img4']['dir'], $row['logo_info']['filepath'], $row['logo_info']['filename']); } } $this->addItem($row); $this->output(); } else { $this->errorOutput('频道不存在'); } }
/** * 串联单显示 * @name show * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $condition 检索条件 * @param $channel_id int 频道ID * @param $dates string 格式化日期(Y-m-d) * @return $channel_name string 频道名称 * @return $channel_id int 频道ID * @return $dates_api string 格式化日期(Y-m-d) * @return $uri string 频道输出流地址 * @return $change array 某天串联单信息内容 */ public function show() { $condition = $this->get_condition(); $channel_id = intval($this->input['channel_id']); if (!$channel_id) { $this->errorOutput('未传入频道ID'); } $dates = $this->input['dates'] ? urldecode($this->input['dates']) : date('Y-m-d'); $sql = "SELECT * FROM " . DB_PREFIX . "channel_chg_plan "; $sql .= " WHERE channel_id=" . $channel_id . " AND dates='" . $dates . "'" . $condition . " ORDER BY change_time ASC "; $q = $this->db->query($sql); $sql = "SELECT * FROM " . DB_PREFIX . "channel c LEFT JOIN " . DB_PREFIX . "channel_stream s ON c.id=s.channel_id WHERE c.id=" . $channel_id; $channel_info = $this->db->query_first($sql); $uri = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $channel_info['code'], 'stream_name' => $channel_info['out_stream_name'])); $this->addItem_withkey('channel_name', $channel_info['name']); $this->addItem_withkey('channel_id', $channel_id); $this->addItem_withkey('dates_api', $dates); $this->addItem_withkey('uri', $uri); $change = array(); $start = strtotime($dates . " 00:00:00"); $end = strtotime($dates . " 23:59:59"); $com_time = 0; $today = date('Y-m-d', TIMENOW); $last_week_day = date('Y-m-d', strtotime($today) + (7 - date('N', strtotime($today))) * 86400); $change_plan = $this->getPlan($channel_id, $dates); if ($dates >= $today && $dates <= $last_week_day) { $change_plan = $this->getPlan($channel_id, $dates); } else { $change_plan = array(); } while ($row = $this->db->fetch_array($q)) { if (!$com_time && $row['change_time'] > $start) { $plan = $this->verify_plan($change_plan, $start, $row['change_time']); if ($plan) { foreach ($plan as $k => $v) { $change[] = $v; } } else { $change[] = $this->getInfo($start, $row['change_time'], $dates); } } if ($com_time && $com_time != $row['change_time']) { $plan = $this->verify_plan($change_plan, $com_time, $row['change_time']); if ($plan) { foreach ($plan as $k => $v) { $change[] = $v; } } else { $change[] = $this->getInfo($com_time, $row['change_time'], $dates); } } if ($row['change_time'] < TIMENOW) { $row['plan_status'] = 1; } else { $row['plan_status'] = 0; } $row['end_time'] = date('H:i:s', $row['change_time'] + $row['toff']); $row['start_time'] = date('H:i:s', $row['change_time']); $row['e_time'] = date('H:i:s', $row['program_start_time'] + $row['toff']); $row['s_time'] = date('m-d H:i:s', $row['program_start_time']); if ($row['program_start_time']) { $row['program_end_time'] = date('Y-m-d H:i:s', $row['program_start_time'] + $row['toff']); $row['program_start_time'] = date('Y-m-d H:i:s', $row['program_start_time']); } //文件 $sql = "select * from " . DB_PREFIX . "backup WHERE id=" . $row['channel2_id']; $file_name = $this->db->query_first($sql); $row['file_name'] = $file_name['title']; if ($file_name['toff']) { if (intval($file_name['toff'] / 1000 / 60)) { $row['file_toff'] = intval($file_name['toff'] / 1000 / 60) . "'" . intval(($file_name['toff'] / 1000 / 60 - intval($file_name['toff'] / 1000 / 60)) * 60) . '"'; } else { $row['file_toff'] = intval($file_name['toff'] / 1000) . '"'; } } $row['start'] = date("H:i:s", $row['change_time']); $row['end'] = date("H:i:s", $row['change_time'] + $row['toff']); $com_time = $row['change_time'] + $row['toff']; $change[] = $row; } if ($com_time && $com_time < $end) { $plan = $this->verify_plan($change_plan, $com_time, $end); if ($plan) { foreach ($plan as $k => $v) { $change[] = $v; } } else { // $change[] = $this->getInfo($com_time,$end,$dates); } } if (empty($change)) { $change = array(); $start = strtotime($dates . " 00:00:00"); $end = strtotime($dates . " 23:59:59"); $com_time = 0; foreach ($change_plan as $k => $v) { if (!$com_time && $v['change_time'] > $start) { $change[] = $this->getInfo($start, $v['change_time'], $dates); } if ($com_time && $com_time != $v['change_time']) { $change[] = $this->getInfo($com_time, $v['change_time'], $dates); } $v['start'] = date("H:i", $v['change_time']); $v['end'] = date("H:i", $v['change_time'] + $v['toff']); $com_time = $v['change_time'] + $v['toff']; $change[] = $v; } } $this->addItem($change); // hg_pre($change); $this->output(); }
/** * 直播列表显示 (包括当前播放节目信息) * @name show * @access public * @author lijiaying * @category hogesoft * @copyright hogesoft * @param $condition 检索条件 * @param $offset 分页参数 * @param $count 分页显示记录数 * @param $id int 频道ID * @param $return array 频道的核心数据 * @return $v array 所有频道直播内容信息 */ public function show() { $condition = $this->get_condition(); $offset = $this->input['offset'] ? $this->input['offset'] : 0; $count = $this->input['count'] ? intval($this->input['count']) : 20; $return = $this->obj->channelsInfo($condition, $offset, $count); //获取备播流地址 $id = trim(urldecode($this->input['id'])); if ($id) { if (!$return[$id]['is_live']) { $this->errorOutput('对不起, 该频道不支持播控!'); } $beibo_ids = @array_keys($return[$id]['beibo']); if ($beibo_ids) { $sql = "SELECT id,ch_name,other_info FROM " . DB_PREFIX . "stream WHERE id IN (" . implode(',', $beibo_ids) . ')'; $q = $this->db->query($sql); } else { $this->errorOutput('该频道没有备播信号'); } $beibo_stream_urls = array(); while ($r = $this->db->fetch_array($q)) { $r['other_info'] = unserialize($r['other_info']); $beibo_stream_urls[$r['id']] = $r; } foreach ($beibo_stream_urls as $k => $v) { foreach ($v['other_info'] as $vv) { $urls = hg_get_stream_url($this->settings['tvie']['up_stream_server'], array('channel' => $v['ch_name'], 'stream_name' => $vv['name'])); $all_beibo_stream_urls[$k][] = $urls; } $return[$id]['beibo_stream_urls'] = $all_beibo_stream_urls; } } $channel_id = @array_keys($return); $current_program = $this->get_current_program_item($channel_id, true); $live_program = $this->live_program($channel_id, TIMENOW); if ($return) { foreach ($return as $v) { if (is_array($v['streams'])) { $this->settings['tvie']['stream_server']['rand'] = 1; //$this->input['rand_stream'] 暂时这样处理 $v['primary_stream_url'] = $v['down_stream_url'] = array(); foreach ($v['streams'] as $vv) { $v['primary_stream_url'][] = $vv['stream_uri']; $v['down_stream_url'][] = hg_get_stream_url($this->settings['tvie']['stream_server'], array('channel' => $v['code'], 'stream_name' => $vv['out_stream_name'])); } } //获取当前频道正在播放的节目 if ($current_program[$v['id']]['pro']) { $v['current'] = $current_program[$v['id']]['pro']; $v['start_time'] = date('H:i:s', $current_program[$v['id']]['start_time']); $v['end_time'] = date('H:i:s', $current_program[$v['id']]['start_time'] + $current_program[$v['id']]['toff']); } else { if ($live_program[$v['id']]['current']) { $v['current'] = $live_program[$v['id']]['current']; $v['start_time'] = $live_program[$v['id']]['start_time']; $v['end_time'] = $live_program[$v['id']]['end_time']; } else { $v['current'] = '精彩节目'; $v['start_time'] = date('H:i:s'); $v['end_time'] = date('H:i:s', TIMENOW + 1800); } } $v['all_channel_ids'] = implode(',', $channel_id); $v['_snap'] = $current_program[$v['id']]['img']; $this->addItem($v); // hg_pre($v); } } $this->output(); }