Mercurial > epgrec.yaz
comparison getepg.php @ 1:f5a9f0eb4858
deleted: LICENSE.ja
author | Sushi-k <epgrec@park.mda.or.jp> |
---|---|
date | Wed, 08 Jul 2009 11:44:50 +0900 |
parents | |
children | 6d334d32b657 |
comparison
equal
deleted
inserted
replaced
0:96312e6ab8d4 | 1:f5a9f0eb4858 |
---|---|
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 | |
8 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA ); | |
9 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML ); | |
10 | |
11 // BSを処理する | |
12 if( BS_TUNERS ) { | |
13 // 録画重複チェック | |
14 $num = DBRecord::countRecords( TBL_PREFIX . RESERVE_TBL, "WHERE complete = '0' AND type = 'BS' AND endtime > now() AND starttime < addtime( now(), '00:03:05')" ); | |
15 if( $num == 0 ) { | |
16 $cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".TEMP_DATA." ".DO_RECORD . " >/dev/null 2>&1"; | |
17 exec( $cmdline ); | |
18 $cmdline = EPGDUMP." /BS ".TEMP_DATA." ".TEMP_XML; | |
19 exec( $cmdline ); | |
20 storeProgram( "BS", TEMP_XML ); | |
21 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA ); | |
22 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML ); | |
23 } | |
24 } | |
25 | |
26 // 地上波を処理する | |
27 if( GR_TUNERS ) { | |
28 foreach( $GR_CHANNEL_MAP as $key=>$value ){ | |
29 // 録画重複チェック | |
30 $num = DBRecord::countRecords( TBL_PREFIX . RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" ); | |
31 if( $num == 0 ) { | |
32 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".TEMP_DATA." ".DO_RECORD . " >/dev/null 2>&1"; | |
33 exec( $cmdline ); | |
34 $cmdline = EPGDUMP." ".$key." ".TEMP_DATA." ".TEMP_XML; | |
35 exec( $cmdline ); | |
36 storeProgram( "GR", TEMP_XML ); | |
37 if( file_exists( TEMP_DATA ) ) @unlink( TEMP_DATA ); | |
38 if( file_exists( TEMP_XML ) ) @unlink( TEMP_XML ); | |
39 } | |
40 } | |
41 } | |
42 | |
43 // 不要なプログラムの削除 | |
44 // 8日以上前のプログラムを消す | |
45 $arr = array(); | |
46 $arr = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); | |
47 foreach( $arr as $val ) $val->delete(); | |
48 | |
49 // 8日以上先のデータがあれば消す | |
50 $arr = array(); | |
51 $arr = DBRecord::createRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); | |
52 foreach( $arr as $val ) $val->delete(); | |
53 | |
54 // キーワード自動録画予約 | |
55 $arr = array(); | |
56 $arr = Keyword::createKeywords(); | |
57 foreach( $arr as $val ) { | |
58 try { | |
59 $val->reservation(); | |
60 } | |
61 catch( Exception $e ) { | |
62 // 無視 | |
63 } | |
64 } | |
65 | |
66 exit(); | |
67 | |
68 function storeProgram( $type, $xmlfile ) { | |
69 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP; | |
70 // チャンネルマップファイルの準備 | |
71 $map = array(); | |
72 if( $type == "BS" ) $map = $BS_CHANNEL_MAP; | |
73 else if( $type == "GR") $map = $GR_CHANNEL_MAP; | |
74 | |
75 // XML parse | |
76 $xml = @simplexml_load_file( $xmlfile ); | |
77 if( $xml === false ) { | |
78 return; // XMLが読み取れないなら何もしない | |
79 } | |
80 // channel抽出 | |
81 foreach( $xml->channel as $ch ) { | |
82 $disc = $ch['id']; | |
83 try { | |
84 // チャンネルデータを探す | |
85 $num = DBRecord::countRecords( TBL_PREFIX . CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" ); | |
86 if( $num == 0 ) { | |
87 // チャンネルデータがないなら新規作成 | |
88 $rec = new DBRecord( TBL_PREFIX . CHANNEL_TBL ); | |
89 $rec->type = $type; | |
90 $rec->channel = $map["$disc"]; | |
91 $rec->channel_disc = $disc; | |
92 $rec->name = $ch->{'display-name'}; | |
93 } | |
94 } | |
95 catch( Exception $e ) { | |
96 exit( "ChannelUpdater::". $e->getMessage() ); | |
97 } | |
98 } | |
99 // channel 終了 | |
100 | |
101 // programme 取得 | |
102 | |
103 foreach( $xml->programme as $program ) { | |
104 $channel_disc = $program['channel']; | |
105 $channel = $map["$channel_disc"]; | |
106 $starttime = ereg_replace(" \+0900", '', $program['start'] ); | |
107 $endtime = ereg_replace( " \+0900", '', $program['stop'] ); | |
108 $title = $program->title; | |
109 $desc = $program->desc; | |
110 $cat_ja = ""; | |
111 $cat_en = ""; | |
112 foreach( $program->category as $cat ) { | |
113 if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat; | |
114 if( $cat['lang'] == "en" ) $cat_en = $cat; | |
115 } | |
116 $program_disc = md5( $channel_disc . $starttime . $endtime ); | |
117 // printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja ); | |
118 try { | |
119 // カテゴリを処理する | |
120 $category_disc = md5( $cat_ja . $cat_en ); | |
121 $num = DBRecord::countRecords( TBL_PREFIX . CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" ); | |
122 $cat_rec = null; | |
123 if( $num == 0 ) { | |
124 // 新規カテゴリの追加 | |
125 $cat_rec = new DBRecord( TBL_PREFIX . CATEGORY_TBL ); | |
126 $cat_rec->name_jp = $cat_ja; | |
127 $cat_rec->name_en = $cat_en; | |
128 $cat_rec->category_disc = $category_disc; | |
129 } | |
130 else | |
131 $cat_rec = new DBRecord( TBL_PREFIX . CATEGORY_TBL, "category_disc" , $category_disc ); | |
132 // | |
133 $channel_rec = new DBRecord( TBL_PREFIX . CHANNEL_TBL, "channel_disc", $channel_disc ); | |
134 $num = DBRecord::countRecords( TBL_PREFIX . PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" ); | |
135 if( $num == 0 ) { | |
136 // 新規番組 | |
137 // 重複チェック 同時間帯にある番組 | |
138 $options = "WHERE channel_disc = '".$channel_disc."' ". | |
139 "AND starttime < '". $endtime ."' AND endtime > '".$starttime."'"; | |
140 $battings = DBRecord::countRecords( TBL_PREFIX.PROGRAM_TBL, $options ); | |
141 if( $battings > 0 ) { | |
142 // 重複発生=おそらく放映時間の変更 | |
143 $records = DBRecord::createRecords( TBL_PREFIX.PROGRAM_TBL, $options ); | |
144 foreach( $records as $rec ) { | |
145 // 自動録画予約された番組は放映時間変更と同時にいったん削除する | |
146 try { | |
147 $reserve = new DBRecord(TBL_PREFIX.RESERVE_TBL, "program_id", $rec->id ); | |
148 if( $reserve->autorec ) { | |
149 Reservation::cancel( $reserve->id ); | |
150 } | |
151 } | |
152 catch( Exception $e ) { | |
153 //無視 | |
154 } | |
155 // 番組削除 | |
156 $rec->delete(); | |
157 } | |
158 } | |
159 // // | |
160 $rec = new DBRecord( TBL_PREFIX.PROGRAM_TBL ); | |
161 $rec->channel_disc = $channel_disc; | |
162 $rec->channel_id = $channel_rec->id; | |
163 $rec->type = $type; | |
164 $rec->channel = $channel_rec->channel; | |
165 $rec->title = $title; | |
166 $rec->description = $desc; | |
167 $rec->category_id = $cat_rec->id; | |
168 $rec->starttime = $starttime; | |
169 $rec->endtime = $endtime; | |
170 $rec->program_disc = $program_disc; | |
171 } | |
172 else { | |
173 // 番組内容更新 | |
174 $rec = new DBRecord( TBL_PREFIX . PROGRAM_TBL, "program_disc", $program_disc ); | |
175 $rec->title = $title; | |
176 $rec->description = $desc; | |
177 $rec->category_id = $cat_rec->id; | |
178 } | |
179 } | |
180 catch(Exception $e) { | |
181 exit( $e->getMessage() ); | |
182 } | |
183 } | |
184 } | |
185 ?> |