3 $script_path = dirname( __FILE__ );
5 include_once( $script_path . '/config.php');
6 include_once( INSTALL_PATH . '/DBRecord.class.php' );
7 include_once( INSTALL_PATH . '/Reservation.class.php' );
8 include_once( INSTALL_PATH . '/Keyword.class.php' );
9 include_once( INSTALL_PATH . '/Settings.class.php' );
10 include_once( INSTALL_PATH . '/storeProgram.inc.php' );
11 include_once( INSTALL_PATH . '/recLog.inc.php' );
14 if( ! defined( "BS_EPG_CHANNEL" ) ) define( "BS_EPG_CHANNEL", "211" );
15 if( ! defined( "CS1_EPG_CHANNEL" ) ) define( "CS1_EPG_CHANNEL", "CS8" );
16 if( ! defined( "CS2_EPG_CHANNEL" ) ) define( "CS2_EPG_CHANNEL", "CS24" );
18 function check_file( $file ) {
20 if( ! file_exists( $file ) ) return true;
22 // 1時間以上前のファイルなら削除してやり直す
23 if( (time() - filemtime( $file )) > 3600 ) {
33 $use_para = (function_exists( "pcntl_fork" ) && function_exists( "posix_setsid" ) && function_exists( "pcntl_signal" ) && function_exists("pcntl_setpriority"));
35 reclog("getepg:: 並列実行が行えないPHP環境です" );
38 reclog("getepg:: 並列実行を使用します" );
41 $settings = Settings::factory();
43 $temp_xml_bs = $settings->temp_xml."_bs";
44 $temp_xml_cs1 = $settings->temp_xml."_cs1";
45 $temp_xml_cs2 = $settings->temp_xml."_cs2";
46 $temp_xml_gr = $settings->temp_xml."_gr";
48 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
51 if( $settings->bs_tuners != 0 ) {
53 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
54 if( ($num == 0) && check_file($temp_xml_bs) ) {
55 $cmdline = "CHANNEL=".BS_EPG_CHANNEL." DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
57 $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$temp_xml_bs;
60 $cmdline = INSTALL_PATH."/storeProgram.php BS ".$temp_xml_bs." >/dev/null 2>&1 &";
64 storeProgram( "BS", $temp_xml_bs );
65 if( file_exists( $temp_xml_bs ) ) @unlink( $temp_xml_bs );
67 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
71 if ($settings->cs_rec_flg != 0) {
72 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
73 if( ($num == 0) && check_file($temp_xml_cs1) ) {
74 $cmdline = "CHANNEL=".CS1_EPG_CHANNEL." DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
76 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs1;
79 $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs1." >/dev/null 2>&1 &";
83 storeProgram( "CS", $temp_xml_cs1 );
84 if( file_exists( $temp_xml_cs1 ) ) @unlink( $temp_xml_cs1 );
86 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
88 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
89 if( ($num == 0) && check_file($temp_xml_cs2) ) {
90 $cmdline = "CHANNEL=".CS2_EPG_CHANNEL." DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
92 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs2;
95 $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs2." >/dev/null 2>&1 &";
99 storeProgram( "CS", $temp_xml_cs2 );
100 if( file_exists( $temp_xml_cs2 ) ) @unlink( $temp_xml_cs2 );
102 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
108 if( $settings->gr_tuners != 0 ) {
109 foreach( $GR_CHANNEL_MAP as $key=>$value ){
111 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" );
112 if( ($num == 0) && check_file($temp_xml_gr.$value."") ) {
113 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
115 $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$temp_xml_gr.$value."";
118 $cmdline = INSTALL_PATH."/storeProgram.php GR ".$temp_xml_gr.$value." >/dev/null 2>&1 &";
122 storeProgram( "GR", $temp_xml_gr.$value );
123 if( file_exists( $temp_xml_gr.$value ) ) @unlink( $temp_xml_gr.$value );
125 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
130 if( $use_para ) exit();
132 garbageClean(); // 不要プログラム削除
133 doKeywordReservation(); // キーワード予約