comparison getepg.old.php @ 137:a18df712fc7e

merged with upstream
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sun, 21 Mar 2010 03:15:00 +0900
parents 2646140c5ba7
children 43f74519bd52
comparison
equal deleted inserted replaced
119:b172a0b1ea48 137:a18df712fc7e
5 include_once( $script_path . '/config.php'); 5 include_once( $script_path . '/config.php');
6 include_once( INSTALL_PATH . '/DBRecord.class.php' ); 6 include_once( INSTALL_PATH . '/DBRecord.class.php' );
7 include_once( INSTALL_PATH . '/Reservation.class.php' ); 7 include_once( INSTALL_PATH . '/Reservation.class.php' );
8 include_once( INSTALL_PATH . '/Keyword.class.php' ); 8 include_once( INSTALL_PATH . '/Keyword.class.php' );
9 include_once( INSTALL_PATH . '/Settings.class.php' ); 9 include_once( INSTALL_PATH . '/Settings.class.php' );
10 include_once( INSTALL_PATH . '/storeProgram.inc.php' );
11
10 12
11 $settings = Settings::factory(); 13 $settings = Settings::factory();
12 14
13 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 15 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
14 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); 16 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
67 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); 69 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
68 } 70 }
69 } 71 }
70 } 72 }
71 73
72 // 不要なプログラムの削除 74 garbageClean(); // 不要プログラム削除
73 // 8日以上前のプログラムを消す 75 doKeywordReservation(); // キーワード予約
74 $arr = array();
75 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" );
76 foreach( $arr as $val ) $val->delete();
77
78 // 8日以上先のデータがあれば消す
79 $arr = array();
80 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" );
81 foreach( $arr as $val ) $val->delete();
82
83 // キーワード自動録画予約
84 $arr = array();
85 $arr = Keyword::createKeywords();
86 foreach( $arr as $val ) {
87 try {
88 $val->reservation();
89 }
90 catch( Exception $e ) {
91 // 無視
92 }
93 }
94
95 exit(); 76 exit();
96
97 function storeProgram( $type, $xmlfile ) {
98 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP;
99 // チャンネルマップファイルの準備
100 $map = array();
101 if( $type == "BS" ) $map = $BS_CHANNEL_MAP;
102 else if( $type == "GR") $map = $GR_CHANNEL_MAP;
103 else if( $type == "CS") $map = $CS_CHANNEL_MAP;
104
105 // XML parse
106 $xml = @simplexml_load_file( $xmlfile );
107 if( $xml === false ) {
108 return; // XMLが読み取れないなら何もしない
109 }
110 // channel抽出
111 foreach( $xml->channel as $ch ) {
112 $disc = $ch['id'];
113 try {
114 // チャンネルデータを探す
115 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" );
116 if( $num == 0 ) {
117 // channel discがないようなら飛ばす
118 if( array_key_exists( "$disc", $map ) ) {
119 // チャンネルデータがないなら新規作成
120 $rec = new DBRecord( CHANNEL_TBL );
121 $rec->type = $type;
122 $rec->channel = $map["$disc"];
123 $rec->channel_disc = $disc;
124 $rec->name = $ch->{'display-name'};
125 }
126 }
127 else {
128 // 存在した場合も、とりあえずチャンネル名は更新する
129 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc );
130 $rec->name = $ch->{'display-name'};
131 }
132 }
133 catch( Exception $e ) {
134 // 無視
135 }
136 }
137 // channel 終了
138
139 // programme 取得
140
141 foreach( $xml->programme as $program ) {
142 $channel_disc = $program['channel'];
143 if( ! array_key_exists( "$channel_disc", $map ) ) continue;
144
145 $channel = $map["$channel_disc"];
146 $starttime = str_replace(" +0900", '', $program['start'] );
147 $endtime = str_replace( " +0900", '', $program['stop'] );
148 $title = $program->title;
149 $desc = $program->desc;
150 $cat_ja = "";
151 $cat_en = "";
152 foreach( $program->category as $cat ) {
153 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat;
154 if( $cat['lang'] == "en" ) $cat_en = $cat;
155 }
156 $program_disc = md5( $channel_disc . $starttime . $endtime );
157 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
158 try {
159 // カテゴリを処理する
160 $category_disc = md5( $cat_ja . $cat_en );
161 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
162 $cat_rec = null;
163 if( $num == 0 ) {
164 // 新規カテゴリの追加
165 $cat_rec = new DBRecord( CATEGORY_TBL );
166 $cat_rec->name_jp = $cat_ja;
167 $cat_rec->name_en = $cat_en;
168 $cat_rec->category_disc = $category_disc;
169 }
170 else
171 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
172 //
173 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc );
174 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
175 if( $num == 0 ) {
176 // 新規番組
177 // 重複チェック 同時間帯にある番組
178 $options = "WHERE channel_disc = '".$channel_disc."' ".
179 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
180 $battings = DBRecord::countRecords(PROGRAM_TBL, $options );
181 if( $battings > 0 ) {
182 // 重複発生=おそらく放映時間の変更
183 $records = DBRecord::createRecords(PROGRAM_TBL, $options );
184 foreach( $records as $rec ) {
185 // 自動録画予約された番組は放映時間変更と同時にいったん削除する
186 try {
187 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
188 if( $reserve->autorec ) {
189 Reservation::cancel( $reserve->id );
190 }
191 }
192 catch( Exception $e ) {
193 //無視
194 }
195 // 番組削除
196 $rec->delete();
197 }
198 }
199 // //
200 $rec = new DBRecord( PROGRAM_TBL );
201 $rec->channel_disc = $channel_disc;
202 $rec->channel_id = $channel_rec->id;
203 $rec->type = $type;
204 $rec->channel = $channel_rec->channel;
205 $rec->title = $title;
206 $rec->description = $desc;
207 $rec->category_id = $cat_rec->id;
208 $rec->starttime = $starttime;
209 $rec->endtime = $endtime;
210 $rec->program_disc = $program_disc;
211 }
212 else {
213 // 番組内容更新
214 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
215 $rec->title = $title;
216 $rec->description = $desc;
217 $rec->category_id = $cat_rec->id;
218 }
219 }
220 catch(Exception $e) {
221 exit( $e->getMessage() );
222 }
223 }
224 }
225 ?> 77 ?>