changeset 83:f873e3251487

new: EPG取得の並列化テストを追加
author yoneda <yoneda@recorder.localnet.mda.or.jp>
date Sun, 28 Feb 2010 23:58:36 +0900
parents 330c83ae8c95
children 3ec5ca5e56ca
files getepg2.php storeProgram.php
diffstat 2 files changed, 262 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/getepg2.php	Sun Feb 28 23:58:36 2010 +0900
@@ -0,0 +1,69 @@
+#!/usr/bin/php
+<?php
+  include_once('config.php');
+  include_once( INSTALL_PATH . '/DBRecord.class.php' );
+  include_once( INSTALL_PATH . '/Reservation.class.php' );
+  include_once( INSTALL_PATH . '/Keyword.class.php' );
+  include_once( INSTALL_PATH . '/Settings.class.php' );
+  
+  $settings = Settings::factory();
+
+  if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
+  
+  // BS
+  if( $settings->bs_tuners != 0 ) {
+	// 牙脂茲с
+	$num = DBRecord::countRecords(  RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
+	if( ($num == 0) && !file_exists($settings->temp_xml."_bs") ) {
+	 	$cmdline = "CHANNEL=211 DURATION=180 TYPE=BS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
+  		exec( $cmdline );
+  		$cmdline = $settings->epgdump." /BS ".$settings->temp_data." ".$settings->temp_xml."_bs";
+  		exec( $cmdline );
+		$cmdline = INSTALL_PATH."/storeProgram.php BS ".$settings->temp_xml."_bs";
+		exec( $cmdline );
+  		if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
+	}
+
+	// CS
+	if ($settings->cs_rec_flg != 0) {
+		$num = DBRecord::countRecords(  RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
+		if( ($num == 0) && !file_exists($settings->temp_xml."_cs01") ) {
+			$cmdline = "CHANNEL=CS8 DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
+			exec( $cmdline );
+			$cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$settings->temp_xml."_cs01";
+			exec( $cmdline );
+			$cmdline = INSTALL_PATH."/storeProgram.php CS ".$settings->temp_xml."_cs01";
+			exec( $cmdline );
+			if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
+		}
+		$num = DBRecord::countRecords(  RESERVE_TBL, "WHERE complete = '0' AND (type = 'BS' OR type = 'CS') AND endtime > now() AND starttime < addtime( now(), '00:03:05')" );
+		if( ($num == 0) && !file_exists($settings->temp_xml."_cs02") ) {
+			$cmdline = "CHANNEL=CS24 DURATION=120 TYPE=CS TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
+			exec( $cmdline );
+			$cmdline = $settings->epgdump." /CS ".$settings->temp_data." ".$settings->temp_xml."_cs02";
+			exec( $cmdline );
+			$cmdline = INSTALL_PATH."/storeProgram.php CS ".$settings->temp_xml."_cs02";
+			exec( $cmdline );
+			if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
+	  	}
+  	}
+  }
+  
+  // 遺羈≪
+  if( $settings->gr_tuners != 0 ) {
+	foreach( $GR_CHANNEL_MAP as $key=>$value ){
+		// 牙脂茲с
+		$num = DBRecord::countRecords(  RESERVE_TBL, "WHERE complete = '0' AND type = 'GR' AND endtime > now() AND starttime < addtime( now(), '00:01:10')" );
+		if( ($num == 0) && !file_exists($settings->temp_xml."_".$value."") ) {
+			$cmdline = "CHANNEL=".$value." DURATION=60 TYPE=GR TUNER=0 MODE=0 OUTPUT=".$settings->temp_data." ".DO_RECORD . " >/dev/null 2>&1";
+			exec( $cmdline );
+			$cmdline = $settings->epgdump." ".$key." ".$settings->temp_data." ".$settings->temp_xml."_".$value."";
+			exec( $cmdline );
+			$cmdline = INSTALL_PATH."/storeProgram.php GR ".$settings->temp_xml."_".$value."";
+			exec( $cmdline );
+			if( file_exists( $settings->temp_data ) ) @unlink( $settings->temp_data );
+  		}
+  	}
+  }
+  
+?>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/storeProgram.php	Sun Feb 28 23:58:36 2010 +0900
@@ -0,0 +1,193 @@
+#!/usr/bin/php
+<?php
+
+  $type = $argv[1];	// BS CS GR
+  $file = $argv[2];	// XML<ゃ
+  
+  
+  // SIGTERM激違
+  function handler( $signo = 0 ) {
+	global $file;
+	if( file_exists( $file ) ) {
+		@unlink( $file );
+	}
+	exit();
+  }
+  
+  // 若≪喝
+  function daemon() {
+	if( pcntl_fork() != 0 )
+		exit();
+	posix_setsid();
+	if( pcntl_fork() != 0 )
+		exit;
+	pcntl_signal(SIGTERM, "handler");
+  }
+  
+  
+  // 若≪喝
+  daemon();
+  // ゃd
+  pcntl_setpriority(20);
+  
+  include_once('config.php');
+  include_once( INSTALL_PATH . '/DBRecord.class.php' );
+  include_once( INSTALL_PATH . '/Reservation.class.php' );
+  include_once( INSTALL_PATH . '/Keyword.class.php' );
+  include_once( INSTALL_PATH . '/Settings.class.php' );
+  
+  $settings = Settings::factory();
+  
+  if( file_exists( $file ) ) {
+	storeProgram( $type, $file );
+	@unlink( $file );
+  }
+  
+  // 筝荀違
+  // 8ヤ札筝違羔
+  $arr = array();
+  $arr = DBRecord::createRecords(  PROGRAM_TBL, "WHERE endtime < subdate( now(), 8 )" );
+  foreach( $arr as $val ) $val->delete();
+	
+  // 8ヤ札筝若帥井
+  $arr = array();
+  $arr = DBRecord::createRecords(  PROGRAM_TBL, "WHERE starttime  > adddate( now(), 8 )" );
+  foreach( $arr as $val ) $val->delete();
+  
+  // 若若牙私膣
+  $arr = array();
+  $arr = Keyword::createKeywords();
+  foreach( $arr as $val ) {
+	try {
+		$val->reservation();
+	}
+	catch( Exception $e ) {
+		// ∴
+	}
+  }
+  exit();
+  
+  function storeProgram( $type, $xmlfile ) {
+	global $BS_CHANNEL_MAP, $GR_CHANNEL_MAP, $CS_CHANNEL_MAP;
+	// c潟<ゃ羣
+	$map = array();
+	if( $type == "BS" ) $map = $BS_CHANNEL_MAP;
+	else if( $type == "GR") $map = $GR_CHANNEL_MAP;
+	else if( $type == "CS") $map = $CS_CHANNEL_MAP;
+	
+	// XML parse
+  	$xml = @simplexml_load_file( $xmlfile );
+	if( $xml === false ) {
+		return;	// XML茯水篏
+	}
+	// channel遵
+	foreach( $xml->channel as $ch ) {
+		$disc = $ch['id'];
+	 try {
+		// c潟若帥「
+		$num = DBRecord::countRecords( CHANNEL_TBL , "WHERE channel_disc = '" . $disc ."'" );
+		if( $num == 0 ) {
+			// c潟若帥域鋎
+			$rec = new DBRecord( CHANNEL_TBL );
+			$rec->type = $type;
+			$rec->channel = $map["$disc"];
+			$rec->channel_disc = $disc;
+			$rec->name = $ch->{'display-name'};
+		}
+		else {
+			// 絖翫c潟贋違
+			$rec = new DBRecord(CHANNEL_TBL, "channel_disc", $disc );
+			$rec->name = $ch->{'display-name'};
+		}
+	 }
+	 catch( Exception $e ) {
+		// ∴
+	 }
+	}
+	// channel 腟篋
+	
+	// programme 緇
+	
+	foreach( $xml->programme as $program ) {
+		$channel_disc = $program['channel']; 
+		$channel = $map["$channel_disc"];
+		$starttime = str_replace(" +0900", '', $program['start'] );
+		$endtime = str_replace( " +0900", '', $program['stop'] );
+		$title = $program->title;
+		$desc = $program->desc;
+		$cat_ja = "";
+		$cat_en = "";
+		foreach( $program->category as $cat ) {
+			if( $cat['lang'] == "ja_JP" ) $cat_ja = $cat;
+			if( $cat['lang'] == "en" ) $cat_en = $cat;
+		}
+		$program_disc = md5( $channel_disc . $starttime . $endtime );
+		// printf( "%s %s %s %s %s %s %s \n", $program_disc, $channel, $starttime, $endtime, $title, $desc, $cat_ja );
+		try {
+		 // 眼
+		 $category_disc = md5( $cat_ja . $cat_en );
+		 $num = DBRecord::countRecords(CATEGORY_TBL, "WHERE category_disc = '".$category_disc."'" );
+		 $cat_rec = null;
+		 if( $num == 0 ) {
+			// 域眼菴遵
+			$cat_rec = new DBRecord( CATEGORY_TBL );
+			$cat_rec->name_jp = $cat_ja;
+			$cat_rec->name_en = $cat_en;
+		 	$cat_rec->category_disc = $category_disc;
+		 }
+		 else
+			$cat_rec = new DBRecord(CATEGORY_TBL, "category_disc" , $category_disc );
+		  //
+		 $channel_rec = new DBRecord(CHANNEL_TBL, "channel_disc", $channel_disc );
+		 $num = DBRecord::countRecords(PROGRAM_TBL, "WHERE program_disc = '".$program_disc."'" );
+		 if( $num == 0 ) {
+			// 域腟
+			// 茲с 絽腟
+			$options = "WHERE channel_disc = '".$channel_disc."' ".
+				"AND starttime < '". $endtime ."' AND endtime > '".$starttime."'";
+			$battings = DBRecord::countRecords(PROGRAM_TBL, $options );
+			if( $battings > 0 ) {
+				// 茲榊鐚丈紊
+				$records = DBRecord::createRecords(PROGRAM_TBL, $options );
+				foreach( $records as $rec ) {
+					// 牙私膣腟丈紊眼cゃ
+					try {
+						$reserve = new DBRecord(RESERVE_TBL, "program_id", $rec->id );
+						if( $reserve->autorec ) {
+							Reservation::cancel( $reserve->id );
+						}
+					}
+					catch( Exception $e ) {
+						//∴
+					}
+					// 腟
+					$rec->delete();
+				}
+			}
+			// //
+			$rec = new DBRecord( PROGRAM_TBL );
+			$rec->channel_disc = $channel_disc;
+			$rec->channel_id = $channel_rec->id;
+			$rec->type = $type;
+			$rec->channel = $channel_rec->channel;
+			$rec->title = $title;
+			$rec->description = $desc;
+			$rec->category_id = $cat_rec->id;
+			$rec->starttime = $starttime;
+			$rec->endtime = $endtime;
+			$rec->program_disc = $program_disc;
+		 }
+		 else {
+			// 腟絎号贋
+			$rec = new DBRecord( PROGRAM_TBL, "program_disc", $program_disc );
+			$rec->title = $title;
+		 	$rec->description = $desc;
+			$rec->category_id = $cat_rec->id;
+		 }
+		}
+		catch(Exception $e) {
+			exit( $e->getMessage() );
+		}
+	}
+  }
+?>
\ No newline at end of file