Mercurial > epgrec.yaz
comparison getepg.php @ 37:e5f9aa34d06f
change: modify all script for web base setting
author | yoneda <epgrec@park.mda.or.jp> |
---|---|
date | Tue, 28 Jul 2009 00:00:04 +0900 |
parents | 6d334d32b657 |
children | 8965ef108821 |
comparison
equal
deleted
inserted
replaced
36:c2522d1df005 | 37:e5f9aa34d06f |
---|---|
2 <?php | 2 <?php |
3 include_once('config.php'); | 3 include_once('config.php'); |
4 include_once( INSTALL_PATH . '/DBRecord.class.php' ); | 4 include_once( INSTALL_PATH . '/DBRecord.class.php' ); |
5 include_once( INSTALL_PATH . '/Reservation.class.php' ); | 5 include_once( INSTALL_PATH . '/Reservation.class.php' ); |
6 include_once( INSTALL_PATH . '/Keyword.class.php' ); | 6 include_once( INSTALL_PATH . '/Keyword.class.php' ); |
7 include_once( INSTALL_PATH . '/Settings.class.php' ); | |
7 | 8 |
8 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA ); | 9 $settings = Settings::factory(); |
9 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML ); | 10 |
11 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); | |
12 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); | |
10 | 13 |
11 // BSを処理する | 14 // BSを処理する |
12 if( BS_TUNERS ) { | 15 if( $settings->bs_tuners ) { |
13 // 録画重複チェック | 16 // 録画重複チェック |
14 $num = DBRecord::countRecords( TBL_PREFIX . RESERVE_TBL, "WHERE complete = '0' AND type = 'BS' AND endtime > now() AND starttime < addtime( now(), '00:03:05')" ); | 17 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND type = 'BS' AND endtime > now() AND starttime < addtime( now(), '00:03:05')" ); |
15 if( $num == 0 ) { | 18 if( $num == 0 ) { |
16 $cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".TEMP_DATA." ".DO_RECORD . " >/dev/null 2>&1"; | 19 $cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; |
17 exec( $cmdline ); | 20 exec( $cmdline ); |
18 $cmdline = EPGDUMP." /BS ".TEMP_DATA." ".TEMP_XML; | 21 $cmdline = EPGDUMP." /BS ".$settings->temp_data." ".$settings->temp_xml; |
19 exec( $cmdline ); | 22 exec( $cmdline ); |
20 storeProgram( "BS", TEMP_XML ); | 23 storeProgram( "BS", $settings->temp_xml ); |
21 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA ); | 24 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); |
22 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML ); | 25 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); |
23 } | 26 } |
24 } | 27 } |
25 | 28 |
26 // 地上波を処理する | 29 // 地上波を処理する |
27 if( GR_TUNERS ) { | 30 if( $settings->gr_tuners ) { |
28 foreach( $GR_CHANNEL_MAP as $key=>$value ){ | 31 foreach( $GR_CHANNEL_MAP as $key=>$value ){ |
29 // 録画重複チェック | 32 // 録画重複チェック |
30 $num = DBRecord::countRecords( TBL_PREFIX . RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" ); | 33 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" ); |
31 if( $num == 0 ) { | 34 if( $num == 0 ) { |
32 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".TEMP_DATA." ".DO_RECORD . " >/dev/null 2>&1"; | 35 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; |
33 exec( $cmdline ); | 36 exec( $cmdline ); |
34 $cmdline = EPGDUMP." ".$key." ".TEMP_DATA." ".TEMP_XML; | 37 $cmdline = EPGDUMP." ".$key." ".$settings->temp_data." ".$settings->temp_xml; |
35 exec( $cmdline ); | 38 exec( $cmdline ); |
36 storeProgram( "GR", TEMP_XML ); | 39 storeProgram( "GR", $settings->temp_xml ); |
37 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA ); | 40 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); |
38 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML ); | 41 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); |
39 } | 42 } |
40 } | 43 } |
41 } | 44 } |
42 | 45 |
43 // 不要なプログラムの削除 | 46 // 不要なプログラムの削除 |
44 // 8日以上前のプログラムを消す | 47 // 8日以上前のプログラムを消す |
45 $arr = array(); | 48 $arr = array(); |
46 $arr = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); | 49 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); |
47 foreach( $arr as $val ) $val->delete(); | 50 foreach( $arr as $val ) $val->delete(); |
48 | 51 |
49 // 8日以上先のデータがあれば消す | 52 // 8日以上先のデータがあれば消す |
50 $arr = array(); | 53 $arr = array(); |
51 $arr = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); | 54 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); |
52 foreach( $arr as $val ) $val->delete(); | 55 foreach( $arr as $val ) $val->delete(); |
53 | 56 |
54 // キーワード自動録画予約 | 57 // キーワード自動録画予約 |
55 $arr = array(); | 58 $arr = array(); |
56 $arr = Keyword::createKeywords(); | 59 $arr = Keyword::createKeywords(); |
80 // channel抽出 | 83 // channel抽出 |
81 foreach( $xml->channel as $ch ) { | 84 foreach( $xml->channel as $ch ) { |
82 $disc = $ch['id']; | 85 $disc = $ch['id']; |
83 try { | 86 try { |
84 // チャンネルデータを探す | 87 // チャンネルデータを探す |
85 $num = DBRecord::countRecords( TBL_PREFIX . CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" ); | 88 $num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" ); |
86 if( $num == 0 ) { | 89 if( $num == 0 ) { |
87 // チャンネルデータがないなら新規作成 | 90 // チャンネルデータがないなら新規作成 |
88 $rec = new DBRecord( TBL_PREFIX . CHANNEL_TBL ); | 91 $rec = new DBRecord( CHANNEL_TBL ); |
89 $rec->type = $type; | 92 $rec->type = $type; |
90 $rec->channel = $map["$disc"]; | 93 $rec->channel = $map["$disc"]; |
91 $rec->channel_disc = $disc; | 94 $rec->channel_disc = $disc; |
92 $rec->name = $ch->{'display-name'}; | 95 $rec->name = $ch->{'display-name'}; |
93 } | 96 } |
94 else { | 97 else { |
95 // 存在した場合も、とりあえずチャンネル名は更新する | 98 // 存在した場合も、とりあえずチャンネル名は更新する |
96 $rec = new DBRecord(TBL_PREFIX.CHANNEL_TBL, "channel_disc", $disc ); | 99 $rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc ); |
97 $rec->name = $ch->{'display-name'}; | 100 $rec->name = $ch->{'display-name'}; |
98 } | 101 } |
99 } | 102 } |
100 catch( Exception $e ) { | 103 catch( Exception $e ) { |
101 // 無視 | 104 // 無視 |
121 $program_disc = md5( $channel_disc . $starttime . $endtime ); | 124 $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 ); | 125 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); |
123 try { | 126 try { |
124 // カテゴリを処理する | 127 // カテゴリを処理する |
125 $category_disc = md5( $cat_ja . $cat_en ); | 128 $category_disc = md5( $cat_ja . $cat_en ); |
126 $num = DBRecord::countRecords( TBL_PREFIX . CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); | 129 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); |
127 $cat_rec = null; | 130 $cat_rec = null; |
128 if( $num == 0 ) { | 131 if( $num == 0 ) { |
129 // 新規カテゴリの追加 | 132 // 新規カテゴリの追加 |
130 $cat_rec = new DBRecord( TBL_PREFIX . CATEGORY_TBL ); | 133 $cat_rec = new DBRecord( CATEGORY_TBL ); |
131 $cat_rec->name_jp = $cat_ja; | 134 $cat_rec->name_jp = $cat_ja; |
132 $cat_rec->name_en = $cat_en; | 135 $cat_rec->name_en = $cat_en; |
133 $cat_rec->category_disc = $category_disc; | 136 $cat_rec->category_disc = $category_disc; |
134 } | 137 } |
135 else | 138 else |
136 $cat_rec = new DBRecord( TBL_PREFIX . CATEGORY_TBL, "category_disc" , $category_disc ); | 139 $cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc ); |
137 // | 140 // |
138 $channel_rec = new DBRecord( TBL_PREFIX . CHANNEL_TBL, "channel_disc", $channel_disc ); | 141 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc ); |
139 $num = DBRecord::countRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); | 142 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); |
140 if( $num == 0 ) { | 143 if( $num == 0 ) { |
141 // 新規番組 | 144 // 新規番組 |
142 // 重複チェック 同時間帯にある番組 | 145 // 重複チェック 同時間帯にある番組 |
143 $options = "WHERE channel_disc = '".$channel_disc."' ". | 146 $options = "WHERE channel_disc = '".$channel_disc."' ". |
144 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; | 147 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; |
145 $battings = DBRecord::countRecords( TBL_PREFIX.PROGRAM_TBL, $options ); | 148 $battings = DBRecord::countRecords(PROGRAM_TBL, $options ); |
146 if( $battings > 0 ) { | 149 if( $battings > 0 ) { |
147 // 重複発生=おそらく放映時間の変更 | 150 // 重複発生=おそらく放映時間の変更 |
148 $records = DBRecord::createRecords( TBL_PREFIX.PROGRAM_TBL, $options ); | 151 $records = DBRecord::createRecords(PROGRAM_TBL, $options ); |
149 foreach( $records as $rec ) { | 152 foreach( $records as $rec ) { |
150 // 自動録画予約された番組は放映時間変更と同時にいったん削除する | 153 // 自動録画予約された番組は放映時間変更と同時にいったん削除する |
151 try { | 154 try { |
152 $reserve = new DBRecord(TBL_PREFIX.RESERVE_TBL, "program_id", $rec->id ); | 155 $reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id ); |
153 if( $reserve->autorec ) { | 156 if( $reserve->autorec ) { |
154 Reservation::cancel( $reserve->id ); | 157 Reservation::cancel( $reserve->id ); |
155 } | 158 } |
156 } | 159 } |
157 catch( Exception $e ) { | 160 catch( Exception $e ) { |
160 // 番組削除 | 163 // 番組削除 |
161 $rec->delete(); | 164 $rec->delete(); |
162 } | 165 } |
163 } | 166 } |
164 // // | 167 // // |
165 $rec = new DBRecord( TBL_PREFIX.PROGRAM_TBL ); | 168 $rec = new DBRecord( PROGRAM_TBL ); |
166 $rec->channel_disc = $channel_disc; | 169 $rec->channel_disc = $channel_disc; |
167 $rec->channel_id = $channel_rec->id; | 170 $rec->channel_id = $channel_rec->id; |
168 $rec->type = $type; | 171 $rec->type = $type; |
169 $rec->channel = $channel_rec->channel; | 172 $rec->channel = $channel_rec->channel; |
170 $rec->title = $title; | 173 $rec->title = $title; |
174 $rec->endtime = $endtime; | 177 $rec->endtime = $endtime; |
175 $rec->program_disc = $program_disc; | 178 $rec->program_disc = $program_disc; |
176 } | 179 } |
177 else { | 180 else { |
178 // 番組内容更新 | 181 // 番組内容更新 |
179 $rec = new DBRecord( TBL_PREFIX . PROGRAM_TBL, "program_disc", $program_disc ); | 182 $rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc ); |
180 $rec->title = $title; | 183 $rec->title = $title; |
181 $rec->description = $desc; | 184 $rec->description = $desc; |
182 $rec->category_id = $cat_rec->id; | 185 $rec->category_id = $cat_rec->id; |
183 } | 186 } |
184 } | 187 } |