public function create(RESTApiRequest $request, $parent_id)
 {
     if (empty($this->params['users.id'])) {
         throw new RESTBadRequest("User required");
     }
     if (empty($this->params['ch_id'])) {
         throw new RESTBadRequest("Channel ID required");
     }
     $user_id = (int) $this->params['users.id'];
     $ch_id = (int) $this->params['ch_id'];
     $program_id = (int) $parent_id;
     $user = \Stb::getById($user_id);
     if (empty($user)) {
         throw new RESTNotFound("User not found");
     }
     $itv = \Itv::getInstance();
     $user_channels = $itv->getAllUserChannelsIdsByUid($user['id']);
     if (!in_array($ch_id, $user_channels)) {
         throw new RESTForbidden("User don't have access to this channel");
     }
     $channel = \Itv::getById($ch_id);
     if (empty($channel)) {
         throw new RESTNotFound("Channel not found");
     }
     if (!$channel['allow_pvr']) {
         throw new RESTForbidden("Channel does not support PVR");
     }
     $program = \Epg::getById($program_id);
     if (empty($program)) {
         throw new RESTNotFound("Program not found");
     }
     if ($program['ch_id'] != $ch_id) {
         throw new RESTNotAcceptable("Channel of program mismatch");
     }
     if (strtotime($program['time']) < time()) {
         throw new RESTNotAcceptable("Start time in past");
     }
     $pvr = new \RemotePvr();
     try {
         $rec_id = $pvr->startRecDeferredById($program['real_id']);
     } catch (\nPVRException $e) {
         throw new RESTServerError($e->getMessage());
     }
     if (!$rec_id) {
         return false;
     }
     $recording = $pvr->getById($rec_id);
     return array('id' => $recording['id'], 'name' => $recording['program'], 'start_time' => strtotime($recording['t_start']), 'end_time' => strtotime($recording['t_stop']), 'ch_id' => (int) $recording['ch_id'], 'ch_name' => $channel['name'], 'status' => $recording['started'] ? $recording['ended'] ? 2 : 1 : 0);
 }
 public function get(RESTApiRequest $request, $parent_id)
 {
     $epg = \Epg::getById(intval($parent_id));
     if (empty($epg)) {
         throw new RESTNotFound("Program not found");
     }
     $channel = \Itv::getChannelById(intval($epg['ch_id']));
     if (empty($channel)) {
         throw new RESTNotFound("Channel not found");
     }
     if ($channel["enable_tv_archive"] != 1) {
         throw new RESTForbidden("This channel does not have tv archive");
     }
     try {
         $archive = new \TvArchive();
         $url = $archive->getUrlByProgramId(intval($epg['id']));
     } catch (\StorageSessionLimitException $e) {
         throw new RESTTemporaryUnavailable("Session limit");
     } catch (\Exception $e) {
         throw new RESTServerError("Failed to obtain url");
     }
     return $url;
 }
 public function add()
 {
     $ch_id = @intval($_REQUEST['ch_id']);
     $program_id = $_REQUEST['program_id'];
     $fire_ts = @intval($_REQUEST['fire_ts']);
     $program_name = $_REQUEST['program_name'];
     $memo = $this->db->from('tv_reminder')->where(array('mac' => $this->stb->mac, 'tv_program_real_id' => $program_id))->get()->first();
     if (!empty($memo)) {
         return false;
     }
     $channel = Itv::getById($ch_id);
     if (empty($channel)) {
         $dvb_channels = Itv::getInstance()->getDvbChannels();
         foreach ($dvb_channels as $dvb_channel) {
             if ($dvb_channel['id'] == $ch_id) {
                 $channel = $dvb_channel;
                 break;
             }
         }
     }
     if (empty($channel)) {
         return false;
     }
     if (isset($channel['type']) && $channel['type'] == 'dvb') {
         $program = array('id' => 0, 'real_id' => $program_id, 'time' => date("Y-m-d H:i:s", $fire_ts));
     } else {
         $program = Epg::getByRealId($program_id);
         if (empty($program)) {
             return false;
         }
     }
     $id = $this->db->insert('tv_reminder', array('mac' => $this->stb->mac, 'ch_id' => $ch_id, 'tv_program_id' => $program['id'], 'tv_program_real_id' => $program['real_id'], 'fire_time' => $program['time'], 'tv_program_name' => $program_name, 'added' => 'NOW()'))->insert_id();
     if (intval($id) <= 0) {
         return false;
     }
     return $this->getRaw()->where(array('tv_reminder.id' => $id))->get()->first();
 }
