public function get(RESTApiRequest $request, $user_id)
 {
     $recorder = new \StreamRecorder();
     $free = ceil($recorder->checkTotalUserRecordsLength($user_id) / 60);
     $total = \Config::getSafe('total_records_length', 600);
     return array('total' => $total, 'free' => $free);
 }
 public function create(RESTApiRequest $request, $parent_id)
 {
     if (empty($this->params['users.id'])) {
         throw new RESTBadRequest("User required");
     }
     $user_id = $this->params['users.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($parent_id, $user_channels)) {
         throw new RESTForbidden("User don't have access to this channel");
     }
     $channel = \Itv::getById($parent_id);
     if (empty($channel)) {
         throw new RESTNotFound("Channel not found");
     }
     if (!$channel['allow_pvr']) {
         throw new RESTForbidden("Channel does not support PVR");
     }
     $now_time = time();
     $start_time = (int) $request->getData('start_time');
     $end_time = (int) $request->getData('end_time');
     if ($start_time && $start_time < $now_time) {
         $start_time = $now_time;
     }
     if ($end_time) {
         if ($start_time && $end_time < $start_time || $end_time < $now_time) {
             throw new RESTNotAcceptable("Not acceptable time range");
         }
     }
     $pvr = new \RemotePvr();
     try {
         $rec_id = $pvr->startRecNowByChannelId($channel['id']);
     } catch (\nPVRException $e) {
         throw new RESTServerError($e->getMessage());
     }
     if (!$rec_id) {
         return false;
     }
     if ($end_time) {
         sleep(1);
         // give some time to dumpstream to startup
         $recorder = new \StreamRecorder();
         $recorder->stopDeferred($rec_id, ceil(($end_time - $now_time) / 60));
     }
     $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);
 }
Ejemplo n.º 3
0
 public function delRecById($rec_id)
 {
     $recorder = new StreamRecorder();
     return $recorder->del($rec_id);
 }
Ejemplo n.º 4
0
 public function getSimpleDataTable()
 {
     $ch_id = intval($_REQUEST['ch_id']);
     $date = $_REQUEST['date'];
     $page = intval($_REQUEST['p']);
     $default_page = false;
     $page_items = 10;
     $from = $date . ' 00:00:00';
     $to = $date . ' 23:59:59';
     //$epg = $this->getEpgForChannelsOnPeriod(array($ch_id), $from, $to);
     $program = Mysql::getInstance()->from('epg')->select('epg.*, UNIX_TIMESTAMP(epg.time) as start_timestamp, UNIX_TIMESTAMP(epg.time_to) as stop_timestamp, TIME_FORMAT(epg.time,"' . _('%H:%i') . '") as t_time, TIME_FORMAT(epg.time_to,"' . _('%H:%i') . '") as t_time_to')->where(array('epg.ch_id' => $ch_id, 'epg.time>=' => $from, 'epg.time<=' => $to))->orderby('epg.time')->get()->all();
     $total_items = count($program);
     $ch_idx = Mysql::getInstance()->from('epg')->count()->where(array('epg.ch_id' => $ch_id, 'epg.time>=' => $from, 'epg.time<' => date(Mysql::DATETIME_FORMAT)))->get()->counter();
     //var_dump($ch_idx, date('Y-m-d'));
     if ($page == 0) {
         $default_page = true;
         $page = ceil($ch_idx / $page_items);
         if ($page == 0) {
             $page = 1;
         }
         if ($date != date('Y-m-d')) {
             $page = 1;
             $default_page = false;
         }
     }
     $program = array_slice($program, ($page - 1) * $page_items, $page_items);
     $now = time();
     $recorder = new StreamRecorder();
     $user_rec_ids = $recorder->getDeferredRecordIdsForUser(Stb::getInstance()->id);
     $tv_archive = new TvArchive();
     $archived_recs = $tv_archive->getAllTasksAssoc();
     $reminder = new TvReminder();
     $reminders = $reminder->getAllActiveForMac(Stb::getInstance()->mac);
     //var_dump($reminders);
     for ($i = 0; $i < count($program); $i++) {
         if ($program[$i]['stop_timestamp'] < $now) {
             $program[$i]['open'] = 0;
         } else {
             $program[$i]['open'] = 1;
         }
         /*if ($program[$i]['start_timestamp'] < $now){
               $program[$i]['mark_memo'] = null;
           }*/
         //var_dump($reminders);
         if (array_key_exists($program[$i]['real_id'], $reminders)) {
             $program[$i]['mark_memo'] = 1;
         } else {
             $program[$i]['mark_memo'] = 0;
         }
         //if (in_array($program[$i]['id'], $user_rec_ids)){
         if (array_key_exists($program[$i]['real_id'], $user_rec_ids)) {
             $program[$i]['mark_rec'] = 1;
             $program[$i]['rec_id'] = $user_rec_ids[$program[$i]['real_id']];
         } else {
             $program[$i]['mark_rec'] = 0;
         }
         if (array_key_exists($program[$i]['ch_id'], $archived_recs)) {
             if ($program[$i]['start_timestamp'] > time() - $archived_recs[$program[$i]['ch_id']]['parts_number'] * 3600 && $program[$i]['stop_timestamp'] < time()) {
                 $program[$i]['mark_archive'] = 1;
             } else {
                 $program[$i]['mark_archive'] = 0;
             }
         } else {
             $program[$i]['mark_archive'] = 0;
         }
     }
     if ($default_page) {
         $cur_page = $page;
         $selected_item = $ch_idx - ($page - 1) * $page_items;
     } else {
         $cur_page = 0;
         $selected_item = 0;
     }
     return array('cur_page' => $cur_page, 'selected_item' => $selected_item, 'total_items' => $total_items, 'max_page_items' => $page_items, 'data' => $program);
 }