comparison getepg.php @ 112:b3ba2658a228

merged with upstream
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 13 Mar 2010 18:27:33 +0900
parents 057ca53de6ca 3bed74eca373
children 4afd353b4507
comparison
equal deleted inserted replaced
110:74a174a245d2 112:b3ba2658a228
1 #!/usr/bin/php 1 #!/usr/bin/php
2 <?php 2 <?php
3 include_once('config.php'); 3 $script_path = dirname( __FILE__ );
4 chdir( $script_path );
5 include_once( $script_path . '/config.php');
4 include_once( INSTALL_PATH . '/DBRecord.class.php' ); 6 include_once( INSTALL_PATH . '/DBRecord.class.php' );
5 include_once( INSTALL_PATH . '/Reservation.class.php' ); 7 include_once( INSTALL_PATH . '/Reservation.class.php' );
6 include_once( INSTALL_PATH . '/Keyword.class.php' ); 8 include_once( INSTALL_PATH . '/Keyword.class.php' );
7 include_once( INSTALL_PATH . '/Settings.class.php' ); 9 include_once( INSTALL_PATH . '/Settings.class.php' );
10 include_once( INSTALL_PATH . '/storeProgram.inc.php' );
8 11
9 // 後方互換性 12 // 後方互換性
10 if( ! defined( "BS_EPG_CHANNEL" ) ) define( "BS_EPG_CHANNEL", "211" ); 13 if( ! defined( "BS_EPG_CHANNEL" ) ) define( "BS_EPG_CHANNEL", "211" );
11 if( ! defined( "CS1_EPG_CHANNEL" ) ) define( "CS1_EPG_CHANNEL", "CS8" ); 14 if( ! defined( "CS1_EPG_CHANNEL" ) ) define( "CS1_EPG_CHANNEL", "CS8" );
12 if( ! defined( "CS2_EPG_CHANNEL" ) ) define( "CS2_EPG_CHANNEL", "CS24" ); 15 if( ! defined( "CS2_EPG_CHANNEL" ) ) define( "CS2_EPG_CHANNEL", "CS24" );
13
14 16
15 function check_file( $file ) { 17 function check_file( $file ) {
16 // ファイルがないなら無問題 18 // ファイルがないなら無問題
17 if( ! file_exists( $file ) ) return true; 19 if( ! file_exists( $file ) ) return true;
18 20
22 return true; 24 return true;
23 } 25 }
24 26
25 return false; 27 return false;
26 } 28 }
29
30 // 並列化が可能か執念深く調べる
31 $use_para = false;
32 $use_para = (function_exists( "pcntl_fork" ) && function_exists( "posix_setsid" ) && function_exists( "pcntl_signal" ) && function_exists("pcntl_setpriority"));
33
27 34
28 $settings = Settings::factory(); 35 $settings = Settings::factory();
29 36
30 $temp_xml_bs = $settings->temp_xml."_bs"; 37 $temp_xml_bs = $settings->temp_xml."_bs";
31 $temp_xml_cs1 = $settings->temp_xml."_cs1"; 38 $temp_xml_cs1 = $settings->temp_xml."_cs1";
41 if($num < $settings->bs_tuners && check_file($temp_xml_bs)) { 48 if($num < $settings->bs_tuners && check_file($temp_xml_bs)) {
42 $cmdline = "CHANNEL=".BS_EPG_CHANNEL." DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; 49 $cmdline = "CHANNEL=".BS_EPG_CHANNEL." DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
43 exec( $cmdline ); 50 exec( $cmdline );
44 $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$temp_xml_bs; 51 $cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$temp_xml_bs;
45 exec( $cmdline ); 52 exec( $cmdline );
46 $cmdline = INSTALL_PATH."/storeProgram.php BS ".$temp_xml_bs." >/dev/null 2>&1 &"; 53 if( $use_para ) {
47 exec( $cmdline ); 54 $cmdline = INSTALL_PATH."/storeProgram.php BS ".$temp_xml_bs." >/dev/null 2>&1 &";
55 exec( $cmdline );
56 }
57 else {
58 storeProgram( "BS", $temp_xml_bs );
59 if( file_exists( $temp_xml_bs ) ) @unlink( $temp_xml_bs );
60 }
48 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 61 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
49 } 62 }
50 63
51 // CS 64 // CS
52 if ($settings->cs_rec_flg != 0) { 65 if ($settings->cs_rec_flg != 0) {
55 68
56 $cmdline = "CHANNEL=".CS1_EPG_CHANNEL." DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; 69 $cmdline = "CHANNEL=".CS1_EPG_CHANNEL." DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
57 exec( $cmdline ); 70 exec( $cmdline );
58 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs1; 71 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs1;
59 exec( $cmdline ); 72 exec( $cmdline );
60 $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs1." >/dev/null 2>&1 &"; 73 if( $use_para ) {
61 exec( $cmdline ); 74 $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs1." >/dev/null 2>&1 &";
75 exec( $cmdline );
76 }
77 else {
78 storeProgram( "CS", $temp_xml_cs1 );
79 if( file_exists( $temp_xml_cs1 ) ) @unlink( $temp_xml_cs1 );
80 }
62 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 81 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
63 } 82 }
64 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" ); 83 $num = DBRecord::countRecords( RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
65 if( ($num == 0) && check_file($temp_xml_cs2) ) { 84 if( ($num == 0) && check_file($temp_xml_cs2) ) {
66 $cmdline = "CHANNEL=".CS2_EPG_CHANNEL." DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; 85 $cmdline = "CHANNEL=".CS2_EPG_CHANNEL." DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
67 exec( $cmdline ); 86 exec( $cmdline );
68 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs2; 87 $cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$temp_xml_cs2;
69 exec( $cmdline ); 88 exec( $cmdline );
70 $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs2." >/dev/null 2>&1 &"; 89 if( $use_para ) {
71 exec( $cmdline ); 90 $cmdline = INSTALL_PATH."/storeProgram.php CS ".$temp_xml_cs2." >/dev/null 2>&1 &";
91 exec( $cmdline );
92 }
93 else {
94 storeProgram( "CS", $temp_xml_cs2 );
95 if( file_exists( $temp_xml_cs2 ) ) @unlink( $temp_xml_cs2 );
96 }
72 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 97 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
73 } 98 }
74 } 99 }
75 } 100 }
76 101
82 if($num < $settings->gr_tuners && check_file($temp_xml_gr.$value."")) { 107 if($num < $settings->gr_tuners && check_file($temp_xml_gr.$value."")) {
83 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1"; 108 $cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
84 exec( $cmdline ); 109 exec( $cmdline );
85 $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$temp_xml_gr.$value.""; 110 $cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$temp_xml_gr.$value."";
86 exec( $cmdline ); 111 exec( $cmdline );
87 $cmdline = INSTALL_PATH."/storeProgram.php GR ".$temp_xml_gr.$value." >/dev/null 2>&1 &"; 112 if( $use_para ) {
88 exec( $cmdline ); 113 $cmdline = INSTALL_PATH."/storeProgram.php GR ".$temp_xml_gr.$value." >/dev/null 2>&1 &";
114 exec( $cmdline );
115 }
116 else {
117 storeProgram( "GR", $temp_xml_gr.$value );
118 if( file_exists( $temp_xml_gr.$value ) ) @unlink( $temp_xml_gr.$value );
119 }
89 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data ); 120 if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
90 } 121 }
91 } 122 }
92 } 123 }
124 // 並列ならこれで終わりにする
125 if( $use_para ) exit();
93 126
127 garbageClean(); // 不要プログラム削除
128 doKeywordReservation(); // キーワード予約
129 exit();
94 ?> 130 ?>