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