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 __construct(RESTApiResourcePvr $parent, array $params) { parent::__construct(); $this->parent = $parent; if (empty($params)) { return; } $this->id = (int) $params[0]; $pvr = new \RemotePvr(); $recording = $pvr->getById($this->id); if (empty($recording)) { throw new RESTNotFound("Recording not found"); } $this->recording = $recording; }
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); }
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; } if (preg_match('/(\\S+:\\/\\/\\S+)/', $url, $match)) {