Mercurial > epgrec.yaz
comparison storeProgram.php @ 98:f7b6ae03a2a7
removed trailing whitespace
| author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
|---|---|
| date | Wed, 03 Mar 2010 06:24:22 +0900 |
| parents | d9b9d1d903a1 |
| children | b3ba2658a228 |
comparison
equal
deleted
inserted
replaced
| 97:ee348c378f2d | 98:f7b6ae03a2a7 |
|---|---|
| 1 #!/usr/bin/php | 1 #!/usr/bin/php |
| 2 <?php | 2 <?php |
| 3 | 3 |
| 4 $type = $argv[1]; // BS CS GR | 4 $type = $argv[1]; // BS CS GR |
| 5 $file = $argv[2]; // XMLファイル | 5 $file = $argv[2]; // XMLファイル |
| 6 | 6 |
| 7 | 7 |
| 8 // SIGTERMシグナル | 8 // SIGTERMシグナル |
| 9 function handler( $signo = 0 ) { | 9 function handler( $signo = 0 ) { |
| 10 global $file; | 10 global $file; |
| 11 if( file_exists( $file ) ) { | 11 if( file_exists( $file ) ) { |
| 12 @unlink( $file ); | 12 @unlink( $file ); |
| 13 } | 13 } |
| 14 exit(); | 14 exit(); |
| 15 } | 15 } |
| 16 | 16 |
| 17 // デーモン化 | 17 // デーモン化 |
| 18 function daemon() { | 18 function daemon() { |
| 19 if( pcntl_fork() != 0 ) | 19 if( pcntl_fork() != 0 ) |
| 20 exit(); | 20 exit(); |
| 21 posix_setsid(); | 21 posix_setsid(); |
| 22 if( pcntl_fork() != 0 ) | 22 if( pcntl_fork() != 0 ) |
| 23 exit; | 23 exit; |
| 24 pcntl_signal(SIGTERM, "handler"); | 24 pcntl_signal(SIGTERM, "handler"); |
| 25 } | 25 } |
| 26 | 26 |
| 27 | 27 |
| 28 // デーモン化 | 28 // デーモン化 |
| 29 daemon(); | 29 daemon(); |
| 30 // プライオリティ低に | 30 // プライオリティ低に |
| 31 pcntl_setpriority(20); | 31 pcntl_setpriority(20); |
| 32 | 32 |
| 33 include_once('config.php'); | 33 include_once('config.php'); |
| 34 include_once( INSTALL_PATH . '/DBRecord.class.php' ); | 34 include_once( INSTALL_PATH . '/DBRecord.class.php' ); |
| 35 include_once( INSTALL_PATH . '/Reservation.class.php' ); | 35 include_once( INSTALL_PATH . '/Reservation.class.php' ); |
| 36 include_once( INSTALL_PATH . '/Keyword.class.php' ); | 36 include_once( INSTALL_PATH . '/Keyword.class.php' ); |
| 37 include_once( INSTALL_PATH . '/Settings.class.php' ); | 37 include_once( INSTALL_PATH . '/Settings.class.php' ); |
| 38 | 38 |
| 39 $settings = Settings::factory(); | 39 $settings = Settings::factory(); |
| 40 | 40 |
| 41 if( file_exists( $file ) ) { | 41 if( file_exists( $file ) ) { |
| 42 storeProgram( $type, $file ); | 42 storeProgram( $type, $file ); |
| 43 @unlink( $file ); | 43 @unlink( $file ); |
| 44 } | 44 } |
| 45 | 45 |
| 46 // 不要なプログラムの削除 | 46 // 不要なプログラムの削除 |
| 47 // 8日以上前のプログラムを消す | 47 // 8日以上前のプログラムを消す |
| 48 $arr = array(); | 48 $arr = array(); |
| 49 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); | 49 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" ); |
| 50 foreach( $arr as $val ) $val->delete(); | 50 foreach( $arr as $val ) $val->delete(); |
| 51 | 51 |
| 52 // 8日以上先のデータがあれば消す | 52 // 8日以上先のデータがあれば消す |
| 53 $arr = array(); | 53 $arr = array(); |
| 54 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); | 54 $arr = DBRecord::createRecords( PROGRAM_TBL, "WHERE starttime > adddate( now(), 8 )" ); |
| 55 foreach( $arr as $val ) $val->delete(); | 55 foreach( $arr as $val ) $val->delete(); |
| 56 | 56 |
| 57 // キーワード自動録画予約 | 57 // キーワード自動録画予約 |
| 58 $arr = array(); | 58 $arr = array(); |
| 59 $arr = Keyword::createKeywords(); | 59 $arr = Keyword::createKeywords(); |
| 60 foreach( $arr as $val ) { | 60 foreach( $arr as $val ) { |
| 61 try { | 61 try { |
| 64 catch( Exception $e ) { | 64 catch( Exception $e ) { |
| 65 // 無視 | 65 // 無視 |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 exit(); | 68 exit(); |
| 69 | 69 |
| 70 function storeProgram( $type, $xmlfile ) { | 70 function storeProgram( $type, $xmlfile ) { |
| 71 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; | 71 global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP; |
| 72 // チャンネルマップファイルの準備 | 72 // チャンネルマップファイルの準備 |
| 73 $map = array(); | 73 $map = array(); |
| 74 if( $type == "BS" ) $map = $BS_CHANNEL_MAP; | 74 if( $type == "BS" ) $map = $BS_CHANNEL_MAP; |
| 75 else if( $type == "GR") $map = $GR_CHANNEL_MAP; | 75 else if( $type == "GR") $map = $GR_CHANNEL_MAP; |
| 76 else if( $type == "CS") $map = $CS_CHANNEL_MAP; | 76 else if( $type == "CS") $map = $CS_CHANNEL_MAP; |
| 77 | 77 |
| 78 // XML parse | 78 // XML parse |
| 79 $xml = @simplexml_load_file( $xmlfile ); | 79 $xml = @simplexml_load_file( $xmlfile ); |
| 80 if( $xml === false ) { | 80 if( $xml === false ) { |
| 81 return; // XMLが読み取れないなら何もしない | 81 return; // XMLが読み取れないなら何もしない |
| 82 } | 82 } |
| 105 catch( Exception $e ) { | 105 catch( Exception $e ) { |
| 106 // 無視 | 106 // 無視 |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 // channel 終了 | 109 // channel 終了 |
| 110 | 110 |
| 111 // programme 取得 | 111 // programme 取得 |
| 112 | 112 |
| 113 foreach( $xml->programme as $program ) { | 113 foreach( $xml->programme as $program ) { |
| 114 $channel_disc = $program['channel']; | 114 $channel_disc = $program['channel']; |
| 115 if( ! array_key_exists( "$channel_disc", $map ) ) continue; | 115 if( ! array_key_exists( "$channel_disc", $map ) ) continue; |
| 116 | 116 |
| 117 $channel = $map["$channel_disc"]; | 117 $channel = $map["$channel_disc"]; |
| 118 $starttime = str_replace(" +0900", '', $program['start'] ); | 118 $starttime = str_replace(" +0900", '', $program['start'] ); |
| 119 $endtime = str_replace( " +0900", '', $program['stop'] ); | 119 $endtime = str_replace( " +0900", '', $program['stop'] ); |
| 120 $title = $program->title; | 120 $title = $program->title; |
| 121 $desc = $program->desc; | 121 $desc = $program->desc; |