Esempio n. 4
0
        exit;
    } elseif (isset($_GET['status'])) {
        Admin::checkAccess(AdminAccess::ACCESS_CONTEXT_ACTION);
        Mysql::getInstance()->update('epg_setting', array('status' => (int) $_GET['status']), array('id' => (int) $_GET['id']));
        header("Location: epg_setting.php");
        exit;
    }
}
if (@$_GET['edit'] && !empty($id)) {
    $action_name = 'edit';
    $action_value = _('Save');
    $edit = Mysql::getInstance()->from('epg_setting')->where(array('id' => $id))->get()->first();
}
if (isset($_GET['update_epg'])) {
    Admin::checkAccess(AdminAccess::ACCESS_PAGE_ACTION);
    $epg = new Epg();
    if (isset($_GET['force'])) {
        $force = true;
    } else {
        $force = false;
    }
    $error = $epg->updateEpg($force);
}
$settings = Mysql::getInstance()->from('epg_setting')->get()->all();
$debug = '<!--' . ob_get_contents() . '-->';
ob_clean();
echo $debug;
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Esempio n. 5
0
 public function getShortEpg()
 {
     $ch_id = intval($_REQUEST['ch_id']);
     $channel = Itv::getById($ch_id);
     if (empty($channel['xmltv_id'])) {
         return array();
     }
     $epg = new Epg();
     return $epg->getCurProgramAndFiveNext($ch_id);
 }
 public function update_epg()
 {
     if (!$this->isAjax || $this->method != 'POST' || empty($this->postData['id'])) {
         $this->app->abort(404, 'Page not found...');
     }
     if ($no_auth = $this->checkAuth()) {
         return $no_auth;
     }
     $data = array();
     $data['action'] = 'manageEPG';
     $data['id'] = $this->postData['id'];
     $error = '';
     $epg = new \Epg();
     $data['msg'] = nl2br($epg->updateEpg(!empty($this->postData['force'])));
     $response = $this->generateAjaxResponse($data, $error);
     return new Response(json_encode($response), empty($error) ? 200 : 500);
 }
 public function getNextPartUrl()
 {
     $program_id = $_REQUEST['id'];
     if (!$program_id) {
         return false;
     }
     $program = Epg::getByRealId($program_id);
     if (empty($program)) {
         if (preg_match("/(\\d+)_(\\d+)/", $program_id, $match)) {
             $next = Mysql::getInstance()->from('epg')->where(array('ch_id' => (int) $match[1], 'time>' => date("Y-m-d H:i:s", (int) $match[2])))->orderby('time')->limit(1)->get()->first();
         } else {
             return false;
         }
     } else {
         $next = Mysql::getInstance()->from('epg')->where(array('ch_id' => $program['ch_id'], 'time>' => $program['time']))->orderby('time')->limit(1)->get()->first();
     }
     if (empty($next)) {
         return false;
     }
     try {
         if ($next['time'] != $program['time_to'] && !isset($match)) {
             $program = array('name' => '[' . _('Break in the program') . ']', 'ch_id' => $next['ch_id'], 'time' => $program['time_to'], 'time_to' => $next['time'], 'real_id' => $next['ch_id'] . '_' . strtotime($program['time_to']));
             return Config::getSafe('tv_archive_player_solution', 'ffmpeg') . ' ' . $this->getUrlByProgramId(0, true, $program);
         } else {
             return Config::getSafe('tv_archive_player_solution', 'ffmpeg') . ' ' . $this->getUrlByProgramId($next['id'], true);
         }
     } catch (StorageSessionLimitException $e) {
         return false;
     }
 }
 private function createUserRecord($channel, $auto_start = true, $start_time = 0, $on_stb = false, $virtual_program = null)
 {
     if (!$on_stb) {
         $rest_length = $this->checkTotalUserRecordsLength($this->stb->id);
         if ($rest_length <= 0) {
             throw new nPVRTotalLengthLimitError();
         }
     } else {
         $rest_length = 0;
     }
     preg_match("/vtrack:(\\d+)/", $channel['mc_cmd'], $vtrack_arr);
     preg_match("/atrack:(\\d+)/", $channel['mc_cmd'], $atrack_arr);
     $vtrack = '';
     $atrack = '';
     if (count($vtrack_arr) > 0) {
         $vtrack = intval($vtrack_arr[1]);
     }
     if (count($atrack_arr)) {
         $atrack = intval($atrack_arr[1]);
     }
     $data = array('ch_id' => $channel['id'], 'uid' => $this->stb->id, 'atrack' => $atrack, 'vtrack' => $vtrack);
     $epg = new Epg();
     if ($auto_start) {
         if ($rest_length / 60 - Config::get('record_max_length') < 0) {
             $length = $rest_length;
         } else {
             $length = Config::get('record_max_length') * 60;
         }
         if ($length < 0) {
             throw new nPVRTotalLengthLimitError();
         }
         $program = $epg->getCurProgram($channel['id']);
         $data['program'] = $program['name'];
         $data['t_start'] = 'NOW()';
         $data['started'] = 1;
         $data['local'] = (int) $on_stb;
         $data['length'] = $length;
         $data['t_stop'] = date("Y-m-d H:i:s", time() + $length);
     } else {
         $program = $epg->getProgramByChannelAndTime($channel['id'], $start_time);
         if ($virtual_program && is_array($virtual_program) && !array_key_exists('id', $virtual_program)) {
             $program['time'] = $virtual_program['time'];
             $program['time_to'] = $virtual_program['time_to'];
             $start_time = $program['time'];
         } elseif ($virtual_program) {
             $virtual_program['name'] = $program['name'];
             $program = $virtual_program;
         }
         $length = strtotime($program['time_to']) - strtotime($program['time']);
         if ($length < 0) {
             throw new nPVRServerError();
         }
         if (!$on_stb && $rest_length - $length <= 0) {
             throw new nPVRTotalLengthLimitError();
         }
         $data['program'] = $program['name'];
         $data['program_id'] = $program['id'];
         $data['program_real_id'] = $program['real_id'];
         $data['t_start'] = $start_time;
         $data['length'] = $length;
         $data['t_stop'] = date("Y-m-d H:i:s", strtotime($start_time) + $length);
         $data['local'] = (int) $on_stb;
     }
     $user_rec_id = Mysql::getInstance()->insert('users_rec', $data)->insert_id();
     if ($on_stb) {
         return $user_rec_id;
     } else {
         $t_start = Mysql::getInstance()->from('users_rec')->where(array('id' => $user_rec_id))->get()->first('t_start');
         $t_stop = date("Y-m-d H:i:s", strtotime($t_start) + $length);
         Mysql::getInstance()->update('users_rec', array('length' => $length, 't_stop' => $t_stop), array('id' => $user_rec_id));
     }
     return $this->createFileRecord($user_rec_id);
 }
Esempio n. 9
0
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php 
set_time_limit(0);
include "./common.php";
$epg = new Epg();
if (isset($_GET['force'])) {
    $force = true;
} else {
    $force = false;
}
echo "<pre>";
echo $epg->updateEpg($force);
echo "</pre>";
?>
</body>
</html>