root/trunk/install/perl/recwrap.pl

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

SQLite採用

  • 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
58 $outputfile = strftime("%Y%m%d-%H%M", localtime(time + 60));
59 chomp($outputfile);
60
61 if ($tid == 0){
62                 $outputfilename = "0--".$outputfile."-".$recch.$extension;
63                 $mp4newstylefilename = "-0--".$outputfile."-".$recch;
64 }else{
65         if ($countno == 0){
66                 $outputfilename = $tid ."--".$outputfile.$extension;
67                 $mp4newstylefilename = "-" . $tid ."--".$outputfile;
68         }else{
69                 $outputfilename = $tid ."-".$countno."-".$outputfile.$extension;
70                 $mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile;
71         }
72 }
73
74 if ($usedigital == 1){
75 #デジタルなら
76 &writelog("recwrap RECSTART DIGITAL $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio");
77 #録画
78     $starttime = time();
79 $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio");
80 $oserr = $oserr / 256;
81
82 if ($oserr == 1){
83         &writelog("recwrap ABORT recfile exist. [$outputfilename] $digitalstationband $digitalch $reclength $stationid 0  $outputfilename $tid $countno");
84         exit;
85 }elsif ($oserr == 2){
86         &writelog("recwrap ERR 2:friio busy;retry.");
87         &continuousrecordingcheck;#もうすぐ終わる番組をkill
88         sleep(2);
89         $oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid N $outputfilename $tid $countno friio");
90         $oserr = $oserr / 256;
91         if ($oserr == 2){
92         &writelog("recwrap ERR 2:friio busy;Giving up digital recording.");
93         }
94 }elsif ($oserr == 3){
95 &writelog("recwrap ABORT:ERR 3");
96 exit ;
97 }
98 }else{
99 #リモコン操作
100 # $haveirdaunit = 1;リモコンつないでるかどうか確認
101 if ($haveirdaunit == 1){
102 # 録画チャンネルが0なら
103         if ($recch == 0){
104 # &つけて非同期でchangestbch.pl呼び出し
105         &writelog("recwrap Call Change STB CH :$pid");
106         system ("$toolpath/perl/changestbch.pl $pid &");
107         }#end if
108 }#end if
109
110 if($recch == -10){
111 #非受信局なら
112         &writelog("recwrap Not recordable channel;exit:PID $pid");
113         exit;
114         }#end if
115 # アナログ録画
116 &writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch");
117
118 #録画
119 #system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfile $bitrate $tid $countno");
120     $starttime = time();
121
122 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno");
123 $oserr = $oserr / 256;
124 if ($oserr == 1){
125         &writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
126         exit;
127 }
128
129 }#endif #デジタル優先フラグ
130
131 #デバイスビジーで即死してないか検出
132 $now = time();
133         if ($now < $starttime + 100){ #録画プロセス起動してから100秒以内に戻ってきてたら
134     $retrycounter = 0;
135                 while($now < $starttime + 100){
136                         if($retrycounter >= 5){
137                                 &writelog("recwrap WARNING  Giving up recording.");
138                                 last;
139                         }
140                 &writelog("recwrap retry recording $now $starttime");
141                 #アナログ録画
142         $starttime = time();
143 if($outputfilename =~ /.m2t$/){
144         $outputfilename =~ s/.m2t$/.m2p/;
145 }
146 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno");
147         $now = time();
148 $oserr = $oserr / 256;
149                         if ($oserr == 1){
150                                 &writelog("recwrap ABORT recfile exist. in resume process.[$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
151                                 exit;
152                         }# if
153                 $retrycounter++;
154                 }# while
155         } # if
156
157         &writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
158
159
160 # m2pファイル名をPIDレコードに書き込み
161 $sth = $dbh->prepare($stmt{'recwrap.1'});
162 $sth->execute($outputfilename, $pid);
163 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}");
164 &changefilestatus($pid,$FILESTATUSRECEND);
165
166 # m2pファイル名をPIDレコードに書き込み
167 $sth = $dbh->prepare($stmt{'recwrap.2'});
168 $sth->execute($outputfilename);
169 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}");
170
171 # Starlight breaker向けキャプチャ画像作成
172 if (-e "$toolpath/perl/captureimagemaker.pl"){
173         &writelog("recwrap Call captureimagemaker $outputfilename");
174 &changefilestatus($pid,$FILESTATUSCAPTURE);
175         system ("$toolpath/perl/captureimagemaker.pl $outputfilename");
176 &changefilestatus($pid,$FILESTATUSCAPEND);
177 }
178
179
180 # MPEG4 ------------------------------------------------------
181 #MPEG4トラコン必要かどうか
182 $sth = $dbh->prepare($stmt{'recwrap.3'});
183 $sth->execute($tid);
184  @psptrcn= $sth->fetchrow_array;
185 if ($psptrcn[0]  == 1 ){#トラコン番組
186 &writelog("recwrap Launch ipodtranscode.pl");
187 exec ("$toolpath/perl/ipodtranscode.pl");
188 exit;
189 }#PSPトラコンあり
190
191 sub continuousrecordingcheck(){
192     my $now = time() + 60 * 2;
193 &writelog("recwrap DEBUG continuousrecordingcheck() now $now");
194 my @processes =`ps ax | grep recfriio`;
195
196 my $psline = "";
197 my @processline = "";
198 my $pid = "";
199 my @pid;
200 my $sth;
201 foreach (@processes){
202         if (/friiodetect/) {
203                 if (/^.[0-9]*\s/){
204                         push(@pid, $&);
205                 }#if
206         }#if
207 }#foreach
208
209 if (@pid > 0){
210 my @filenameparts;
211 my $tid = "";
212 my $startdate = "";
213 my $starttime = "";
214 my $startdatetime = "";
215 my @recfile;
216 my $endtime = "";
217 my $endtimeepoch = "";
218 foreach $pid (@pid){
219 #print "DEBUG  PID $pid\n";
220 &writelog("recwrap DEBUG continuousrecordingcheck() PID $pid");
221
222         my @lsofoutput = `/usr/sbin/lsof -p $pid`;
223         my $filename = "";
224         #print "recfolferpath $recfolderpath\n";
225         foreach (@lsofoutput){
226                 if (/m2t/){
227                 @processline = split(/\s+/,$_);
228                 $filename = $processline[8];
229                 $filename =~ s/$recfolderpath\///;
230                 &writelog("recwrap DEBUG continuousrecordingcheck()  FILENAME $filename");
231                 # 1520-9-20081201-0230.m2t
232                 @filenameparts = split(/-/,$filename);
233                 $tid = $filenameparts[0];
234                 $startdate = $filenameparts[2];
235                 $starttime = $filenameparts[3];
236                 @filenameparts = split(/\./,$starttime);
237                 $startdatetime = $startdate.$filenameparts[0];
238                 #DBから録画中番組のデータ探す
239                     &writelog("recwrap DEBUG continuousrecordingcheck() $stmt{'recwrap.7'}");
240                     $sth = $dbh->prepare($stmt{'recwrap.7'});
241         &writelog("recwrap DEBUG continuousrecordingcheck() prepare");
242                     $sth->execute($tid, $startdatetime);
243         &writelog("recwrap DEBUG continuousrecordingcheck() execute");
244         @recfile = $sth->fetchrow_array;
245         &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] ");
246         #終了時刻
247         $endtime = $recfile[4];
248         $endtimeepoch = &foldate2epoch($endtime);
249         &writelog("recwrap DEBUG continuousrecordingcheck() $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] endtimeepoch $endtimeepoch");
250         if ($endtimeepoch < $now){#まもなく終わる番組なら
251                 #kill
252                 system("kill $pid");
253                 &writelog("recwrap recording process killed $pid/$endtimeepoch/$now");
254         }
255                 }#endif m2t
256         }#foreach lsofoutput
257 }#foreach
258 }else{
259 #print "DEBUG fecfriio NO PID\n";
260 &writelog("recwrap No recording process killed.");
261 }
262 }#endsub
263
264
265
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed