Mercurial > epgrec.yaz
comparison storeProgram.php @ 111:3bed74eca373
change: EPG取得並列化が可能かどうかを判定するように変更
author | epgrec@park.mda.or.jp <yoneda@recorder.localnet.mda.or.jp> |
---|---|
date | Sat, 13 Mar 2010 16:45:29 +0900 |
parents | d9b9d1d903a1 |
children | b3ba2658a228 |
comparison
equal
deleted
inserted
replaced
108:4bd07b03c694 | 111:3bed74eca373 |
---|---|
1 #!/usr/bin/php | 1 #!/usr/bin/php |
2 <?php | 2 <?php |
3 $script_path = dirname( __FILE__ ); | |
4 chdir( $script_path ); | |
5 include_once( $script_path . '/config.php'); | |
3 | 6 |
4 $type = $argv[1]; // BS CS GR | 7 $type = $argv[1]; // BS CS GR |
5 $file = $argv[2]; // XML<ゃ | 8 $file = $argv[2]; // XML<ゃ |
6 | |
7 | 9 |
8 // SIGTERM激違 | 10 // SIGTERM激違 |
9 function handler( $signo = 0 ) { | 11 function handler( $signo = 0 ) { |
10 global $file; | 12 global $file; |
11 if( file_exists( $file ) ) { | 13 if( file_exists( $file ) ) { |
22 if( pcntl_fork() != 0 ) | 24 if( pcntl_fork() != 0 ) |
23 exit; | 25 exit; |
24 pcntl_signal(SIGTERM, "handler"); | 26 pcntl_signal(SIGTERM, "handler"); |
25 } | 27 } |
26 | 28 |
27 | |
28 // 若≪喝 | 29 // 若≪喝 |
29 daemon(); | 30 daemon(); |
30 // ゃd | 31 // ゃd |
31 pcntl_setpriority(20); | 32 pcntl_setpriority(20); |
32 | 33 |
33 include_once('config.php'); | |
34 include_once( INSTALL_PATH . '/DBRecord.class.php' ); | 34 include_once( INSTALL_PATH . '/DBRecord.class.php' ); |
35 include_once( INSTALL_PATH . '/Reservation.class.php' ); | 35 include_once( INSTALL_PATH . '/Reservation.class.php' ); |
36 include_once( INSTALL_PATH . '/Keyword.class.php' ); | 36 include_once( INSTALL_PATH . '/Keyword.class.php' ); |
37 include_once( INSTALL_PATH . '/Settings.class.php' ); | 37 include_once( INSTALL_PATH . '/Settings.class.php' ); |
38 include_once( INSTALL_PATH . '/storeProgram.inc.php' ); | |
38 | 39 |
39 $settings = Settings::factory(); | 40 $settings = Settings::factory(); |
40 | 41 |
41 if( file_exists( $file ) ) { | 42 if( file_exists( $file ) ) { |
42 storeProgram( $type, $file ); | 43 storeProgram( $type, $file ); |
43 @unlink( $file ); | 44 @unlink( $file ); |
44 } | 45 } |
45 | 46 garbageClean(); // 筝荀違 |
46 // 筝荀違 | 47 doKeywordReservation(); // 若若篋膣 |
47 // 8ヤ札筝違羔 | |
48 $arr = array(); | |
49 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); | |
50 foreach( $arr as $val ) $val->delete(); | |
51 | |
52 // 8ヤ札筝若帥井 | |
53 $arr = array(); | |
54 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); | |
55 foreach( $arr as $val ) $val->delete(); | |
56 | |
57 // 若若牙私膣 | |
58 $arr = array(); | |
59 $arr = Keyword::createKeywords(); | |
60 foreach( $arr as $val ) { | |
61 try { | |
62 $val->reservation(); | |
63 } | |
64 catch( Exception $e ) { | |
65 // ∴ | |
66 } | |
67 } | |
68 exit(); | |
69 | |
70 function storeProgram( $type, $xmlfile ) { | |
71 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; | |
72 // c潟<ゃ羣 | |
73 $map = array(); | |
74 if( $type == "BS" ) $map = $BS_CHANNEL_MAP; | |
75 else if( $type == "GR") $map = $GR_CHANNEL_MAP; | |
76 else if( $type == "CS") $map = $CS_CHANNEL_MAP; | |
77 | |
78 // XML parse | |
79 $xml = @simplexml_load_file( $xmlfile ); | |
80 if( $xml === false ) { | |
81 return; // XML茯水篏 | |
82 } | |
83 // channel遵 | |
84 foreach( $xml->channel as $ch ) { | |
85 $disc = $ch['id']; | |
86 try { | |
87 // c潟若帥「 | |
88 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" ); | |
89 if( $num == 0 ) { | |
90 if( array_key_exists( "$disc", $map ) ) { | |
91 // c潟若帥域鋎 | |
92 $rec = new DBRecord( CHANNEL_TBL ); | |
93 $rec->type = $type; | |
94 $rec->channel = $map["$disc"]; | |
95 $rec->channel_disc = $disc; | |
96 $rec->name = $ch->{'display-name'}; | |
97 } | |
98 } | |
99 else { | |
100 // 絖翫c潟贋違 | |
101 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc ); | |
102 $rec->name = $ch->{'display-name'}; | |
103 } | |
104 } | |
105 catch( Exception $e ) { | |
106 // ∴ | |
107 } | |
108 } | |
109 // channel 腟篋 | |
110 | |
111 // programme 緇 | |
112 | |
113 foreach( $xml->programme as $program ) { | |
114 $channel_disc = $program['channel']; | |
115 if( ! array_key_exists( "$channel_disc", $map ) ) continue; | |
116 | |
117 $channel = $map["$channel_disc"]; | |
118 $starttime = str_replace(" +0900", '', $program['start'] ); | |
119 $endtime = str_replace( " +0900", '', $program['stop'] ); | |
120 $title = $program->title; | |
121 $desc = $program->desc; | |
122 $cat_ja = ""; | |
123 $cat_en = ""; | |
124 foreach( $program->category as $cat ) { | |
125 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat; | |
126 if( $cat['lang'] == "en" ) $cat_en = $cat; | |
127 } | |
128 $program_disc = md5( $channel_disc . $starttime . $endtime ); | |
129 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); | |
130 try { | |
131 // 眼 | |
132 $category_disc = md5( $cat_ja . $cat_en ); | |
133 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); | |
134 $cat_rec = null; | |
135 if( $num == 0 ) { | |
136 // 域眼菴遵 | |
137 $cat_rec = new DBRecord( CATEGORY_TBL ); | |
138 $cat_rec->name_jp = $cat_ja; | |
139 $cat_rec->name_en = $cat_en; | |
140 $cat_rec->category_disc = $category_disc; | |
141 } | |
142 else | |
143 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc ); | |
144 // | |
145 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc ); | |
146 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); | |
147 if( $num == 0 ) { | |
148 // 域腟 | |
149 // 茲с 絽腟 | |
150 $options = "WHERE channel_disc = '".$channel_disc."' ". | |
151 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; | |
152 $battings = DBRecord::countRecords(PROGRAM_TBL, $options ); | |
153 if( $battings > 0 ) { | |
154 // 茲榊鐚丈紊 | |
155 $records = DBRecord::createRecords(PROGRAM_TBL, $options ); | |
156 foreach( $records as $rec ) { | |
157 // 牙私膣腟丈紊眼cゃ | |
158 try { | |
159 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); | |
160 if( $reserve->autorec ) { | |
161 Reservation::cancel( $reserve->id ); | |
162 } | |
163 } | |
164 catch( Exception $e ) { | |
165 //∴ | |
166 } | |
167 // 腟 | |
168 $rec->delete(); | |
169 } | |
170 } | |
171 // // | |
172 $rec = new DBRecord( PROGRAM_TBL ); | |
173 $rec->channel_disc = $channel_disc; | |
174 $rec->channel_id = $channel_rec->id; | |
175 $rec->type = $type; | |
176 $rec->channel = $channel_rec->channel; | |
177 $rec->title = $title; | |
178 $rec->description = $desc; | |
179 $rec->category_id = $cat_rec->id; | |
180 $rec->starttime = $starttime; | |
181 $rec->endtime = $endtime; | |
182 $rec->program_disc = $program_disc; | |
183 } | |
184 else { | |
185 // 腟絎号贋 | |
186 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc ); | |
187 $rec->title = $title; | |
188 $rec->description = $desc; | |
189 $rec->category_id = $cat_rec->id; | |
190 } | |
191 } | |
192 catch(Exception $e) { | |
193 exit( $e->getMessage() ); | |
194 } | |
195 } | |
196 } | |
197 ?> | 48 ?> |