1
|
1 #!/usr/bin/php
|
|
2 <?php
|
|
3 include_once('config.php');
|
|
4 include_once( INSTALL_PATH . '/DBRecord.class.php' );
|
|
5 include_once( INSTALL_PATH . '/Reservation.class.php' );
|
|
6 include_once( INSTALL_PATH . '/Keyword.class.php' );
|
|
7
|
|
8 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA );
|
|
9 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML );
|
|
10
|
|
11 // BSを処理する
|
|
12 if( BS_TUNERS ) {
|
|
13 // 録画重複チェック
|
|
14 $num = DBRecord::countRecords( TBL_PREFIX . RESERVE_TBL, "WHERE complete = '0' AND type = 'BS' AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
|
|
15 if( $num == 0 ) {
|
|
16 $cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".TEMP_DATA." ".DO_RECORD . " >/dev/null 2>&1";
|
|
17 exec( $cmdline );
|
|
18 $cmdline = EPGDUMP." /BS ".TEMP_DATA." ".TEMP_XML;
|
|
19 exec( $cmdline );
|
|
20 storeProgram( "BS", TEMP_XML );
|
|
21 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA );
|
|
22 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML );
|
|
23 }
|
|
24 }
|
|
25
|
|
26 // 地上波を処理する
|
|
27 if( GR_TUNERS ) {
|
|
28 foreach( $GR_CHANNEL_MAP as $key=>$value ){
|
|
29 // 録画重複チェック
|
|
30 $num = DBRecord::countRecords( TBL_PREFIX . RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" );
|
|
31 if( $num == 0 ) {
|
|
32 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".TEMP_DATA." ".DO_RECORD . " >/dev/null 2>&1";
|
|
33 exec( $cmdline );
|
|
34 $cmdline = EPGDUMP." ".$key." ".TEMP_DATA." ".TEMP_XML;
|
|
35 exec( $cmdline );
|
|
36 storeProgram( "GR", TEMP_XML );
|
|
37 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA );
|
|
38 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML );
|
|
39 }
|
|
40 }
|
|
41 }
|
|
42
|
|
43 // 不要なプログラムの削除
|
|
44 // 8日以上前のプログラムを消す
|
|
45 $arr = array();
|
|
46 $arr = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" );
|
|
47 foreach( $arr as $val ) $val->delete();
|
|
48
|
|
49 // 8日以上先のデータがあれば消す
|
|
50 $arr = array();
|
|
51 $arr = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" );
|
|
52 foreach( $arr as $val ) $val->delete();
|
|
53
|
|
54 // キーワード自動録画予約
|
|
55 $arr = array();
|
|
56 $arr = Keyword::createKeywords();
|
|
57 foreach( $arr as $val ) {
|
|
58 try {
|
|
59 $val->reservation();
|
|
60 }
|
|
61 catch( Exception $e ) {
|
|
62 // 無視
|
|
63 }
|
|
64 }
|
|
65
|
|
66 exit();
|
|
67
|
|
68 function storeProgram( $type, $xmlfile ) {
|
|
69 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP;
|
|
70 // チャンネルマップファイルの準備
|
|
71 $map = array();
|
|
72 if( $type == "BS" ) $map = $BS_CHANNEL_MAP;
|
|
73 else if( $type == "GR") $map = $GR_CHANNEL_MAP;
|
|
74
|
|
75 // XML parse
|
|
76 $xml = @simplexml_load_file( $xmlfile );
|
|
77 if( $xml === false ) {
|
|
78 return; // XMLが読み取れないなら何もしない
|
|
79 }
|
|
80 // channel抽出
|
|
81 foreach( $xml->channel as $ch ) {
|
|
82 $disc = $ch['id'];
|
|
83 try {
|
|
84 // チャンネルデータを探す
|
|
85 $num = DBRecord::countRecords( TBL_PREFIX . CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" );
|
|
86 if( $num == 0 ) {
|
|
87 // チャンネルデータがないなら新規作成
|
|
88 $rec = new DBRecord( TBL_PREFIX . CHANNEL_TBL );
|
|
89 $rec->type = $type;
|
|
90 $rec->channel = $map["$disc"];
|
|
91 $rec->channel_disc = $disc;
|
|
92 $rec->name = $ch->{'display-name'};
|
|
93 }
|
7
|
94 else {
|
|
95 // 存在した場合も、とりあえずチャンネル名は更新する
|
|
96 $rec = new DBRecord(TBL_PREFIX.CHANNEL_TBL, "channel_disc", $disc );
|
|
97 $rec->name = $ch->{'display-name'};
|
|
98 }
|
1
|
99 }
|
|
100 catch( Exception $e ) {
|
7
|
101 // 無視
|
1
|
102 }
|
|
103 }
|
|
104 // channel 終了
|
|
105
|
|
106 // programme 取得
|
|
107
|
|
108 foreach( $xml->programme as $program ) {
|
|
109 $channel_disc = $program['channel'];
|
|
110 $channel = $map["$channel_disc"];
|
|
111 $starttime = ereg_replace(" \+0900", '', $program['start'] );
|
|
112 $endtime = ereg_replace( " \+0900", '', $program['stop'] );
|
|
113 $title = $program->title;
|
|
114 $desc = $program->desc;
|
|
115 $cat_ja = "";
|
|
116 $cat_en = "";
|
|
117 foreach( $program->category as $cat ) {
|
|
118 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat;
|
|
119 if( $cat['lang'] == "en" ) $cat_en = $cat;
|
|
120 }
|
|
121 $program_disc = md5( $channel_disc . $starttime . $endtime );
|
|
122 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
|
|
123 try {
|
|
124 // カテゴリを処理する
|
|
125 $category_disc = md5( $cat_ja . $cat_en );
|
|
126 $num = DBRecord::countRecords( TBL_PREFIX . CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
|
|
127 $cat_rec = null;
|
|
128 if( $num == 0 ) {
|
|
129 // 新規カテゴリの追加
|
|
130 $cat_rec = new DBRecord( TBL_PREFIX . CATEGORY_TBL );
|
|
131 $cat_rec->name_jp = $cat_ja;
|
|
132 $cat_rec->name_en = $cat_en;
|
|
133 $cat_rec->category_disc = $category_disc;
|
|
134 }
|
|
135 else
|
|
136 $cat_rec = new DBRecord( TBL_PREFIX . CATEGORY_TBL, "category_disc" , $category_disc );
|
|
137 //
|
|
138 $channel_rec = new DBRecord( TBL_PREFIX . CHANNEL_TBL, "channel_disc", $channel_disc );
|
|
139 $num = DBRecord::countRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
|
|
140 if( $num == 0 ) {
|
|
141 // 新規番組
|
|
142 // 重複チェック 同時間帯にある番組
|
|
143 $options = "WHERE channel_disc = '".$channel_disc."' ".
|
|
144 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
|
|
145 $battings = DBRecord::countRecords( TBL_PREFIX.PROGRAM_TBL, $options );
|
|
146 if( $battings > 0 ) {
|
|
147 // 重複発生=おそらく放映時間の変更
|
|
148 $records = DBRecord::createRecords( TBL_PREFIX.PROGRAM_TBL, $options );
|
|
149 foreach( $records as $rec ) {
|
|
150 // 自動録画予約された番組は放映時間変更と同時にいったん削除する
|
|
151 try {
|
|
152 $reserve = new DBRecord(TBL_PREFIX.RESERVE_TBL, "program_id", $rec->id );
|
|
153 if( $reserve->autorec ) {
|
|
154 Reservation::cancel( $reserve->id );
|
|
155 }
|
|
156 }
|
|
157 catch( Exception $e ) {
|
|
158 //無視
|
|
159 }
|
|
160 // 番組削除
|
|
161 $rec->delete();
|
|
162 }
|
|
163 }
|
|
164 // //
|
|
165 $rec = new DBRecord( TBL_PREFIX.PROGRAM_TBL );
|
|
166 $rec->channel_disc = $channel_disc;
|
|
167 $rec->channel_id = $channel_rec->id;
|
|
168 $rec->type = $type;
|
|
169 $rec->channel = $channel_rec->channel;
|
|
170 $rec->title = $title;
|
|
171 $rec->description = $desc;
|
|
172 $rec->category_id = $cat_rec->id;
|
|
173 $rec->starttime = $starttime;
|
|
174 $rec->endtime = $endtime;
|
|
175 $rec->program_disc = $program_disc;
|
|
176 }
|
|
177 else {
|
|
178 // 番組内容更新
|
|
179 $rec = new DBRecord( TBL_PREFIX . PROGRAM_TBL, "program_disc", $program_disc );
|
|
180 $rec->title = $title;
|
|
181 $rec->description = $desc;
|
|
182 $rec->category_id = $cat_rec->id;
|
|
183 }
|
|
184 }
|
|
185 catch(Exception $e) {
|
|
186 exit( $e->getMessage() );
|
|
187 }
|
|
188 }
|
|
189 }
|
|
190 ?>
|