root/trunk/install/perl/digitaltvrecording.pl

リビジョン 94, 14.7 kB (コミッタ: sorshi, コミット時期: 14 年 前)

SQLite採用

  • svn:executable 属性の設定値: *
Line 
1 #!/usr/bin/perl
2 #
3 # Anime recording system foltia
4 # http://www.dcc-jpl.com/soft/foltia/
5 #
6 #digitaltvrecording.pl
7 # friioをはじめとするデジタル録画プログラムを呼びだす録画モジュール。
8 #
9 #usage digitaltvrecording.pl bandtype ch length(sec) [stationid] [sleeptype] [filename] [TID] [NO] [unittype]
10 #引数
11 #bandtype : 0:地デジ 1:BSデジタル 2:CSデジタル
12 #ch :録画チャンネル (地デジはそのまま渡す、BS/CSデジタルは基本的にチャンネル BS1/BS2など同じ数時に)
13 #length(sec) :録画秒数 [必須項目]
14 #[stationid] :foltia stationid
15 #[sleeptype] :0かN Nならスリープなしで録画
16 #[filename] :出力ファイル名
17 #[TID] :しょぼかるタイトルID
18 #[NO] :その番組の放送話数
19 #[unittype] :friioかfriioBSかユニデンチューナかHDUSかなど(未使用)
20 #
21 # DCC-JPL Japan/foltia project
22 #
23 #
24
25 $path = $0;
26 $path =~ s/digitaltvrecording.pl$//i;
27 if ($path ne "./"){
28 push( @INC, "$path");
29 }
30
31 #tvConfig.pl -------------------------------
32 $extendrecendsec = 10;                                                  #recording end second.
33 #$startupsleeptime = 52;                                        #process wait(MAX60sec)
34 $startupsleeptime = 27;                                 #process wait(MAX60sec)
35 #-------------------------------
36
37 require 'foltialib.pl';
38
39  &writelog("digitaltvrecording: DEBUG $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $ARGV[8]");
40
41
42 #準備
43 &prepare;
44 #もし録画が走ってたら、止める
45 #$reclengthsec = &chkrecprocess();
46 #&setbitrate;
47 #&chkextinput;
48 #$reclengthsec = $reclengthsec + $extendrecendsec ;
49
50 &calldigitalrecorder;
51
52 &writelog("digitaldigitaltvrecording:RECEND:$bandtype $recch $lengthsec $stationid $sleeptype $filename $tid $countno $unittype
53 ");
54
55 # -- これ以下サブルーチン ----------------------------
56
57
58 sub prepare{
59
60 #引数エラー処理
61 $bandtype = $ARGV[0] ;
62 $recch = $ARGV[1] ;
63 $lengthsec = $ARGV[2] ;
64 $stationid = $ARGV[3] ;
65 $sleeptype = $ARGV[4] ;
66 $filename = $ARGV[5] ;
67 $tid = $ARGV[6] ;
68 $countno = $ARGV[7] ;
69 $unittype = $ARGV[8] ;
70
71 if (($bandtype eq "" )|| ($recch eq "")|| ($lengthsec eq "")){
72         print "usage digitaltvrecording.pl bandtype ch length(sec) [stationid] [sleeptype] [filename] [TID] [NO] [unittype]\n";
73         exit;
74 }
75
76 my $intval = $recch % 10; # 0〜9 sec
77 my $startupsleep = $startupsleeptime - $intval; #  18〜27 sec
78 $reclengthsec = $lengthsec + (60 - $startupsleep) + 1; #
79
80 if ( $sleeptype ne "N"){
81         &writelog("digitaltvrecording: DEBUG SLEEP $startupsleeptime:$intval:$startupsleep:$reclengthsec");
82         sleep ( $startupsleep);
83         #2008/08/12_06:39:00 digitaltvrecording: DEBUG SLEEP 17:23:-6:367
84 }else{
85         &writelog("digitaltvrecording: DEBUG RAPID START");
86 }
87 ## recfriio このへんどうなってるの?
88 #if ($recunits > 1){
89 #my $deviceno = $recunits - 1;#3枚差しのとき/dev/video2から使う
90 #       $recdevice = "/dev/video$deviceno";
91 #       $recch = $ARGV[0] ;
92 #}else{
93 ##1枚差し
94 #       $recdevice = "/dev/video0";
95 #       $recch = $ARGV[0] ;
96 #}
97
98 $outputpath = "$recfolderpath"."/";
99
100 if ($countno eq "0"){
101         $outputfile = $outputpath.$tid."--";
102 }else{
103         $outputfile = $outputpath.$tid."-".$countno."-";
104 }
105 #2番目以降のクリップでファイル名指定があったら
106         if ($filename  ne ""){
107
108                 $outputfile = $filename ;
109                 $outputfile = &filenameinjectioncheck($outputfile);
110                 $outputfilewithoutpath = $outputfile ;
111                 $outputfile = $outputpath.$outputfile ;
112                 &writelog("digitaltvrecording: DEBUG FILENAME ne null \$outputfile $outputfile ");
113         }else{
114         $outputfile .= strftime("%Y%m%d-%H%M", localtime(time + 60));
115                 chomp($outputfile);
116                 $outputfile .= ".m2t";
117                 $outputfilewithoutpath = $outputfile ;
118                 &writelog("digitaltvrecording:  DEBUG FILENAME is null \$outputfile $outputfile ");
119         }
120
121
122 @wday_name = ("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
123 $sleepcounter = 0;
124 $cmd="";
125
126 #二重録りなど既に同名ファイルがあったら中断
127 if ( -e "$outputfile" ){
128         if ( -s "$outputfile" ){
129         &writelog("digitaltvrecording :ABORT :recfile $outputfile exist.");
130         exit 1;
131         }
132 }
133
134 }#end prepare
135
136 sub calldigitalrecorderOld{
137 #
138 #
139 #いまんところ白friioと黒friioのみ
140 #
141 #
142 my $oserr = 0;
143
144 if ($bandtype == 0){
145 # 地デジ friio
146 # b25,recfriioがあるか確認
147         if ((-e "$toolpath/perl/tool/b25") && (-e "$toolpath/perl/tool/recfriio")){
148         my $friiofifo = "$outputpath"."fifo-friio-"."$outputfilewithoutpath";
149         my $b25fifo = "$outputpath"."fifo-b25-"."$outputfilewithoutpath";
150        
151                 if ((-e "$friiofifo") || (-e "$b25fifo")){
152                         &writelog("digitaltvrecording :ABORT :fifo is exist. It may be overwrite recording.");
153                         exit 1;
154                 }else{
155                 system ("mkfifo $friiofifo $b25fifo");
156                 # mkfifo fifo-friio-9999-01-20080810.m2t  fifo-b25-9999-01-20080810.m2t
157                 &writelog("digitaltvrecording DEBUG mkfifo $friiofifo $b25fifo: $?.");
158         # /home/foltia/perl/recfriio 27 30 ./fifo-friio-9999-01-20080810.m2t & /home/foltia/perl/b25 ./fifo-friio-9999-01-20080810.m2t  ./fifo-b25-9999-01-20080810.m2t & dd if=./fifo-b25-9999-01-20080810.m2t  of=/home/foltia/php/tv/9999-01-20080810.m2t bs=1M skip=10
159 #               system("$toolpath/perl/tool/recfriio $recch $reclengthsec $friiofifo & ");
160 #               system("$toolpath/perl/tool/b25 $friiofifo $b25fifo &");
161 #               system("dd if=$b25fifo  of=$outputfile bs=1M skip=10");
162                 &writelog("digitaltvrecording DEBUG $toolpath/perl/tool/recfriio $recch $reclengthsec $friiofifo & dd if=$friiofifo  of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile: $?.");
163                 system("dd if=$friiofifo  of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile &");
164                 $oserr = system("$toolpath/perl/tool/recfriio $recch $reclengthsec $friiofifo  ");
165                 $oserr = $oserr >> 8;
166                 system ("rm -rf $friiofifo $b25fifo");
167                 &writelog("digitaltvrecording DEBUG rm -rf $friiofifo $b25fifo: $?.");
168                         if ($oserr > 0){
169                         #               print "RECFRIIO RETURNS:$oserr\n";
170                         &writelog("digitaltvrecording :ERROR :friio is BUSY.");
171                         # kill dd
172                         $ddpid = `ps a | grep $friiofifo | grep -v grep`;
173                         @ddpid = split(/ /,$ddpid);
174                         $ddpid = $ddpid[0];
175                         chomp($ddpid);
176                         $killcmd = "kill ".$ddpid;
177                         system($killcmd);
178                         &writelog("digitaltvrecording :DEBUG dd killed:$killcmd");
179
180                         #kill b25
181                         $b25pid = `ps a | grep $b25fifo |   grep -v grep`;
182                         @b25pid = split(/ /,$b25pid);
183                         $b25pid = $b25pid[0];
184                         chomp($b25pid);
185                         $killcmd = "kill ".$b25pid;
186                         system($killcmd);
187                         &writelog("digitaltvrecording :DEBUG b25 killed:$killcmd");
188
189                         system ("rm -rf $outputfile");
190
191                         exit 2;
192                         }
193                 }
194         }else{ # エラー b25とrecfriioがありません
195                 &writelog("digitaltvrecording :ERROR :recfriio or b25 not found. You must install $toolpath/perl/tool/b25 and $toolpath/perl/tool/recfriio.");
196         exit 1;
197         }
198
199 }elsif($bandtype == 1){
200
201 # BS/CS friio
202 # b25,recfriioがあるか確認
203         if ((-e "$toolpath/perl/tool/b25") && (-e "$toolpath/perl/tool/recfriiobs")){
204         my $friiofifo = "$outputpath"."fifo-friioBS-"."$outputfilewithoutpath";
205         my $b25fifo = "$outputpath"."fifo-b25-"."$outputfilewithoutpath";
206        
207                 if ((-e "$friiofifo") || (-e "$b25fifo")){
208                         &writelog("digitaltvrecording :ABORT :fifo is exist. It may be overwrite recording.");
209                         exit 1;
210                 }else{
211                 system ("mkfifo $friiofifo $b25fifo");
212                 &writelog("digitaltvrecording DEBUG mkfifo $friiofifo $b25fifo: $?.");
213                 #recfriiobs用チャンネルリマップ
214                 if ($recch == 101) {
215                         $bssplitflag = $recch;
216                         $recch = 22;#22 : NHK BS1/BS2
217                 }elsif($recch == 102){
218                         $bssplitflag = $recch;
219                         $recch = 22;#22 : NHK BS1/BS2
220                 }elsif($recch == 103){
221                         $recch = 23;#23 : NHK hi 
222                 }elsif($recch == 141){
223                         $recch = 20;# 20 : BS-NTV 
224                 }elsif($recch == 151){
225                         $recch = 13;#13 : BS-Asahi
226                 }elsif($recch == 161){
227                         $recch = 14;#14 : BS-i 
228                 }elsif($recch == 171){
229                         $recch = 16;#16 : BS-Japan
230                 }elsif($recch == 181){
231                         $recch = 21;#21 : BS-Fuji
232                 }elsif($recch == 191){
233                         $recch = 15;#15 : WOWOW
234                 }elsif($recch == 192){
235                         $recch = 15;#15 : WOWOW
236                 }elsif($recch == 193){
237                         $recch = 15;#15 : WOWOW
238                 }elsif($recch == 211){
239                         $recch = 17;#17 : BS11 
240                 }else{
241                         $recch = 19;#19 : TwellV
242                 }
243                 &writelog("digitaltvrecording DEBUG $toolpath/perl/tool/recfriiobs $recch $reclengthsec $friiofifo & dd if=$friiofifo  of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile : $?.");
244                 system("dd if=$friiofifo  of=$b25fifo bs=1M skip=10 & $toolpath/perl/tool/b25 $b25fifo $outputfile  &");
245                 $oserr = system("$toolpath/perl/tool/recfriiobs $recch $reclengthsec $friiofifo  ");
246                 $oserr = $oserr >> 8;
247
248                 system ("rm -rf $friiofifo $b25fifo");
249                 &writelog("digitaltvrecording DEBUG rm -rf $friiofifo $b25fifo: $?.");
250                         if ($oserr > 0){
251                         #               print "RECFRIIO RETURNS:$oserr\n";
252                         &writelog("digitaltvrecording :ERROR :friioBS is BUSY.");
253                         # kill dd
254                         $ddpid = `ps a | grep $friiofifo | grep -v grep`;
255                         @ddpid = split(/ /,$ddpid);
256                         $ddpid = $ddpid[0];
257                         chomp($ddpid);
258                         $killcmd = "kill ".$ddpid;
259                         system($killcmd);
260                         &writelog("digitaltvrecording :DEBUG dd killed:$killcmd");
261
262                         #kill b25
263                         $b25pid = `ps a | grep $b25fifo |   grep -v grep`;
264                         @b25pid = split(/ /,$b25pid);
265                         $b25pid = $b25pid[0];
266                         chomp($b25pid);
267                         $killcmd = "kill ".$b25pid;
268                         system($killcmd);
269                         &writelog("digitaltvrecording :DEBUG b25 killed:$killcmd");
270
271                         system ("rm -rf $outputfile");
272
273                         exit 2;
274                         }
275                
276                 #BS1/BS2などのスプリットを
277                 if ($bssplitflag == 101){
278                         if (-e "$toolpath/perl/tool/TsSplitter.exe"){
279                         # BS1           
280                         system("wine $toolpath/perl/tool/TsSplitter.exe  -EIT -ECM  -EMM  -OUT \"$outputpath\" -HD  -SD2 -SD3 -1SEG  -LOGFILE -WAIT2 $outputfile");
281                         $splitfile = $outputfile;
282                         $splitfile =~ s/\.m2t$/_SD1.m2t/;
283                                 if (-e "$splitfile"){
284                                 system("rm -rf $outputfile ; mv $splitfile $outputfile");
285                                 &writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?.");
286                                 }else{
287                                 &writelog("digitaltvrecording ERROR File not found:$splitfile.");
288                                 }
289                         }else{
290                         &writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found.");
291                         }
292                 }elsif($bssplitflag == 102){
293                         if (-e "$toolpath/perl/tool/TsSplitter.exe"){
294                         # BS2           
295                         system("wine $toolpath/perl/tool/TsSplitter.exe  -EIT -ECM  -EMM  -OUT \"$outputpath\" -HD  -SD1 -SD3 -1SEG  -LOGFILE -WAIT2 $outputfile");
296                         $splitfile = $outputfile;
297                         $splitfile =~ s/\.m2t$/_SD2.m2t/;
298                                 if (-e "$splitfile"){
299                                 system("rm -rf $outputfile ; mv $splitfile $outputfile");
300                                 &writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?.");
301                                 }else{
302                                 &writelog("digitaltvrecording ERROR File not found:$splitfile.");
303                                 }
304                         }else{
305                         &writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found.");
306                         }
307                 }else{
308                         &writelog("digitaltvrecording DEBUG not split TS.$bssplitflag");
309                 }# endif #BS1/BS2などのスプリットを
310                 
311                 }
312         }else{ # エラー b25とrecfriioがありません
313                 &writelog("digitaltvrecording :ERROR :recfriiobs or b25 not found. You must install $toolpath/perl/tool/b25 and $toolpath/perl/tool/recfriiobs.");
314         exit 1;
315         }
316 }elsif($bandtype == 2){
317 }else{
318         &writelog("digitaltvrecording :ERROR :Unsupported and type (digital CS).");
319         exit 3;
320 }
321
322
323
324 }#end calldigitalrecorderOld
325 #------------------------------------------------------------------------------------
326 #
327 sub calldigitalrecorder{
328 #
329 #白friioと黒friio、PT1対応
330 #2008/10/23 recfriio4仕様に変更
331 #
332 my $oserr = 0;
333 my $originalrecch = $recch;
334 my $errorflag = 0;
335 if ($bandtype == 0){
336 # 地デジ friio
337 }elsif($bandtype == 1){
338 # BS/CS friio
339                 #recfriiobs用チャンネルリマップ
340                 if ($recch == 101) {
341                         $bssplitflag = $recch;
342                         $recch = "b10";#22 : NHK BS1/BS2
343                 }elsif($recch == 102){
344                         $bssplitflag = $recch;
345                         $recch = "b10";#22 : NHK BS1/BS2
346                 }elsif($recch == 103){
347                         $recch = "b11";#23 : NHK hi 
348                 }elsif($recch == 141){
349                         $recch = "b8";# 20 : BS-NTV 
350                 }elsif($recch == 151){
351                         $recch = "b1";#13 : BS-Asahi
352                 }elsif($recch == 161){
353                         $recch = "b2";#14 : BS-i 
354                 }elsif($recch == 171){
355                         $recch = "b4";#16 : BS-Japan
356                 }elsif($recch == 181){
357                         $recch = "b9";#21 : BS-Fuji
358                 }elsif($recch == 191){
359                         $recch = "b3";#15 : WOWOW
360                 }elsif($recch == 192){
361                         $recch = "b3";#15 : WOWOW
362                 }elsif($recch == 193){
363                         $recch = "b3";#15 : WOWOW
364                 }elsif($recch == 211){
365                         $recch = "b5";#17 : BS11 
366                 }else{
367                         $recch = "b7";#19 : TwellV
368                 }
369                 # b6 # Star Channel
370
371 }elsif($bandtype == 2){
372 # 110度CSよくわかんない
373 }else{
374         &writelog("digitaltvrecording :ERROR :Unsupported and type (digital CS).");
375         exit 3;
376 }
377
378 # PT1
379 # b25,recpt1があるか確認
380         if  (-e "$toolpath/perl/tool/recpt1"){
381                 &writelog("digitaltvrecording DEBUG recpt1 --b25  $originalrecch $reclengthsec $outputfile  ");
382                 $oserr = system("$toolpath/perl/tool/recpt1 --b25  $originalrecch $reclengthsec $outputfile  ");
383                 $oserr = $oserr >> 8;
384                         if ($oserr > 0){
385                         &writelog("digitaltvrecording :ERROR :PT1 is BUSY.$oserr");
386                         $errorflag = 2;
387                         }
388         }else{ # エラー recpt1がありません
389                 &writelog("digitaltvrecording :ERROR :recpt1  not found. You must install $toolpath/tool/b25 and $toolpath/tool/recpt1.");
390         $errorflag = 1;
391         }
392 # friio
393 if ($errorflag >= 1 ){
394 # b25,recfriioがあるか確認
395         if  (-e "$toolpath/perl/tool/recfriio"){
396        
397         if (! -e "$toolpath/perl/tool/friiodetect"){
398                 system("touch $toolpath/perl/tool/friiodetect");
399                 system("chown foltia:foltia $toolpath/perl/tool/friiodetect");
400                 system("chmod 775 $toolpath/perl/tool/friiodetect");
401                 &writelog("digitaltvrecording :DEBUG make lock file.$toolpath/perl/tool/friiodetect");
402         }
403                 &writelog("digitaltvrecording DEBUG recfriio --b25 --lockfile $toolpath/perl/tool/friiodetect $recch $reclengthsec $outputfile  ");
404                 $oserr = system("$toolpath/perl/tool/recfriio --b25 --lockfile $toolpath/perl/tool/friiodetect $recch $reclengthsec $outputfile  ");
405                 $oserr = $oserr >> 8;
406                         if ($oserr > 0){
407                         &writelog("digitaltvrecording :ERROR :friio is BUSY.$oserr");
408                         exit 2;
409                         }
410         }else{ # エラー recfriioがありません
411                 &writelog("digitaltvrecording :ERROR :recfriio  not found. You must install $toolpath/perl/tool/b25 and $toolpath/perl/tool/recfriio.");
412         exit 1;
413         }
414 }#end if errorflag
415
416 #BS1/BS2などのスプリットを
417 if ($bssplitflag == 101){
418         if (-e "$toolpath/perl/tool/TsSplitter.exe"){
419         # BS1           
420         system("wine $toolpath/perl/tool/TsSplitter.exe  -EIT -ECM  -EMM  -OUT \"$outputpath\" -HD  -SD2 -SD3 -1SEG  -LOGFILE -WAIT2 $outputfile");
421         $splitfile = $outputfile;
422         $splitfile =~ s/\.m2t$/_SD1.m2t/;
423                 if (-e "$splitfile"){
424                 system("rm -rf $outputfile ; mv $splitfile $outputfile");
425                 &writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?.");
426                 }else{
427                 &writelog("digitaltvrecording ERROR File not found:$splitfile.");
428                 }
429         }else{
430         &writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found.");
431         }
432 }elsif($bssplitflag == 102){
433         if (-e "$toolpath/perl/tool/TsSplitter.exe"){
434         # BS2           
435         system("wine $toolpath/perl/tool/TsSplitter.exe  -EIT -ECM  -EMM  -OUT \"$outputpath\" -HD  -SD1 -SD3 -1SEG  -LOGFILE -WAIT2 $outputfile");
436         $splitfile = $outputfile;
437         $splitfile =~ s/\.m2t$/_SD2.m2t/;
438                 if (-e "$splitfile"){
439                 system("rm -rf $outputfile ; mv $splitfile $outputfile");
440                 &writelog("digitaltvrecording DEBUG rm -rf $outputfile ; mv $splitfile $outputfile: $?.");
441                 }else{
442                 &writelog("digitaltvrecording ERROR File not found:$splitfile.");
443                 }
444         }else{
445         &writelog("digitaltvrecording ERROR $toolpath/perl/tool/TsSplitter.exe not found.");
446         }
447 }else{
448         &writelog("digitaltvrecording DEBUG not split TS.$bssplitflag");
449 }# endif #BS1/BS2などのスプリットを
450
451 }#end calldigitalrecorder
452
453
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed