comparison getepg.old.php @ 84:3ec5ca5e56ca

add: EPG取得並列化版を暫定的に標準に
author yoneda <yoneda@recorder.localnet.mda.or.jp>
date Mon, 01 Mar 2010 12:16:32 +0900
parents
children 80cc05b420af
comparison
equal deleted inserted replaced
83:f873e3251487 84:3ec5ca5e56ca
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 include_once( INSTALL_PATH . '/Settings.class.php' );
8
9 $settings = Settings::factory();
10
11 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
12 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
13
14 // BS
15 if( $settings->bs_tuners != 0 ) {
16 // 牙脂茲с
17 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
18 if( $num == 0 ) {
19 $cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
20 exec( $cmdline );
21 $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$settings->temp_xml;
22 exec( $cmdline );
23 storeProgram( "BS", $settings->temp_xml );
24 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
25 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
26 }
27
28 // CS
29 if ($settings->cs_rec_flg != 0) {
30 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
31 if( $num == 0 ) {
32 $cmdline = "CHANNEL=CS8 DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
33 exec( $cmdline );
34 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$settings->temp_xml;
35 exec( $cmdline );
36 storeProgram( "CS", $settings->temp_xml );
37 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
38 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
39 }
40 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
41 if( $num == 0 ) {
42 $cmdline = "CHANNEL=CS24 DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
43 exec( $cmdline );
44 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$settings->temp_xml;
45 exec( $cmdline );
46 storeProgram( "CS", $settings->temp_xml );
47 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
48 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
49 }
50 }
51 }
52
53 // 遺羈≪
54 if( $settings->gr_tuners != 0 ) {
55 foreach( $GR_CHANNEL_MAP as $key=>$value ){
56 // 牙脂茲с
57 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" );
58 if( $num == 0 ) {
59 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
60 exec( $cmdline );
61 $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$settings->temp_xml;
62 exec( $cmdline );
63 storeProgram( "GR", $settings->temp_xml );
64 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
65 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
66 }
67 }
68 }
69
70 // 筝荀違
71 // 8ヤ札筝違羔
72 $arr = array();
73 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" );
74 foreach( $arr as $val ) $val->delete();
75
76 // 8ヤ札筝若帥井
77 $arr = array();
78 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" );
79 foreach( $arr as $val ) $val->delete();
80
81 // 若若牙私膣
82 $arr = array();
83 $arr = Keyword::createKeywords();
84 foreach( $arr as $val ) {
85 try {
86 $val->reservation();
87 }
88 catch( Exception $e ) {
89 // ∴
90 }
91 }
92
93 exit();
94
95 function storeProgram( $type, $xmlfile ) {
96 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP;
97 // c潟<ゃ羣
98 $map = array();
99 if( $type == "BS" ) $map = $BS_CHANNEL_MAP;
100 else if( $type == "GR") $map = $GR_CHANNEL_MAP;
101 else if( $type == "CS") $map = $CS_CHANNEL_MAP;
102
103 // XML parse
104 $xml = @simplexml_load_file( $xmlfile );
105 if( $xml === false ) {
106 return; // XML茯水篏
107 }
108 // channel遵
109 foreach( $xml->channel as $ch ) {
110 $disc = $ch['id'];
111 try {
112 // c潟若帥「
113 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" );
114 if( $num == 0 ) {
115 // c潟若帥域鋎
116 $rec = new DBRecord( CHANNEL_TBL );
117 $rec->type = $type;
118 $rec->channel = $map["$disc"];
119 $rec->channel_disc = $disc;
120 $rec->name = $ch->{'display-name'};
121 }
122 else {
123 // 絖翫c潟贋違
124 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc );
125 $rec->name = $ch->{'display-name'};
126 }
127 }
128 catch( Exception $e ) {
129 // ∴
130 }
131 }
132 // channel 腟篋
133
134 // programme 緇
135
136 foreach( $xml->programme as $program ) {
137 $channel_disc = $program['channel'];
138 $channel = $map["$channel_disc"];
139 $starttime = str_replace(" +0900", '', $program['start'] );
140 $endtime = str_replace( " +0900", '', $program['stop'] );
141 $title = $program->title;
142 $desc = $program->desc;
143 $cat_ja = "";
144 $cat_en = "";
145 foreach( $program->category as $cat ) {
146 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat;
147 if( $cat['lang'] == "en" ) $cat_en = $cat;
148 }
149 $program_disc = md5( $channel_disc . $starttime . $endtime );
150 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
151 try {
152 // 眼
153 $category_disc = md5( $cat_ja . $cat_en );
154 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
155 $cat_rec = null;
156 if( $num == 0 ) {
157 // 域眼菴遵
158 $cat_rec = new DBRecord( CATEGORY_TBL );
159 $cat_rec->name_jp = $cat_ja;
160 $cat_rec->name_en = $cat_en;
161 $cat_rec->category_disc = $category_disc;
162 }
163 else
164 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
165 //
166 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc );
167 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
168 if( $num == 0 ) {
169 // 域腟
170 // 茲с 絽腟
171 $options = "WHERE channel_disc = '".$channel_disc."' ".
172 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
173 $battings = DBRecord::countRecords(PROGRAM_TBL, $options );
174 if( $battings > 0 ) {
175 // 茲榊鐚丈紊
176 $records = DBRecord::createRecords(PROGRAM_TBL, $options );
177 foreach( $records as $rec ) {
178 // 牙私膣腟丈紊眼cゃ
179 try {
180 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
181 if( $reserve->autorec ) {
182 Reservation::cancel( $reserve->id );
183 }
184 }
185 catch( Exception $e ) {
186 //∴
187 }
188 // 腟
189 $rec->delete();
190 }
191 }
192 // //
193 $rec = new DBRecord( PROGRAM_TBL );
194 $rec->channel_disc = $channel_disc;
195 $rec->channel_id = $channel_rec->id;
196 $rec->type = $type;
197 $rec->channel = $channel_rec->channel;
198 $rec->title = $title;
199 $rec->description = $desc;
200 $rec->category_id = $cat_rec->id;
201 $rec->starttime = $starttime;
202 $rec->endtime = $endtime;
203 $rec->program_disc = $program_disc;
204 }
205 else {
206 // 腟絎号贋
207 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
208 $rec->title = $title;
209 $rec->description = $desc;
210 $rec->category_id = $cat_rec->id;
211 }
212 }
213 catch(Exception $e) {
214 exit( $e->getMessage() );
215 }
216 }
217 }
218 ?>