Пример #1
0
 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;
 }
Пример #2
0
 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;
 }