public function get(RESTApiRequest $request, $parent_id)
 {
     $rec_id = $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");
     }
     $pvr = new \RemotePvr();
     $recording = $pvr->getById($rec_id);
     if (empty($recording)) {
         throw new RESTNotFound("Recording not found");
     }
     if ($recording['uid'] != $user_id) {
         throw new RESTNotFound("User don't have access to this recording");
     }
     try {
         $url = $pvr->getUrlByRecId($rec_id);
     } catch (\Exception $e) {
         throw new RESTServerError("Failed to obtain url");
     }
     if (preg_match("/(\\S+:\\/\\/\\S+)/", $url, $match)) {
         $url = $match[1];
     }
     return $url;
 }
 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);
 }
 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 create(RESTApiRequest $request, $parent_id)
 {
     $rec_id = $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");
     }
     $pvr = new \RemotePvr();
     $recording = $pvr->getById($rec_id);
     if (empty($recording)) {
         throw new RESTNotFound("Recording not found");
     }
     if ($recording['uid'] != $user_id) {
         throw new RESTNotFound("User don't have access to this recording");
     }
     return $pvr->stopRecById($rec_id);
 }
 private function setAllowedStoragesForChannel($id, $data)
 {
     if ($data['allow_pvr']) {
         \RemotePvr::setAllowedStoragesForChannel($id, $data['pvr_storage_names']);
     }
 }
示例#6
0
    preg_match("/(\\S+)\\s(\\S+):\\/\\/(\\d+).(\\d+).(\\d+).(\\d+):(\\d+)/", $addr, $tmp_arr);
    $img_str = '/iptv/mpg/' . $tmp_arr[6] . '_' . $tmp_arr[7] . '.mpg';
    return $img_str;
}
$tv_archive = new TvArchive();
$storages = Mysql::getInstance()->from('storages')->where(array('status' => 1, 'for_records' => 1, 'wowza_server' => 0))->get()->all();
$stream_servers = StreamServer::getAll();
$selected_storages = $selected_pvr_storages = array();
if (!empty($_GET['id'])) {
    $tasks = TvArchive::getTasksByChannelId((int) $_GET['id']);
    if (!empty($tasks)) {
        $selected_storages = array_map(function ($storage) {
            return $storage['storage_name'];
        }, $tasks);
    }
    $selected_pvr_storages = array_keys(RemotePvr::getStoragesForChannel((int) $_GET['id']));
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">

body {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
}
td {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    text-decoration: none;
 public function get(RESTApiRequest $request)
 {
     $pvr = new \RemotePvr();
     return $this->filter($pvr->prepareQuery()->where(array('uid' => $this->user_id))->get()->all());
 }
 public function delete(RESTApiRequest $request)
 {
     $pvr = new \RemotePvr();
     return $pvr->delRecById($this->recording['id']);
 }
 private function createFileRecord($user_rec_id)
 {
     $user_rec = Mysql::getInstance()->from('users_rec')->where(array('id' => $user_rec_id))->get()->first();
     if (empty($user_rec)) {
         throw new nPVRServerError();
     }
     $channel = Mysql::getInstance()->from('itv')->where(array('id' => $user_rec['ch_id']))->get()->first();
     if (empty($channel)) {
         throw new nPVRChannelNotFoundError();
     }
     $rec_file_id = Mysql::getInstance()->insert('rec_files', array('ch_id' => $user_rec['ch_id'], 't_start' => 'NOW()', 'atrack' => $user_rec['atrack'], 'vtrack' => $user_rec['vtrack']))->insert_id();
     $allowed_storages = array_keys(RemotePvr::getStoragesForChannel($user_rec['ch_id']));
     foreach ($this->storages as $name => $storage) {
         if (!in_array($name, $allowed_storages)) {
             continue;
         }
         if ($storage['load'] < 1) {
             try {
                 $file_name = $this->clients[$name]->resource('recorder')->create(array('url' => $channel['mc_cmd'], 'rec_id' => $rec_file_id, 'start_delay' => strtotime($user_rec['t_start']) - time(), 'duration' => $user_rec['length']));
             } catch (Exception $exception) {
                 try {
                     //stop recording just in case
                     $this->clients[$name]->resource('recorder')->ids($rec_file_id)->update();
                 } catch (Exception $exception) {
                     $this->parseException($exception);
                 }
                 $this->deleteUserRecord($user_rec_id);
                 $this->deleteFileRecord($rec_file_id);
                 $this->parseException($exception);
             }
         }
         if (!empty($file_name)) {
             break;
         }
     }
     if (empty($file_name)) {
         Mysql::getInstance()->update('users_rec', array('ended' => 1), array('id' => $user_rec_id));
         Mysql::getInstance()->update('rec_files', array('ended' => 1), array('id' => $rec_file_id));
         throw new nPVRServerError();
     }
     Mysql::getInstance()->update('rec_files', array('storage_name' => $name, 'file_name' => $file_name), array('id' => $rec_file_id));
     Mysql::getInstance()->update('users_rec', array('file_id' => $rec_file_id, 'started' => strtotime($user_rec['t_start']) - time() > 0 ? 0 : 1), array('id' => $user_rec_id));
     return $user_rec_id;
 }
    }
    if (preg_match('/(\\S+:\\/\\/\\S+)/', $url, $match)) {
        $url = $match[1];
    }
    if ($url) {
        header("Location: " . $url);
        ob_end_clean();
        exit;
    }
} elseif ($link['type'] == 'pvr') {
    $user = Stb::getById((int) $link['uid']);
    if (empty($user)) {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        exit;
    }
    $pvr = new RemotePvr();
    $recording = $pvr->getById($link['media_id']);
    if (empty($recording)) {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        exit;
    }
    if ($recording['uid'] != $link['uid']) {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        exit;
    }
    try {
        $url = $pvr->getUrlByRecId($link['media_id']);
    } catch (\Exception $e) {
        header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found");
        exit;
    }