チェンジセット 83: trunk/install/perl/recwrap.pl
- コミット日時:
- 2008/12/30 22:12:46 (15 年前)
- ファイル:
凡例:
- 変更無し
- 追加
- 削除
- 更新
- コピー
- 移動
trunk/install/perl/recwrap.pl
r70 r83 1 1 #!/usr/bin/perl 2 #usage recwrap.pl ch length(sec) [bitrate(5)] [TID] [NO] [PID]2 #usage recwrap.pl ch length(sec) [bitrate(5)] [TID] [NO] [PID] [stationid] [digitalflag] [digitalband] [digitalch] 3 3 # 4 4 # Anime recording system foltia … … 39 39 $tid = $ARGV[3] ; 40 40 $countno = $ARGV[4] ; 41 $pid = $ARGV[5] ; 41 $pid = $ARGV[5] ; 42 $stationid = $ARGV[6] ; 43 $usedigital = $ARGV[7] ; 44 $digitalstationband = $ARGV[8] ; 45 $digitalch= $ARGV[9] ; 46 47 #DB初期化 48 my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", 49 $DBDriv,$DBName,$DBHost,$DBPort); 50 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; 51 52 53 if ($usedigital == 1){ 54 $extension = ".m2t";#TSの拡張子 55 }else{ 56 $extension = ".m2p";#MPEG2の拡張子 57 } 42 58 43 59 $outputfile = `date +%Y%m%d-%H%M --date "1 min "`; 44 60 chomp($outputfile); 61 45 62 if ($tid == 0){ 46 $outputfilename = "0--".$outputfile."-".$recch. ".m2p";63 $outputfilename = "0--".$outputfile."-".$recch.$extension; 47 64 $mp4newstylefilename = "-0--".$outputfile."-".$recch; 48 65 }else{ 49 66 if ($countno == 0){ 50 $outputfilename = $tid ."--".$outputfile. ".m2p";67 $outputfilename = $tid ."--".$outputfile.$extension; 51 68 $mp4newstylefilename = "-" . $tid ."--".$outputfile; 52 69 }else{ 53 $outputfilename = $tid ."-".$countno."-".$outputfile. ".m2p";70 $outputfilename = $tid ."-".$countno."-".$outputfile.$extension; 54 71 $mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile; 55 72 } 56 73 } 74 75 if ($usedigital == 1){ 76 #デジタルなら 77 &writelog("recwrap RECSTART DIGITAL $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio"); 78 #録画 79 $starttime = (`date +%s`); 80 $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio"); 81 $oserr = $oserr / 256; 82 83 if ($oserr == 1){ 84 &writelog("recwrap ABORT recfile exist. [$outputfilename] $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno"); 85 exit; 86 }elsif ($oserr == 2){ 87 &writelog("recwrap ERR 2:friio busy;retry."); 88 &continuousrecordingcheck;#もうすぐ終わる番組をkill 89 sleep(2); 90 $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid N $outputfilename $tid $countno friio"); 91 $oserr = $oserr / 256; 92 if ($oserr == 2){ 93 &writelog("recwrap ERR 2:friio busy;Giving up digital recording."); 94 } 95 }elsif ($oserr == 3){ 96 &writelog("recwrap ABORT:ERR 3"); 97 exit ; 98 } 99 }else{ 57 100 #リモコン操作 58 101 # $haveirdaunit = 1;リモコンつないでるかどうか確認 … … 71 114 exit; 72 115 }#end if 73 74 &writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid"); 116 # アナログ録画 117 &writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch"); 118 75 119 #録画 76 120 #system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfile $bitrate $tid $countno"); … … 83 127 exit; 84 128 } 129 130 }#endif #デジタル優先フラグ 131 85 132 #デバイスビジーで即死してないか検出 86 133 $now = (`date +%s`); 87 134 if ($now < $starttime + 100){ #録画プロセス起動してから100秒以内に戻ってきてたら 135 $retrycounter == 0; 88 136 while($now < $starttime + 100){ 137 if($retrycounter >= 5){ 138 &writelog("recwrap WARNING Giving up recording."); 139 last; 140 } 89 141 &writelog("recwrap retry recording $now $starttime"); 142 #アナログ録画 90 143 $starttime = (`date +%s`); 144 if($outputfilename =~ /.m2t$/){ 145 $outputfilename =~ s/.m2t$/.m2p/; 146 } 91 147 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno"); 92 148 $now = (`date +%s`); … … 96 152 exit; 97 153 }# if 154 $retrycounter++; 98 155 }# while 99 156 } # if 100 157 101 102 158 &writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); 103 159 104 #DB初期化105 my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d",106 $DBDriv,$DBName,$DBHost,$DBPort);107 $dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;;108 160 109 161 # m2pファイル名をPIDレコードに書き込み 110 $DBQuery = "UPDATE foltia_subtitle SET 111 m2pfilename = '$outputfilename' 112 WHERE pid = '$pid' "; 162 $DBQuery = "UPDATE foltia_subtitle SET m2pfilename = '$outputfilename' WHERE pid = '$pid' "; 113 163 $sth = $dbh->prepare($DBQuery); 114 164 $sth->execute(); 115 &writelog("recwrap UPDATEDB $DBQuery"); 165 &writelog("recwrap DEBUG UPDATEDB $DBQuery"); 166 &changefilestatus($pid,$FILESTATUSRECEND); 116 167 117 168 # m2pファイル名をPIDレコードに書き込み 118 $DBQuery = "insert into 169 $DBQuery = "insert into foltia_m2pfiles values ('$outputfilename')"; 119 170 $sth = $dbh->prepare($DBQuery); 120 171 $sth->execute(); 121 &writelog("recwrap UPDATEDB$DBQuery");172 &writelog("recwrap DEBUG UPDATEDB $DBQuery"); 122 173 123 174 # Starlight breaker向けキャプチャ画像作成 124 175 if (-e "$toolpath/perl/captureimagemaker.pl"){ 125 176 &writelog("recwrap Call captureimagemaker $outputfilename"); 177 &changefilestatus($pid,$FILESTATUSCAPTURE); 126 178 system ("$toolpath/perl/captureimagemaker.pl $outputfilename"); 127 } 128 129 130 131 # PSP ------------------------------------------------------ 132 #PSPトラコン必要かどうか 133 $DBQuery = "SELECT psp,aspect,title FROM foltia_program WHERE tid = '$tid' "; 179 &changefilestatus($pid,$FILESTATUSCAPEND); 180 } 181 182 183 184 # MPEG4 ------------------------------------------------------ 185 #MPEG4トラコン必要かどうか 186 $DBQuery = "SELECT psp,aspect,title FROM foltia_program WHERE tid = '$tid' "; 134 187 $sth = $dbh->prepare($DBQuery); 135 188 $sth->execute(); 136 189 @psptrcn= $sth->fetchrow_array; 137 if ($psptrcn[0] == 1 ){#トラコン番組 138 139 140 #PSPムービーディレクトリがアルかどうか 190 if ($psptrcn[0] == 1 ){#トラコン番組 191 &writelog("recwrap Launch ipodtranscode.pl"); 192 exec ("$toolpath/perl/ipodtranscode.pl"); 193 exit; 194 # 195 # ここから下は旧エンコード#2008/12/23 196 # 新エンコードはDBを見て未完了MPEG2を順次トラコン処理、 197 # 分散エンコードもきっとラクチンに対応可能 198 # 新エンコードではXviD/M4VスタイルとPSPファイル名対応を廃止 199 200 &changefilestatus($pid,80); 201 #MPEG4ムービーディレクトリがあるかどうか 141 202 142 203 #TIDが100以上の3桁の場合はそのまま 143 204 my $pspfilnamehd = ""; 144 205 145 $pspfilnamehd = $tid; 206 $pspfilnamehd = $tid; 207 &makemp4dir($tid); 146 208 $pspdirname = "$tid.localized/"; 147 209 $pspdirname = $recfolderpath."/".$pspdirname; 148 210 149 211 #なければ作る 150 unless (-e $pspdirname ){151 system("$toolpath/perl/mklocalizeddir.pl $tid");152 #&writelog("recwrap mkdir $pspdirname");153 }212 #unless (-e $pspdirname ){ 213 # system("$toolpath/perl/mklocalizeddir.pl $tid"); 214 # #&writelog("recwrap mkdir $pspdirname"); 215 #} 154 216 $pspdirname = "$tid.localized/mp4/"; 155 217 $pspdirname = $recfolderpath."/".$pspdirname; 156 218 #なければ作る 157 unless (-e $pspdirname ){158 mkdir $pspdirname ,0777;159 #&writelog("recwrap mkdir $pspdirname");160 }219 #unless (-e $pspdirname ){ 220 # mkdir $pspdirname ,0777; 221 # #&writelog("recwrap mkdir $pspdirname"); 222 #} 161 223 162 224 #ファイル名決定 … … 350 412 351 413 # MP4ファイル名をPIDレコードに書き込み 352 $DBQuery = "UPDATE foltia_subtitle SET 353 PSPfilename = '$mp4filename' 354 WHERE pid = '$pid' "; 414 $DBQuery = "UPDATE foltia_subtitle SET PSPfilename = '$mp4filename' WHERE pid = '$pid' "; 355 415 $sth = $dbh->prepare($DBQuery); 356 416 $sth->execute(); … … 358 418 359 419 # MP4ファイル名をfoltia_mp4files挿入 360 $DBQuery = "insert intofoltia_mp4files values ('$tid','$mp4filename') ";420 $DBQuery = "insert into foltia_mp4files values ('$tid','$mp4filename') "; 361 421 $sth = $dbh->prepare($DBQuery); 362 422 $sth->execute(); 363 423 &writelog("recwrap UPDATEmp4DB $DBQuery"); 364 424 425 &changefilestatus($pid,200); 365 426 }#PSPトラコンあり 366 427 367 368 369 428 sub continuousrecordingcheck(){ 429 my $now = `date +%s --date "2 min "`; 430 &writelog("recwrap DEBUG continuousrecordingcheck() now $now"); 431 my @processes =`ps ax | grep recfriio`; 432 433 my $psline = ""; 434 my @processline = ""; 435 my $pid = ""; 436 my @pid; 437 my $sth; 438 foreach (@processes){ 439 if (/friiodetect/) { 440 if (/^.[0-9]*\s/){ 441 push(@pid, $&); 442 }#if 443 }#if 444 }#foreach 445 446 if (@pid > 0){ 447 my @filenameparts; 448 my $tid = ""; 449 my $startdate = ""; 450 my $starttime = ""; 451 my $startdatetime = ""; 452 my @recfile; 453 my $endtime = ""; 454 my $endtimeepoch = ""; 455 foreach $pid (@pid){ 456 #print "DEBUG PID $pid\n"; 457 &writelog("recwrap DEBUG continuousrecordingcheck() PID $pid"); 458 459 my @lsofoutput = `/usr/sbin/lsof -p $pid`; 460 my $filename = ""; 461 #print "recfolferpath $recfolderpath\n"; 462 foreach (@lsofoutput){ 463 if (/m2t/){ 464 @processline = split(/\s+/,$_); 465 $filename = $processline[8]; 466 #print "DEBUG $_ \n"; 467 #print "DEBUG $processline[0]/$processline[1]/$processline[2]/$processline[3]/$processline[4]/$processline[5]/$processline[6]/$processline[7]/$processline[8] \n"; 468 $filename =~ s/$recfolderpath\///; 469 #print "DEBUG FILENAME $filename\n"; 470 &writelog("recwrap DEBUG continuousrecordingcheck() FILENAME $filename"); 471 # 1520-9-20081201-0230.m2t 472 @filenameparts = split(/-/,$filename); 473 $tid = $filenameparts[0]; 474 $startdate = $filenameparts[2]; 475 $starttime = $filenameparts[3]; 476 $startdatetime = $filenameparts[2].$filenameparts[3]; 477 #DBから録画中番組のデータ探す 478 $DBQuery = " 479 SELECT foltia_subtitle.tid,foltia_subtitle.countno,foltia_subtitle.subtitle,foltia_subtitle.startdatetime ,foltia_subtitle.enddatetime ,foltia_subtitle.lengthmin ,foltia_tvrecord.bitrate , foltia_subtitle.startoffset , foltia_subtitle.pid ,foltia_tvrecord.digital 480 FROM foltia_subtitle ,foltia_tvrecord 481 WHERE 482 foltia_tvrecord.tid = foltia_subtitle.tid AND 483 foltia_tvrecord.tid = $tid AND 484 foltia_subtitle.startdatetime = $startdatetime AND 485 foltia_tvrecord.digital = 1"; 486 &writelog("recwrap DEBUG continuousrecordingcheck() $DBQuery"); 487 $sth = $dbh->prepare($DBQuery); 488 &writelog("recwrap DEBUG continuousrecordingcheck() prepare"); 489 $sth->execute(); 490 &writelog("recwrap DEBUG continuousrecordingcheck() execute"); 491 @recfile = $sth->fetchrow_array; 492 &writelog("recwrap DEBUG continuousrecordingcheck() @recfile $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] $recfile[6] $recfile[7] $recfile[8] $recfile[9] "); 493 #終了時刻 494 $endtime = $recfile[4]; 495 $endtimeepoch = &foldate2epoch($endtime); 496 &writelog("recwrap DEBUG continuousrecordingcheck() $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] endtimeepoch $endtimeepoch"); 497 if ($endtimeepoch < $now){#まもなく終わる番組なら 498 #kill 499 system("kill $pid"); 500 &writelog("recwrap recording process killed $pid/$endtimeepoch/$now"); 501 } 502 }#endif m2t 503 }#foreach lsofoutput 504 }#foreach 505 }else{ 506 #print "DEBUG fecfriio NO PID\n"; 507 &writelog("recwrap No recording process killed."); 508 } 509 }#endsub 510 511 512