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 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 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)); }
Mysql::getInstance()->update('itv', array('logo' => $logo), array('id' => $ch_id)); } else { $error = _('Error: could not save logo') . ' <a href="#form">#</a>'; } } header("Location: add_itv.php"); exit; } else { $error = _('Error: all fields are required') . ' <a href="#form">#</a>'; } } if (@$_GET['update'] && !$error && !empty($_POST)) { Admin::checkAccess(AdminAccess::ACCESS_EDIT); if (@$_GET['name'] && @$_POST['tv_genre_id'] > 0) { $ch_id = intval(@$_GET['id']); $channel = Itv::getChannelById($ch_id); if (!empty($channel) && ($channel['enable_tv_archive'] != $enable_tv_archive || $channel['wowza_dvr'] != $wowza_dvr || $channel['flussonic_dvr'] != $flussonic_dvr || $channel['tv_archive_duration'] != $_POST['tv_archive_duration'])) { if ($channel['enable_tv_archive']) { if ($channel['flussonic_dvr']) { $archive = new FlussonicTvArchive(); } elseif ($channel['wowza_dvr']) { $archive = new WowzaTvArchive(); } else { $archive = new TvArchive(); } $archive->deleteTasks($ch_id); } } Mysql::getInstance()->update('itv', array('name' => $_POST['name'], 'cmd' => !empty($_POST['cmd'][0]) ? $_POST['cmd'][0] : "", 'cmd_1' => @$_POST['cmd_1'], 'cmd_2' => @$_POST['cmd_2'], 'cmd_3' => @$_POST['cmd_3'], 'mc_cmd' => $mc_cmd, 'enable_wowza_load_balancing' => $enable_wowza_load_balancing, 'enable_tv_archive' => $enable_tv_archive, 'allow_pvr' => $allow_pvr, 'allow_local_pvr' => $allow_local_pvr, 'allow_local_timeshift' => $allow_local_timeshift, 'enable_monitoring' => $enable_monitoring, 'wowza_tmp_link' => $wowza_tmp_link, 'nginx_secure_link' => $nginx_secure_link, 'wowza_dvr' => $wowza_dvr, 'flussonic_dvr' => $flussonic_dvr, 'use_http_tmp_link' => $use_http_tmp_link, 'censored' => $censored, 'base_ch' => $base_ch, 'bonus_ch' => $bonus_ch, 'hd' => $hd, 'cost' => $_POST['cost'], 'number' => $_POST['number'], 'descr' => $_POST['descr'], 'tv_genre_id' => $_POST['tv_genre_id'], 'xmltv_id' => $_POST['xmltv_id'], 'service_id' => trim($_POST['service_id']), 'volume_correction' => intval($_POST['volume_correction']), 'correct_time' => intval($_POST['correct_time']), 'modified' => 'NOW()', 'tv_archive_duration' => $_POST['tv_archive_duration']), array('id' => intval(@$_GET['id']))); Itv::invalidateCacheForChannel(intval(@$_GET['id'])); if (!$enable_monitoring) {
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); }
/** * @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; }