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 get(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(); $this->user_channels = $itv->getAllUserChannelsIdsByUid($user['id']); if (!in_array($parent_id, $this->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"); } $start = $request->getParam('start'); if ($start) { // todo: time shift! throw new RESTNotFound("Time shift in progress..."); } $urls = \Itv::getUrlsForChannel($channel['id']); if (!empty($urls)) { $link = $urls[0]['id']; } else { $link = null; } try { $url = $itv->getUrlByChannelId($parent_id, $link); } catch (\ItvChannelTemporaryUnavailable $e) { throw new RESTNotFound($e->getMessage()); } if (preg_match("/(\\S+:\\/\\/\\S+)/", $url, $match)) { $url = $match[1]; } 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(); }
public static function getLogoUriById($id, $resolution = 320) { $channel = Itv::getById($id); if (empty($channel['logo'])) { //return Config::get('portal_url').'misc/logos/dummy.png'; return ""; } return Config::get('portal_url') . 'misc/logos/' . $resolution . '/' . $channel['logo']; }
/** * Main claim method. * * @param string $media_type */ protected function setClaimGlobal($media_type) { $id = intval($_REQUEST['id']); $type = $_REQUEST['real_type']; $this->db->insert('media_claims_log', array('media_type' => $media_type, 'media_id' => $id, 'type' => $type, 'uid' => $this->stb->id, 'added' => 'NOW()')); $total_media_claims = $this->db->from('media_claims')->where(array('media_type' => $media_type, 'media_id' => $id))->get()->first(); $sound_counter = 0; $video_counter = 0; $no_epg_counter = 0; $wrong_epg_counter = 0; if ($type == 'video') { $video_counter++; } else { if ($type == 'sound') { $sound_counter++; } else { if ($type == 'no_epg') { $no_epg_counter++; } else { if ($type == 'wrong_epg') { $wrong_epg_counter++; } } } } if (!empty($total_media_claims)) { $this->db->update('media_claims', array('sound_counter' => $total_media_claims['sound_counter'] + $sound_counter, 'video_counter' => $total_media_claims['video_counter'] + $video_counter, 'no_epg' => $total_media_claims['no_epg'] + $no_epg_counter, 'wrong_epg' => $total_media_claims['wrong_epg'] + $wrong_epg_counter), array('media_type' => $media_type, 'media_id' => $id)); } else { $this->db->insert('media_claims', array('sound_counter' => $sound_counter, 'video_counter' => $video_counter, 'no_epg' => $no_epg_counter, 'wrong_epg' => $wrong_epg_counter, 'media_type' => $media_type, 'media_id' => $id)); } $total_daily_claims = $this->db->from('daily_media_claims')->where(array('date' => 'CURDATE()'))->get()->first(); $media_name = 'undefined'; if ($media_type == 'itv') { $media = Itv::getById($id); if (!empty($media['name'])) { $media_name = $media['name']; } } elseif ($media_type == 'vclub') { $media = Video::getById($id); if (!empty($media['name'])) { $media_name = $media['name']; } } elseif ($media_type == 'karaoke') { $media = Karaoke::getById($id); if (!empty($media['name'])) { $media_name = $media['name']; } } if (Config::exist('administrator_email')) { $message = sprintf(_("New claim on %s - %s (%s, id: %s). From %s"), $media_type, $type, $media_name, $id, $this->stb->mac); mail(Config::get('administrator_email'), 'New claim on ' . $media_type . ' - ' . $type, $message, "Content-type: text/html; charset=UTF-8\r\n"); } if (!empty($total_daily_claims)) { return $this->db->update('daily_media_claims', array($media_type . '_sound' => $total_daily_claims[$media_type . '_sound'] + $sound_counter, $media_type . '_video' => $total_daily_claims[$media_type . '_video'] + $video_counter, 'no_epg' => $total_daily_claims['no_epg'] + $no_epg_counter, 'wrong_epg' => $total_daily_claims['wrong_epg'] + $wrong_epg_counter), array('date' => 'CURDATE()'))->result(); } else { return $this->db->insert('daily_media_claims', array($media_type . '_sound' => $sound_counter, $media_type . '_video' => $video_counter, 'no_epg' => $no_epg_counter, 'wrong_epg' => $wrong_epg_counter, 'date' => 'CURDATE()'))->insert_id(); } }
} echo "</td>\n"; echo "<td class='list' nowrap><a href='?edit=1&id=" . $arr['id'] . "#form'>edit</a> "; //echo "<a href='?del=1&id=".$arr['id']."' >del</a> "; echo "<a href='#' onclick='if(confirm(\"" . htmlspecialchars(_('Do you really want to delete this record?'), ENT_QUOTES) . "\")){document.location=\"add_itv.php?del=1&id=" . $arr['id'] . "&letter=" . @$_GET['letter'] . "&search=" . @$_GET['search'] . "\"}'>del</a> \n"; if ($arr['status']) { echo "<a href='?status=0&id=" . $arr['id'] . "'><font color='Green'>on</font></a> "; } else { echo "<a href='?status=1&id=" . $arr['id'] . "'><font color='Red'>off</font></a> "; } echo "<a href='add_epg.php?id=" . $arr['id'] . "'>EPG</a> </td>"; echo "</tr>"; } echo "</table></center>"; if (@$_GET['edit']) { $arr = Itv::getById(intval(@$_GET['id'])); if (!empty($arr)) { $name = $arr['name']; $number = $arr['number']; $cmd = $arr['cmd']; $mc_cmd = $arr['mc_cmd']; $tv_genre_id = $arr['tv_genre_id']; $descr = $arr['descr']; $status = $arr['status']; $status = $arr['status']; $censored = $arr['censored']; $base_ch = $arr['base_ch']; $bonus_ch = $arr['bonus_ch']; $cost = $arr['cost']; $hd = $arr['hd']; $xmltv_id = $arr['xmltv_id'];
public function log() { $action = strval($_REQUEST['real_action']); $param = urldecode($_REQUEST['param']); $type = $_REQUEST['tmp_type']; if ($type == 1 && !empty($_REQUEST['ch_id'])) { $param = $this->db->from('itv')->where(array('id' => (int) $_REQUEST['ch_id']))->get()->first('cmd'); } $this->db->insert('user_log', array('mac' => $this->mac, 'action' => $action, 'param' => $param, 'time' => 'NOW()', 'type' => $type)); $update_data = array(); if ($action == 'play') { $update_data['now_playing_start'] = 'NOW()'; switch ($type) { case 1: // TV if (!empty($_REQUEST['ch_id'])) { $ch_name = Itv::getChannelNameById((int) $_REQUEST['ch_id']); } else { $ch_name = $this->db->from('ch_links')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.url' => $param, 'ch_links.status' => 1))->get()->first('name'); } if (empty($ch_name)) { $ch_name = $param; } $update_data['now_playing_content'] = $ch_name; if (!empty($_REQUEST['link_id'])) { $update_data['now_playing_link_id'] = $_REQUEST['link_id']; } else { $update_data['now_playing_link_id'] = 0; } if (!empty($_REQUEST['streamer_id'])) { $update_data['now_playing_streamer_id'] = $_REQUEST['streamer_id']; } else { $update_data['now_playing_streamer_id'] = 0; } break; case 2: // Video Club $param = preg_replace('/\\s+position:\\d+/', '', $param); if (strpos($param, '://') !== false) { $video = $this->db->from('video')->where(array('rtsp_url' => $param, 'protocol' => 'custom'))->get()->first(); if (empty($video)) { preg_match("/\\/([^\\/]+)\\/[^\\/]+\\/(\\d+)\\.[a-z0-9]*/", $param, $tmp_arr); } } else { preg_match("/auto \\/media\\/([\\S\\s]+)\\/(\\d+)\\.[a-z0-9]*/", $param, $tmp_arr); } if (empty($video) && !empty($tmp_arr)) { $storage = $tmp_arr[1]; $media_id = intval($tmp_arr[2]); $video = $this->db->from('video')->where(array('id' => $media_id))->get()->first(); $update_data['storage_name'] = $storage; } if (!empty($video)) { $update_data['now_playing_content'] = $video['name']; $update_data['hd_content'] = (int) $video['hd']; if (Config::getSafe('enable_tariff_plans', false)) { $user = User::getInstance(Stb::getInstance()->id); $package = $user->getPackageByVideoId($video['id']); if (!empty($package) && $package['service_type'] == 'single') { $video_rent_history = Mysql::getInstance()->from('video_rent_history')->where(array('video_id' => $video['id'], 'uid' => Stb::getInstance()->id))->orderby('rent_date', 'DESC')->get()->first(); if (!empty($video_rent_history)) { $rent_data_update = array(); if ($video_rent_history['start_watching_date'] == '0000-00-00 00:00:00') { $rent_data_update['start_watching_date'] = 'NOW()'; } //$rent_data_update['watched'] = $video_rent_history['watched'] + 1; if (!empty($rent_data_update)) { Mysql::getInstance()->update('video_rent_history', $rent_data_update, array('id' => $video_rent_history['id'])); } } } } } else { $update_data['now_playing_content'] = $param; } break; case 3: // Karaoke preg_match("/(\\d+).mpg/", $param, $tmp_arr); $karaoke_id = intval($tmp_arr[1]); $karaoke = $this->db->from('karaoke')->where(array('id' => $karaoke_id))->get()->first(); if (!empty($karaoke)) { $update_data['now_playing_content'] = $karaoke['name']; } else { $update_data['now_playing_content'] = $param; } break; case 4: // Audio Club if (!empty($_REQUEST['content_id'])) { $audio = Mysql::getInstance()->select('audio_compositions.name as track_title, audio_albums.performer_id')->from('audio_compositions')->where(array('audio_compositions.id' => (int) $_REQUEST['content_id']))->join('audio_albums', 'audio_albums.id', 'audio_compositions.album_id', 'INNER')->get()->first(); if ($audio) { $performer = Mysql::getInstance()->from('audio_performers')->where(array('id' => $audio['performer_id']))->get()->first(); if ($performer) { $update_data['now_playing_content'] = $performer['name'] . ' - ' . $audio['track_title']; } } } else { $update_data['now_playing_content'] = $param; } break; case 5: // Radio $radio = $this->db->from('radio')->where(array('cmd' => $param, 'status' => 1))->get()->first(); if (!empty($radio)) { $update_data['now_playing_content'] = $radio['name']; } else { $update_data['now_playing_content'] = $param; } break; case 6: // My Records break; case 7: // Shared Records break; case 8: // Video clips break; case 11: if (preg_match("/http:\\/\\/([^:\\/]*)/", $param, $tmp_arr)) { $storage_ip = $tmp_arr[1]; $update_data['storage_name'] = Mysql::getInstance()->from('storages')->where(array('storage_ip' => $storage_ip, 'for_records' => 1))->get()->first('storage_name'); } if (empty($update_data['storage_name']) && preg_match("/http:\\/\\/([^\\/]*)/", $param, $tmp_arr)) { $storage_ip = $tmp_arr[1]; $update_data['storage_name'] = Mysql::getInstance()->from('storages')->where(array('storage_ip' => $storage_ip, 'for_records' => 1))->get()->first('storage_name'); } $update_data['now_playing_content'] = $param; if (preg_match("/ch_id=(\\d+)/", $param, $match)) { $ch_id = $match[1]; $channel = Itv::getById($ch_id); if (!empty($channel)) { $update_data['now_playing_content'] = $channel['name']; } } break; case 14: if (preg_match("/http:\\/\\/([^:\\/]*)/", $param, $tmp_arr)) { $storage_ip = $tmp_arr[1]; $update_data['storage_name'] = Mysql::getInstance()->from('storages')->where(array('storage_ip' => $storage_ip, 'for_records' => 1))->get()->first('storage_name'); } if (empty($update_data['storage_name']) && preg_match("/http:\\/\\/([^\\/]*)/", $param, $tmp_arr)) { $storage_ip = $tmp_arr[1]; $update_data['storage_name'] = Mysql::getInstance()->from('storages')->where(array('storage_ip' => $storage_ip, 'for_records' => 1))->get()->first('storage_name'); } $update_data['now_playing_content'] = $param; if (preg_match("/\\/archive\\/(\\d+)\\//", $param, $match)) { $ch_id = $match[1]; $channel = Itv::getById($ch_id); if (!empty($channel)) { $update_data['now_playing_content'] = $channel['name']; } } break; default: $update_data['now_playing_content'] = 'unknown media ' . $param; } } if ($action == 'infoportal') { $update_data['now_playing_start'] = 'NOW()'; $info_arr = array(20 => 'city_info', 21 => 'anec_page', 22 => 'weather_page', 23 => 'game_page', 24 => 'horoscope_page', 25 => 'course_page'); if (@$info_arr[$type]) { $info_name = $info_arr[$type]; } else { $info_name = 'unknown'; } $update_data['now_playing_content'] = $info_name; } if ($action == 'stop' || $action == 'close_infoportal') { $update_data['now_playing_content'] = ''; $update_data['storage_name'] = ''; $update_data['hd_content'] = 0; $update_data['now_playing_link_id'] = 0; $update_data['now_playing_streamer_id'] = 0; $type = 0; } if ($action == 'pause') { $this->db->insert('vclub_paused', array('uid' => $this->id, 'mac' => $this->mac, 'pause_time' => 'NOW()')); } if ($action == 'continue' || $action == 'stop' || $action == 'set_pos()' || $action == 'play') { $this->db->delete('vclub_paused', array('mac' => $this->mac)); } if ($action == 'readed_anec') { return $this->db->insert('readed_anec', array('mac' => $this->mac, 'readed' => 'NOW()')); } if ($action == 'loading_fail') { return $this->db->insert('loading_fail', array('mac' => $this->mac, 'added' => 'NOW()')); } $update_data['last_active'] = 'NOW()'; $update_data['keep_alive'] = 'NOW()'; $update_data['now_playing_type'] = $type; $this->db->update('users', $update_data, array('mac' => $this->mac)); return 1; }
public function getAllProgramForCh() { $ch_id = intval($_REQUEST['ch_id']); $channel = Itv::getById($ch_id); if (empty($channel)) { return array(); } return $this->db->select('UNIX_TIMESTAMP(time) as start_timestamp, UNIX_TIMESTAMP(time_to) as stop_timestamp, name')->from('epg')->where(array('ch_id' => $ch_id, 'time>' => date('Y-m-d H:i:s', strtotime('-' . $channel['tv_archive_duration'] . ' hours'))))->orderby('time')->get()->all(); }
<?php if (@$_GET['saved']) { echo _('Saving was successful'); } ?> </strong> </font> <br> <br> </td> </tr> <tr> <td> <?php if (@$_GET['edit']) { $channel = Itv::getById(intval(@$_GET['id'])); if (!empty($channel)) { $name = $channel['name']; $cmd = $channel['cmd']; $descr = $channel['descr']; $status = $channel['status']; } } ?> <script> function save(){ form = document.getElementById('form'); name = document.getElementById('name').value; cmd = document.getElementById('cmd').value; id = document.getElementById('id').value;