comparison getepg.php @ 72:605d327bddcc

- tuner occupation check was too strict - removed trailing whitespace
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 26 Jan 2010 22:02:54 +0900
parents 1363ac056197
children 36ac7c416bd7
comparison
equal deleted inserted replaced
71:29131bd8dea3 72:605d327bddcc
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 include_once( INSTALL_PATH . '/Settings.class.php' );
8 8
9 $settings = Settings::factory(); 9 $settings = Settings::factory();
10 10
11 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 11 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
12 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); 12 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
13 13
14 // BSを処理する 14 // BSを処理する
15 if( $settings->bs_tuners != 0 ) { 15 if( $settings->bs_tuners != 0 ) {
16 // 録画重複チェック 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')" ); 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 ) { 18 if( $num < $settings->bs_tuners ) {
19 $cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->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";
20 exec( $cmdline ); 20 exec( $cmdline );
21 $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$settings->temp_xml; 21 $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$settings->temp_xml;
22 exec( $cmdline ); 22 exec( $cmdline );
23 storeProgram( "BS", $settings->temp_xml ); 23 storeProgram( "BS", $settings->temp_xml );
42 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 42 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
43 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); 43 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
44 } 44 }
45 } 45 }
46 } 46 }
47 47
48 // 地上波を処理する 48 // 地上波を処理する
49 if( $settings->gr_tuners != 0 ) { 49 if( $settings->gr_tuners != 0 ) {
50 foreach( $GR_CHANNEL_MAP as $key=>$value ){ 50 foreach( $GR_CHANNEL_MAP as $key=>$value ){
51 // 録画重複チェック 51 // 録画重複チェック
52 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" ); 52 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" );
53 if( $num == 0 ) { 53 if( $num < $settings->gr_tuners ) {
54 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; 54 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
55 exec( $cmdline ); 55 exec( $cmdline );
56 $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$settings->temp_xml; 56 $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$settings->temp_xml;
57 exec( $cmdline ); 57 exec( $cmdline );
58 storeProgram( "GR", $settings->temp_xml ); 58 storeProgram( "GR", $settings->temp_xml );
59 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 59 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
60 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml ); 60 if( file_exists( $settings->temp_xml ) ) @unlink( $settings->temp_xml );
61 } 61 }
62 } 62 }
63 } 63 }
64 64
65 // 不要なプログラムの削除 65 // 不要なプログラムの削除
66 // 8日以上前のプログラムを消す 66 // 8日以上前のプログラムを消す
67 $arr = array(); 67 $arr = array();
68 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); 68 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" );
69 foreach( $arr as $val ) $val->delete(); 69 foreach( $arr as $val ) $val->delete();
70 70
71 // 8日以上先のデータがあれば消す 71 // 8日以上先のデータがあれば消す
72 $arr = array(); 72 $arr = array();
73 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); 73 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" );
74 foreach( $arr as $val ) $val->delete(); 74 foreach( $arr as $val ) $val->delete();
75 75
76 // キーワード自動録画予約 76 // キーワード自動録画予約
77 $arr = array(); 77 $arr = array();
78 $arr = Keyword::createKeywords(); 78 $arr = Keyword::createKeywords();
79 foreach( $arr as $val ) { 79 foreach( $arr as $val ) {
80 try { 80 try {
82 } 82 }
83 catch( Exception $e ) { 83 catch( Exception $e ) {
84 // 無視 84 // 無視
85 } 85 }
86 } 86 }
87 87
88 exit(); 88 exit();
89 89
90 function storeProgram( $type, $xmlfile ) { 90 function storeProgram( $type, $xmlfile ) {
91 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; 91 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP;
92 // チャンネルマップファイルの準備 92 // チャンネルマップファイルの準備
93 $map = array(); 93 $map = array();
94 if( $type == "BS" ) $map = $BS_CHANNEL_MAP; 94 if( $type == "BS" ) $map = $BS_CHANNEL_MAP;
95 else if( $type == "GR") $map = $GR_CHANNEL_MAP; 95 else if( $type == "GR") $map = $GR_CHANNEL_MAP;
96 else if( $type == "CS") $map = $CS_CHANNEL_MAP; 96 else if( $type == "CS") $map = $CS_CHANNEL_MAP;
97 97
98 // XML parse 98 // XML parse
99 $xml = @simplexml_load_file( $xmlfile ); 99 $xml = @simplexml_load_file( $xmlfile );
100 if( $xml === false ) { 100 if( $xml === false ) {
101 return; // XMLが読み取れないなら何もしない 101 return; // XMLが読み取れないなら何もしない
102 } 102 }
123 catch( Exception $e ) { 123 catch( Exception $e ) {
124 // 無視 124 // 無視
125 } 125 }
126 } 126 }
127 // channel 終了 127 // channel 終了
128 128
129 // programme 取得 129 // programme 取得
130 130
131 foreach( $xml->programme as $program ) { 131 foreach( $xml->programme as $program ) {
132 $channel_disc = $program['channel']; 132 $channel_disc = $program['channel'];
133 $channel = $map["$channel_disc"]; 133 $channel = $map["$channel_disc"];
134 $starttime = str_replace(" +0900", '', $program['start'] ); 134 $starttime = str_replace(" +0900", '', $program['start'] );
135 $endtime = str_replace( " +0900", '', $program['stop'] ); 135 $endtime = str_replace( " +0900", '', $program['stop'] );
136 $title = $program->title; 136 $title = $program->title;
137 $desc = $program->desc; 137 $desc = $program->desc;