root/trunk/install/perl/recwrap.pl

リビジョン 131, 9.1 kB (コミッタ: sorshi, コミット時期: 13 年 前)

デジタル録画時に重複録画数がエンコーダ数を超えたときの対策を強化

  • svn:executable 属性の設定値:
Line 
1 #!/usr/bin/perl
2 #usage recwrap.pl ch length(sec) [bitrate(5)] [TID] [NO] [PID] [stationid] [digitalflag] [digitalband] [digitalch]
3 #
4 # Anime recording system foltia
5 # http://www.dcc-jpl.com/soft/foltia/
6 #
7 #
8 #レコーディングラッパ
9 #atから呼び出され、tvrecordingを呼び出し録画
10 #そのあとMPEG4トラコンを呼び出す
11 #
12 # DCC-JPL Japan/foltia project
13 #
14
15 use DBI;
16 use DBD::Pg;
17 use DBD::SQLite;
18 use Schedule::At;
19 use Time::Local;
20 use Jcode;
21
22 $path = $0;
23 $path =~ s/recwrap.pl$//i;
24 if ($path ne "./"){
25 push( @INC, "$path");
26 }
27
28 require "foltialib.pl";
29 #引き数がアルか?
30 $recch = $ARGV[0] ;
31 if ($recch eq "" ){
32         #引き数なしで実行されたら、終了
33         print "usage recwrap.pl  ch length(sec) [bitrate(5)] [TID] [NO] [PID]\n";
34         exit;
35 }
36
37 $recch = $ARGV[0] ;
38 $reclength = $ARGV[1] ;
39 $bitrate  = $ARGV[2] ;
40 $tid  = $ARGV[3] ;
41 $countno  = $ARGV[4] ;
42 $pid = $ARGV[5] ;
43 $stationid = $ARGV[6] ;
44 $usedigital = $ARGV[7] ;
45 $digitalstationband = $ARGV[8] ;
46 $digitalch= $ARGV[9] ;
47
48 #DB初期化
49 $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
50
51
52 if ($usedigital == 1){
53         $extension = ".m2t";#TSの拡張子
54 }else{
55         $extension = ".m2p";#MPEG2の拡張子
56 }
57 if ($recch == -2 ){ #ラジオ局
58         $extension = ".aac";#MPEG2の拡張子
59 }
60
61 $outputfile = strftime("%Y%m%d-%H%M", localtime(time + 60));
62 chomp($outputfile);
63
64 if ($tid == 0){
65         if ($usedigital == 1){
66                 $outputfilename = "0--".$outputfile."-".$digitalch.$extension;
67                 $mp4newstylefilename = "-0--".$outputfile."-".$digitalch;
68         }else{
69                 $outputfilename = "0--".$outputfile."-".$recch.$extension;
70                 $mp4newstylefilename = "-0--".$outputfile."-".$recch;
71         }
72 }else{
73         if ($countno == 0){
74                 $outputfilename = $tid ."--".$outputfile.$extension;
75                 $mp4newstylefilename = "-" . $tid ."--".$outputfile;
76         }else{
77                 $outputfilename = $tid ."-".$countno."-".$outputfile.$extension;
78                 $mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile;
79         }
80 }
81
82 if ($recch == -2 ){ #ラジオ局
83 # stationIDからradiko識別子を取得
84 $sth = $dbh->prepare($stmt{'recwrap.8'});
85 $sth->execute($stationid);
86  @stationline= $sth->fetchrow_array;
87 $radikostationname = $stationline[3];
88
89 $oserr = system("$toolpath/perl/digitalradiorecording.pl $radikostationname $reclength $outputfilename");
90 $oserr = $oserr / 256;
91 &writelog("recwrap DEBUG radiko rec finished. $oserr");
92
93 # aacファイル名をfoltia_subtitlePIDレコードに書き込み
94 $sth = $dbh->prepare($stmt{'recwrap.1'});
95 $sth->execute($outputfilename, $pid);
96 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}");
97 &changefilestatus($pid,$FILESTATUSTRANSCODEMP4BOX);
98
99 # aacファイル名をfoltia_m2pfilesPIDレコードに書き込み
100 $sth = $dbh->prepare($stmt{'recwrap.2'});
101 $sth->execute($outputfilename);
102 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}");
103
104
105 }else{#非ラジオ局なら
106
107 if ($usedigital == 1){
108 #デジタルなら
109 &writelog("recwrap RECSTART DIGITAL $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio");
110 #録画
111     $starttime = time();
112 $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio");
113 $oserr = $oserr / 256;
114
115 if ($oserr == 1){
116         &writelog("recwrap ABORT recfile exist. [$outputfilename] $digitalstationband $digitalch $reclength $stationid 0  $outputfilename $tid $countno");
117         exit;
118 }elsif ($oserr == 2){
119         &writelog("recwrap ERR 2:Device busy;retry.");
120         &continuousrecordingcheck;#もうすぐ終わる番組をkill
121         sleep(2);
122         $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid N $outputfilename $tid $countno friio");
123         $oserr = $oserr / 256;
124         if ($oserr == 2){
125         &writelog("recwrap ERR 2:Device busy;Giving up digital recording.");
126                 if ($recunits > 0 ){
127                 }else{
128                         exit;
129                 }
130         }
131 }elsif ($oserr == 3){
132 &writelog("recwrap ABORT:ERR 3");
133 exit ;
134 }
135 }else{ # NOT $usedigital == 1
136         if ($recunits > 0 ){
137         #リモコン操作
138         # $haveirdaunit = 1;リモコンつないでるかどうか確認
139         if ($haveirdaunit == 1){
140         # 録画チャンネルが0なら
141                 if ($recch == 0){
142         # &つけて非同期でchangestbch.pl呼び出し
143                 &writelog("recwrap Call Change STB CH :$pid");
144                 system ("$toolpath/perl/changestbch.pl $pid &");
145                 }#end if
146         }#end if
147         
148         if($recch == -10){
149         #非受信局なら
150                 &writelog("recwrap Not recordable channel;exit:PID $pid");
151                 exit;
152                 }#end if
153         # アナログ録画
154         &writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch");
155        
156         #録画
157         #system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfile $bitrate $tid $countno");
158                 $starttime = time();
159        
160         $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno");
161         $oserr = $oserr / 256;
162         if ($oserr == 1){
163                 &writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
164                 exit;
165         }
166 #デバイスビジーで即死してないか検出
167 $now = time();
168         if ($now < $starttime + 100){ #録画プロセス起動してから100秒以内に戻ってきてたら
169     $retrycounter = 0;
170                 while($now < $starttime + 100){
171                         if($retrycounter >= 5){
172                                 &writelog("recwrap WARNING  Giving up recording.");
173                                 last;
174                         }
175                 &writelog("recwrap retry recording $now $starttime");
176                 #アナログ録画
177         $starttime = time();
178 if($outputfilename =~ /.m2t$/){
179         $outputfilename =~ s/.m2t$/.m2p/;
180 }
181 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno");
182         $now = time();
183 $oserr = $oserr / 256;
184                         if ($oserr == 1){
185                                 &writelog("recwrap ABORT recfile exist. in resume process.[$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
186                                 exit;
187                         }# if
188                 $retrycounter++;
189                 }# while
190         } # if
191
192         &writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
193
194         }#end if $recunits > 0
195 }#endif #デジタル優先フラグ
196
197
198 # m2pファイル名をPIDレコードに書き込み
199 $sth = $dbh->prepare($stmt{'recwrap.1'});
200 $sth->execute($outputfilename, $pid);
201 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}");
202 &changefilestatus($pid,$FILESTATUSRECEND);
203
204 # m2pファイル名をPIDレコードに書き込み
205 $sth = $dbh->prepare($stmt{'recwrap.2'});
206 $sth->execute($outputfilename);
207 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}");
208
209 # Starlight breaker向けキャプチャ画像作成
210 if (-e "$toolpath/perl/captureimagemaker.pl"){
211         &writelog("recwrap Call captureimagemaker $outputfilename");
212 &changefilestatus($pid,$FILESTATUSCAPTURE);
213         system ("$toolpath/perl/captureimagemaker.pl $outputfilename");
214 &changefilestatus($pid,$FILESTATUSCAPEND);
215 }
216 }#非ラジオ局
217
218 # MPEG4 ------------------------------------------------------
219 #MPEG4トラコン必要かどうか
220 $sth = $dbh->prepare($stmt{'recwrap.3'});
221 $sth->execute($tid);
222  @psptrcn= $sth->fetchrow_array;
223 if ($psptrcn[0]  == 1 ){#トラコン番組
224         &writelog("recwrap Launch ipodtranscode.pl");
225         exec ("$toolpath/perl/ipodtranscode.pl");
226         exit;
227 }#PSPトラコンあり
228
229 sub continuousrecordingcheck(){
230     my $now = time() + 60 * 2;
231 &writelog("recwrap DEBUG continuousrecordingcheck() now $now");
232 my @processes =`ps ax | grep -e recpt1 -e recfriio`; #foltiaBBS もうすぐ終了する番組のプロセスをkill 投稿日 2010年08月05日03時19分33秒 投稿者 Nis
233
234 my $psline = "";
235 my @processline = "";
236 my $pid = "";
237 my @pid;
238 my $sth;
239 foreach (@processes){
240         if (/recpt1|friiodetect/) {
241                 if (/^.[0-9]*\s/){
242                         push(@pid, $&);
243                 }#if
244         }#if
245 }#foreach
246
247 if (@pid > 0){
248 my @filenameparts;
249 my $tid = "";
250 my $startdate = "";
251 my $starttime = "";
252 my $startdatetime = "";
253 my @recfile;
254 my $endtime = "";
255 my $endtimeepoch = "";
256 foreach $pid (@pid){
257 #print "DEBUG  PID $pid\n";
258 &writelog("recwrap DEBUG continuousrecordingcheck() PID $pid");
259
260         my @lsofoutput = `/usr/sbin/lsof -p $pid`;
261         my $filename = "";
262         #print "recfolferpath $recfolderpath\n";
263         foreach (@lsofoutput){
264                 if (/m2t/){
265                 @processline = split(/\s+/,$_);
266                 $filename = $processline[8];
267                 $filename =~ s/$recfolderpath\///;
268                 &writelog("recwrap DEBUG continuousrecordingcheck()  FILENAME $filename");
269                 # 1520-9-20081201-0230.m2t
270                 @filenameparts = split(/-/,$filename);
271                 $tid = $filenameparts[0];
272                 $startdate = $filenameparts[2];
273                 $starttime = $filenameparts[3];
274                 @filenameparts = split(/\./,$starttime);
275                 $startdatetime = $startdate.$filenameparts[0];
276                 #DBから録画中番組のデータ探す
277                     &writelog("recwrap DEBUG continuousrecordingcheck() $stmt{'recwrap.7'}");
278                     $sth = $dbh->prepare($stmt{'recwrap.7'});
279         &writelog("recwrap DEBUG continuousrecordingcheck() prepare");
280                     $sth->execute($tid, $startdatetime);
281         &writelog("recwrap DEBUG continuousrecordingcheck() execute");
282         @recfile = $sth->fetchrow_array;
283         &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] ");
284         #終了時刻
285         $endtime = $recfile[4];
286         $endtimeepoch = &foldate2epoch($endtime);
287         &writelog("recwrap DEBUG continuousrecordingcheck() $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] endtimeepoch $endtimeepoch");
288         if ($endtimeepoch < $now){#まもなく終わる番組なら
289                 #kill
290                 system("kill $pid");
291                 &writelog("recwrap recording process killed $pid/$endtimeepoch/$now");
292         }else{
293                 &writelog("recwrap No processes killed: $endtimeepoch/$now");
294         }
295                 }#endif m2t
296         }#foreach lsofoutput
297 }#foreach
298 }else{
299 #print "DEBUG fecfriio NO PID\n";
300 &writelog("recwrap No recording process killed.");
301 }
302 }#endsub
303
304
305
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed