public function create(RESTApiRequest $request, $parent_id) { $type = $request->getData('type'); $media_id = (int) $request->getData('media_id'); if (empty($type)) { throw new RESTBadRequest("Type is empty"); } if (empty($media_id)) { throw new RESTBadRequest("Media ID is empty"); } if (empty($this->types_map[$type])) { throw new RESTBadRequest("Type is not supported"); } $media = \Mysql::getInstance()->from($this->types_map[$type]['target'])->where(array('id' => $media_id))->get()->first(); if (empty($media)) { throw new RESTNotFound("Media not found"); } //todo: save storage name for video and karaoke? //todo: load balancing if ($type == 'tv-archive') { $channel = \Itv::getChannelById($media['ch_id']); $now_playing_content = $channel ? $channel['name'] : '--'; } else { $now_playing_content = $media[$this->types_map[$type]['title_field']]; } return \Mysql::getInstance()->update('users', array('now_playing_type' => $this->types_map[$type]['code'], 'now_playing_link_id' => $media_id, 'now_playing_content' => $now_playing_content, 'now_playing_start' => 'NOW()', 'last_active' => 'NOW()'), array('id' => $parent_id))->result(); }
public function get(RESTApiRequest $request) { //throw new RESTNotAllowedMethod("Please use /tv-channel/[ch_id]/epg instead"); if (empty($this->nested_params['ch_id'])) { throw new RESTBadRequest("ch_id required"); } $ch_ids = explode(',', $this->nested_params['ch_id']); $epg_data = array(); foreach ($ch_ids as $ch_id) { $channel = \Itv::getChannelById((int) $ch_id); if (empty($channel)) { throw new RESTNotFound("Channel " . intval($ch_id) . " not found"); } $from = (int) $request->getParam('from'); $to = (int) $request->getParam('to'); $next = (int) $request->getParam('next'); if (!empty($next)) { $epg_data[(int) $ch_id] = $this->filter($this->manager->getCurProgramAndFewNext($channel['id'], $next)); } else { $from = empty($from) ? "" : date("Y-m-d H:i:s", $from); $to = empty($to) ? "" : date("Y-m-d H:i:s", $to); $epg = $this->manager->getEpgForChannelsOnPeriod(array($channel['id']), $from, $to); $epg_data[(int) $ch_id] = $this->filter($epg[$channel['id']]); } } if (count($epg_data) == 1) { $keys = array_keys($epg_data); return $epg_data[$keys[0]]; } else { return $epg_data; } }
public function get(RESTRequest $request) { $ids = $request->getIdentifiers(); if (empty($ids[0])) { throw new ErrorException('Empty token'); } return Itv::checkTemporaryLink($ids[0]); }
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(array $nested_params, array $external_params) { parent::__construct($nested_params, $external_params); $this->document = new RESTApiTvFavoriteDocument($this, $this->external_params); if (empty($this->nested_params['users.id'])) { throw new RESTBadRequest("User must be specified"); } $user_id = $this->nested_params['users.id']; $user = \Stb::getById($user_id); if (empty($user)) { throw new RESTNotFound("User not found"); } $this->user_id = $user['id']; $this->manager = \Itv::getInstance(); }
public static function getGoodStreamersIdsForLink($link_id) { $link = Itv::getLinkById($link_id); if (empty($link)) { return false; } $ch_link_on_streamer = Mysql::getInstance()->from('ch_link_on_streamer')->where(array('link_id' => $link_id))->get()->all(); if ($link['enable_monitoring'] && $link['enable_balancer_monitoring']) { $ch_link_on_streamer = array_values(array_filter($ch_link_on_streamer, function ($link_on_streamer) { return $link_on_streamer['monitoring_status'] == 1; })); } $ch_link_on_streamer = array_map(function ($link_on_streamer) { return $link_on_streamer['streamer_id']; }, $ch_link_on_streamer); return $ch_link_on_streamer; }
public function create(RESTApiRequest $request, $parent_id) { $type = $request->getData('type'); $media_id = (int) $request->getData('media_id'); if (empty($type)) { throw new RESTBadRequest("Type is empty"); } if (empty($media_id)) { throw new RESTBadRequest("Media ID is empty"); } if (empty($this->types_map[$type])) { throw new RESTBadRequest("Type is not supported"); } $media = \Mysql::getInstance()->from($this->types_map[$type]['target'])->where(array('id' => $media_id))->get()->first(); if (empty($media)) { throw new RESTNotFound("Media not found"); } $cache = \Cache::getInstance(); $playback_session = $cache->get($parent_id . '_playback'); if (!empty($playback_session) && is_array($playback_session)) { if ($playback_session['type'] == 'tv-channel' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['streamer_id'])) { $now_playing_streamer_id = $playback_session['streamer_id']; } else { if ($playback_session['type'] == 'video' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['storage'])) { $storage_name = $playback_session['storage']; } else { if ($playback_session['type'] == 'karaoke' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['storage'])) { $storage_name = $playback_session['storage']; } else { if ($playback_session['type'] == 'tv-archive' && isset($playback_session['id']) && $playback_session['id'] == $media_id && !empty($playback_session['storage'])) { $storage_name = $playback_session['storage']; } } } } } if ($type == 'tv-archive') { $channel = \Itv::getChannelById($media['ch_id']); $now_playing_content = $channel ? $channel['name'] : '--'; } else { $now_playing_content = $media[$this->types_map[$type]['title_field']]; } \Mysql::getInstance()->insert('user_log', array('uid' => $parent_id, 'action' => 'play', 'param' => $now_playing_content, 'time' => 'NOW()', 'type' => $this->types_map[$type]['code'])); return \Mysql::getInstance()->update('users', array('now_playing_type' => $this->types_map[$type]['code'], 'now_playing_link_id' => $media_id, 'now_playing_content' => $now_playing_content, 'now_playing_streamer_id' => isset($now_playing_streamer_id) ? $now_playing_streamer_id : 0, 'storage_name' => isset($storage_name) ? $storage_name : '', 'now_playing_start' => 'NOW()', 'last_active' => 'NOW()'), array('id' => $parent_id))->result(); }
public function getAllActive() { $memos = $this->getRaw()->where(array('tv_reminder.mac' => $this->stb->mac, 'tv_reminder.fire_time>' => 'NOW()'))->get()->all(); $dvb_memos = $this->db->select('UNIX_TIMESTAMP(`fire_time`) as fire_ts, TIME_FORMAT(`fire_time`,"%H:%i") as t_fire_time, ch_id, tv_program_id, tv_program_real_id, tv_program_name as program_name')->from('tv_reminder')->where(array('tv_reminder.mac' => $this->stb->mac, 'tv_reminder.fire_time>' => 'NOW()', 'tv_reminder.tv_program_id' => 0))->get()->all(); $dvb_channels_map = array(); $dvb_channels = Itv::getInstance()->getDvbChannels(); foreach ($dvb_channels as $dvb_channel) { $dvb_channels_map[$dvb_channel['id']] = $dvb_channel; } $dvb_memos = array_map(function ($memo) use($dvb_channels_map) { if (!empty($dvb_channels_map[$memo['ch_id']])) { $memo['itv_name'] = $dvb_channels_map[$memo['ch_id']]['name']; } return $memo; }, $dvb_memos); $memos = array_merge($memos, $dvb_memos); return $memos; }
private function getLinkByRecId($rec_id) { $item = self::getById($rec_id); $master = new StreamRecorder(); try { $res = $master->play($rec_id, 0, false, $item['storage_name']); } catch (Exception $e) { trigger_error($e->getMessage()); } $res['local'] = 0; if (!empty($res['cmd'])) { preg_match("/\\.(\\w*)\$/", $res['cmd'], $ext_arr); $res['to_file'] = System::transliterate($item['id'] . '_' . Itv::getChannelNameById($item['ch_id']) . '_' . $item['program']); $res['to_file'] .= '.' . $ext_arr[1]; } if (!empty($_REQUEST['download'])) { $downloads = new Downloads(); $res['cmd'] = $downloads->createDownloadLink('pvr', $rec_id, Stb::getInstance()->id); } return $res; }
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 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 createTask($ch_id, $force_storage = '') { if (empty($this->storages)) { return false; } $storage_names = array_keys($this->storages); if (!empty($force_storage) && in_array($force_storage, $storage_names)) { $storage_name = $force_storage; } else { $storage_name = $storage_names[0]; } $exist_task = Mysql::getInstance()->from('tv_archive')->where(array('ch_id' => $ch_id, 'storage_name' => $storage_name))->get()->first(); if (!empty($exist_task)) { return true; } $task_id = Mysql::getInstance()->insert('tv_archive', array('ch_id' => $ch_id, 'storage_name' => $storage_name))->insert_id(); if (!$task_id) { return false; } if (!empty($force_storage) && array_key_exists($force_storage, $this->storages) && ($this->storages[$force_storage]['fake_tv_archive'] == 1 || $this->storages[$force_storage]['flussonic_dvr'] == 1 || $this->storages[$force_storage]['wowza_dvr'] == 1)) { return true; } $channel = Itv::getChannelById($ch_id); if ($channel['flussonic_dvr'] || $channel['wowza_dvr']) { return true; } if (preg_match("/(\\S+:\\/\\/\\S+)/", $channel['mc_cmd'], $match)) { $cmd = $match[1]; } else { $cmd = $channel['mc_cmd']; } $task = array('id' => $task_id, 'ch_id' => $channel['id'], 'cmd' => $cmd, 'parts_number' => $channel['tv_archive_duration']); return $this->clients[$storage_name]->resource('tv_archive_recorder')->create(array('task' => $task)); }
</td> <td> <textarea id="descr" name="descr" cols="39" rows="5"><?php echo @$descr; ?> </textarea> </td> </tr> <?php if (!empty($logo)) { ?> <tr> <td align="right"></td> <td valign="top" id="logo_block"> <img src="<?php echo Itv::getLogoUriById(intval($_GET['id'])) . '?' . time(); ?> " style="float: left;"/><a href="javascript://" onclick="delete_logo(<?php echo intval($_GET['id']); ?> ); return false;" style="float: left;">[x]</a> </td> </tr> <?php } ?> <tr> <td align="right"> <?php echo _('Logo'); ?>
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; }
private function get_tv_services() { return \Itv::getServices(); }
<?php include "./common.php"; $uid = Itv::checkTemporaryLink($_GET['token']); if (!$uid) { header($_SERVER["SERVER_PROTOCOL"] . " 403 Forbidden"); } else { header("X-AuthDuration: 36000"); header("X-Unique: true"); header("X-Max-Sessions: 1"); header("X-UserId: " . $uid); header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); }
public function getDataTable() { $page = intval($_REQUEST['p']); $ch_id = intval($_REQUEST['ch_id']); $from = $_REQUEST['from']; $to = $_REQUEST['to']; $default_page = false; $page_items = 10; $all_user_ids = Itv::getInstance()->getAllUserChannelsIds(); $dvb_channels = Itv::getInstance()->getDvbChannels(); if (!empty($_REQUEST['fav'])) { $fav = Itv::getInstance()->getFav(Stb::getInstance()->id); $all_user_ids = array_intersect($all_user_ids, $fav); $fav_assoc = array_fill_keys($fav, 1); $dvb_channels = array_values(array_filter($dvb_channels, function ($channel) use($fav_assoc) { return isset($fav_assoc[$channel['id']]); })); } $dvb_ch_idx = null; $channel = Itv::getChannelById($ch_id); if (empty($channel)) { foreach ($dvb_channels as $dvb_channel) { if ($dvb_channel['id'] == $ch_id) { $channel = $dvb_channel; break; } } for ($i = 0; $i < count($dvb_channels); $i++) { if ($dvb_channels[$i]['id'] == $ch_id) { $channel = $dvb_channels[$i]; $dvb_ch_idx = $i; } } if ($dvb_ch_idx != null) { $dvb_ch_idx++; } } $total_channels = Itv::getInstance()->getChannels()->orderby('number')->in('id', $all_user_ids)->get()->count(); $total_iptv_channels = $total_channels; $total_channels += count($dvb_channels); $ch_idx = Itv::getInstance()->getChannels()->orderby(isset($fav) ? 'field(id,' . (empty($fav) ? 'null' : implode(',', $fav)) . ')' : 'number')->in('id', $all_user_ids)->where(array('number<=' => $channel['number']))->get()->count(); $ch_idx += $dvb_ch_idx; if ($ch_idx === false) { $ch_idx = 0; } if ($page == 0) { $default_page = true; $page = ceil($ch_idx / $page_items); } $ch_idx = $ch_idx - ($page - 1) * $page_items; $user_channels = Itv::getInstance()->getChannels()->orderby(isset($fav) ? 'field(id,' . (empty($fav) ? 'null' : implode(',', $fav)) . ')' : 'number')->in('id', $all_user_ids)->limit($page_items, ($page - 1) * $page_items)->get()->all(); $total_iptv_pages = ceil($total_iptv_channels / $page_items); if (count($user_channels) < $page_items) { if ($page == $total_iptv_pages) { $dvb_part_length = $page_items - $total_iptv_channels % $page_items; } else { $dvb_part_length = $page_items; } if ($page > $total_iptv_pages) { $dvb_part_offset = ($page - $total_iptv_pages - 1) * $page_items + ($page_items - $total_iptv_channels % $page_items); } else { $dvb_part_offset = 0; } if (isset($_REQUEST['p'])) { $dvb_channels = array_splice($dvb_channels, $dvb_part_offset, $dvb_part_length); } $user_channels = array_merge($user_channels, $dvb_channels); } $display_channels_ids = array(); for ($i = 0; $i < count($user_channels); $i++) { if (Config::getSafe('enable_numbering_in_order', false)) { $user_channels[$i]['number'] = (string) ($i + 1 + ($page - 1) * 10); } $display_channels_ids[] = $user_channels[$i]['id']; } $raw_epg = $this->getEpgForChannelsOnPeriod($display_channels_ids, $from, $to); $result = array(); $num = 1; foreach ($raw_epg as $id => $epg) { $channel = $user_channels[array_search($id, $display_channels_ids)]; $result[] = array('ch_id' => $id, 'name' => $channel['name'], 'number' => !empty($_REQUEST['fav']) ? (string) $num : $channel['number'], 'ch_type' => isset($channel['type']) && $channel['type'] == 'dvb' ? 'dvb' : 'iptv', 'dvb_id' => isset($channel['type']) && $channel['type'] == 'dvb' ? $channel['dvb_id'] : null, 'epg_container' => 1, 'epg' => $epg); $num++; } $time_marks = array(); $from_ts = strtotime($from); $to_ts = strtotime($to); /// Time format. See: http://ua2.php.net/manual/en/function.date.php $time_marks[] = date(_("H:i"), $from_ts); $time_marks[] = date(_("H:i"), $from_ts + 1800); $time_marks[] = date(_("H:i"), $from_ts + 2 * 1800); $time_marks[] = date(_("H:i"), $from_ts + 3 * 1800); if (!$default_page) { //$ch_idx = 0; //$page = 0; } if (!in_array($ch_id, $display_channels_ids)) { $ch_idx = 0; $page = 0; } else { $ch_idx = array_search($ch_id, $display_channels_ids) + 1; } //var_dump($display_channels_ids, $ch_id, $ch_idx); return array('total_items' => $total_channels, 'max_page_items' => $page_items, 'cur_page' => $page, 'selected_item' => $ch_idx, 'time_marks' => $time_marks, 'from_ts' => $from_ts, 'to_ts' => $to_ts, 'data' => $result); }
$response['result'] = vclubinfo::getRatingByName($_GET['oname']); } else { if ($_GET['get'] == 'kinopoisk_info_by_id') { $response['result'] = vclubinfo::getInfoById($_GET['kinopoisk_id']); } } } } catch (KinopoiskException $e) { echo $e->getMessage(); $logger = new Logger(); $logger->setPrefix("vclubinfo_"); // format: [date] - error_message - [base64 encoded response]; $logger->error(sprintf("[%s] - %s - \"%s\"\n", date("r"), $e->getMessage(), base64_encode($e->getResponse()))); } } elseif ($_GET['get'] == 'tv_services') { $response['result'] = Itv::getServices(); } elseif ($_GET['get'] == 'video_services') { $response['result'] = Video::getServices(); } elseif ($_GET['get'] == 'radio_services') { $response['result'] = Radio::getServices(); } elseif ($_GET['get'] == 'module_services') { $response['result'] = Module::getServices(); } elseif ($_GET['get'] == 'option_services') { $option_services = Config::getSafe('option_services', array()); $response['result'] = array_map(function ($item) { return array('id' => $item, 'name' => $item); }, $option_services); } $output = ob_get_contents(); ob_end_clean(); if ($output) {
<?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;
public function __construct() { $this->manager = Itv::getInstance(); }
public function filter($channels) { $genres = new \TvGenre(); $all_genres = $genres->getAll(true, true); $all_genres_map = array(); foreach ($all_genres as $genre) { $all_genres_map[$genre['_id']] = $genre; } $fav_channels = $this->fav_channels; $fields_map = $this->fields_map; $user_channels = $this->user_channels; $channels = array_map(function ($channel) use($fav_channels, $fields_map, $user_channels, $all_genres_map) { $new_channel = array_intersect_key($channel, $fields_map); $new_channel['id'] = (int) $channel['id']; $new_channel['number'] = (int) $channel['number']; $new_channel['genre_id'] = isset($all_genres_map[$channel['tv_genre_id']]) ? $all_genres_map[$channel['tv_genre_id']]['id'] : ''; $new_channel['favorite'] = in_array($channel['id'], $fav_channels) ? 1 : 0; $new_channel['archive'] = (int) $channel['enable_tv_archive']; $new_channel['censored'] = (int) $channel['censored']; $new_channel['archive_range'] = (int) $channel['tv_archive_duration']; $new_channel['pvr'] = (int) $channel['allow_pvr']; if ($channel['enable_monitoring']) { $new_channel['monitoring_status'] = (int) $channel['monitoring_status']; } else { $new_channel['monitoring_status'] = 1; } if (!empty($_SERVER['HTTP_UA_RESOLUTION']) && in_array($_SERVER['HTTP_UA_RESOLUTION'], array(120, 160, 240, 320))) { $resolution = (int) $_SERVER['HTTP_UA_RESOLUTION']; } else { $resolution = 320; } $new_channel['logo'] = \Itv::getLogoUriById($channel['id'], $resolution); $urls = \Itv::getUrlsForChannel($channel['id']); if (!empty($urls) && $urls[0]['use_http_tmp_link'] == 0 && $urls[0]['use_load_balancing'] == 0) { $new_channel['url'] = $urls[0]['url']; } else { $new_channel['url'] = ""; } if (preg_match("/(\\S+:\\/\\/\\S+)/", $new_channel['url'], $match)) { $new_channel['url'] = $match[1]; } return $new_channel; }, $channels); return $channels; }
/** * @deprecated * @param $user_rec_id * @return bool */ public function stopAndUsrMsg($user_rec_id) { $stopped = $this->stop($user_rec_id); if ($stopped) { $user_record = Mysql::getInstance()->from('users_rec')->where(array('id' => $user_rec_id))->get()->first(); $channel = Itv::getChannelById($user_record['ch_id']); $event = new SysEvent(); $event->setUserListById($user_record['uid']); $user = User::getInstance((int) $user_record['uid']); $event->sendMsg($user->getLocalizedText('Stopped recording') . ' — ' . $user_record['program'] . ' ' . $user->getLocalizedText('on channel') . ' ' . $channel['name']); } return $stopped; }
function get_data() { $get = @$_GET['get']; $data = @$_POST['data']; $arr = array(); if ($data) { switch ($get) { case 'del_tv_logo': if (!Admin::isEditAllowed('add_itv')) { header($_SERVER["SERVER_PROTOCOL"] . ' 405 Method Not Allowed'); echo _('Action "edit" denied for page "add_itv"'); exit; } return Itv::delLogoById(intval($_GET['id'])); case 'vclub_info': $media_id = intval($data); $video = Video::getById($media_id); $path = $video['path']; $rtsp_url = $video['rtsp_url']; if (!empty($rtsp_url)) { $result['data'] = array(); return $result; } $master = new VideoMaster(); $good_storages = $master->getAllGoodStoragesForMediaFromNet($media_id, true); foreach ($good_storages as $name => $data) { $arr[] = array('storage_name' => $name, 'path' => $path, 'series' => count($data['series']), 'files' => $data['files'], 'for_moderator' => $data['for_moderator']); } $result['data'] = $arr; return $result; break; case 'startmd5sum': $resp = array(); if (Admin::isPageActionAllowed('add_video')) { $master = new VideoMaster(); try { $master->startMD5Sum($data['storage_name'], $data['media_name']); } catch (Exception $exception) { $resp['error'] = $exception->getMessage(); } return $resp; } else { $resp['error'] = 'У Вас нет прав на это действие'; return $resp; } break; case 'karaoke_info': $media_id = intval($data); $master = new KaraokeMaster(); $good_storages = $master->getAllGoodStoragesForMediaFromNet($media_id, true); if (count($good_storages) > 0) { set_karaoke_status($media_id, 1); } else { set_karaoke_status($media_id, 0); } foreach ($good_storages as $name => $data) { $arr[] = array('storage_name' => $name, 'file' => $media_id . '.mpg'); } $result['data'] = $arr; return $result; break; case 'chk_name': return $result['data'] = Mysql::getInstance()->count()->from('video')->where(array('name' => $data))->get()->counter(); break; case 'org_name_chk': return $result['data'] = Mysql::getInstance()->count()->from('permitted_video')->where(array('o_name' => $data['o_name'], 'year' => $data['year']))->get()->counter(); break; case 'get_cat_genres': $category_alias = Mysql::getInstance()->from('media_category')->where(array('id' => $data))->get()->first('category_alias'); $genres = Mysql::getInstance()->from('cat_genre')->where(array('category_alias' => $category_alias))->orderby('title')->get()->all(); $genres = array_map(function ($genre) { return array('id' => $genre['id'], 'title' => _($genre['title'])); }, $genres); return array('data' => $genres); break; } } }
/** * 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(); } }
public function __construct() { $this->manager = Itv::getInstance(); $this->allowed_fields = array_fill_keys(array('id', 'name', 'number', 'base_ch', 'hd', 'url', 'enable_monitoring'), true); }
public function getLinksForMonitoring($status = FALSE) { $result = Mysql::getInstance()->select('ch_links.*, itv.name as ch_name')->from('ch_links')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.enable_monitoring' => 1, 'ch_links.enable_balancer_monitoring' => 0)); if ($status) { $result->where(array('ch_links.status' => (int) ($status == 'up'))); } $monitoring_links = $result->orderby('ch_id')->get()->all(); $result = Mysql::getInstance()->select('ch_links.*, streamer_id, ch_link_on_streamer.id as streamer_link_id, itv.name as ch_name')->from('ch_links')->join('ch_link_on_streamer', 'link_id', 'ch_links.id', 'INNER')->join('itv', 'itv.id', 'ch_links.ch_id', 'INNER')->where(array('ch_links.enable_monitoring' => 1, 'ch_links.enable_balancer_monitoring' => 1, 'ch_links.use_load_balancing' => 1)); if ($status) { $result->where(array('ch_links.status' => (int) ($status == 'up'))); } $balanser_monitoring_links_raw = $result->orderby('ch_id')->get()->all(); $servers_map = StreamServer::getIdMap(); $balanser_monitoring_links = array(); foreach ($balanser_monitoring_links_raw as $link) { if (empty($servers_map[$link['streamer_id']])) { continue; } if ($link['use_http_tmp_link'] == 1 && $link['wowza_tmp_link'] == 0) { $colon_pos = strpos($servers_map[$link['streamer_id']]['address'], ":"); if ($colon_pos === false) { $address = $servers_map[$link['streamer_id']]['address']; } else { $address = substr($servers_map[$link['streamer_id']]['address'], 0, $colon_pos); } $link['url'] = preg_replace('/:\\/\\/([^\\/:]*)/', '://' . $address, $link['url']); $link['monitoring_url'] = preg_replace('/:\\/\\/([^\\/:]*)/', '://' . $address, $link['monitoring_url']); } else { $link['url'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $servers_map[$link['streamer_id']]['address'], $link['url']); $link['monitoring_url'] = preg_replace('/:\\/\\/([^\\/]*)/', '://' . $servers_map[$link['streamer_id']]['address'], $link['monitoring_url']); } $link['id'] = 's' . $link['streamer_link_id']; $balanser_monitoring_links[] = $link; } $monitoring_links = array_merge($monitoring_links, $balanser_monitoring_links); $monitoring_links = array_map(function ($cmd) { $cmd['monitoring_url'] = trim($cmd['monitoring_url']); if (!empty($cmd['monitoring_url']) && preg_match("/(\\S+:\\/\\/\\S+)/", $cmd['monitoring_url'], $match)) { $cmd['url'] = $match[1]; } else { if (preg_match("/(\\S+:\\/\\/\\S+)/", $cmd['url'], $match)) { $cmd['url'] = $match[1]; } } if ($cmd['flussonic_tmp_link']) { $cmd['type'] = 'flussonic_health'; } elseif ($cmd['nginx_secure_link']) { try { $cmd['type'] = 'nginx_secure_link'; $cmd['url'] = Itv::getNginxSecureLink($cmd['url']); } catch (ItvLinkException $e) { return false; } } else { $cmd['type'] = 'stream'; } return $cmd; }, $monitoring_links); return array_values(array_filter($monitoring_links)); }
<?php include "./common.php"; $result = Itv::checkTemporaryLink($_GET['key']); if (!$result) { $result = '/404/'; } header("X-Accel-Redirect: " . $result);