root/trunk/install/perl/recwrap.pl

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

recpt1を使う環境でBS/CSが録れていなかった問題を解消。
EPG録画の時のファイル名をデジタル録画の場合は録画チャンネルに変更。

  • 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:friio 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:friio busy;Giving up digital recording.");
126         }
127 }elsif ($oserr == 3){
128 &writelog("recwrap ABORT:ERR 3");
129 exit ;
130 }
131 }else{ # NOT $usedigital == 1
132 #リモコン操作
133 # $haveirdaunit = 1;リモコンつないでるかどうか確認
134 if ($haveirdaunit == 1){
135 # 録画チャンネルが0なら
136         if ($recch == 0){
137 # &つけて非同期でchangestbch.pl呼び出し
138         &writelog("recwrap Call Change STB CH :$pid");
139         system ("$toolpath/perl/changestbch.pl $pid &");
140         }#end if
141 }#end if
142
143 if($recch == -10){
144 #非受信局なら
145         &writelog("recwrap Not recordable channel;exit:PID $pid");
146         exit;
147         }#end if
148 # アナログ録画
149 &writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch");
150
151 #録画
152 #system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfile $bitrate $tid $countno");
153     $starttime = time();
154
155 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno");
156 $oserr = $oserr / 256;
157 if ($oserr == 1){
158         &writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
159         exit;
160 }
161
162 }#endif #デジタル優先フラグ
163
164 #デバイスビジーで即死してないか検出
165 $now = time();
166         if ($now < $starttime + 100){ #録画プロセス起動してから100秒以内に戻ってきてたら
167     $retrycounter = 0;
168                 while($now < $starttime + 100){
169                         if($retrycounter >= 5){
170                                 &writelog("recwrap WARNING  Giving up recording.");
171                                 last;
172                         }
173                 &writelog("recwrap retry recording $now $starttime");
174                 #アナログ録画
175         $starttime = time();
176 if($outputfilename =~ /.m2t$/){
177         $outputfilename =~ s/.m2t$/.m2p/;
178 }
179 $oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno");
180         $now = time();
181 $oserr = $oserr / 256;
182                         if ($oserr == 1){
183                                 &writelog("recwrap ABORT recfile exist. in resume process.[$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
184                                 exit;
185                         }# if
186                 $retrycounter++;
187                 }# while
188         } # if
189
190         &writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid");
191
192
193 # m2pファイル名をPIDレコードに書き込み
194 $sth = $dbh->prepare($stmt{'recwrap.1'});
195 $sth->execute($outputfilename, $pid);
196 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}");
197 &changefilestatus($pid,$FILESTATUSRECEND);
198
199 # m2pファイル名をPIDレコードに書き込み
200 $sth = $dbh->prepare($stmt{'recwrap.2'});
201 $sth->execute($outputfilename);
202 &writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}");
203
204 # Starlight breaker向けキャプチャ画像作成
205 if (-e "$toolpath/perl/captureimagemaker.pl"){
206         &writelog("recwrap Call captureimagemaker $outputfilename");
207 &changefilestatus($pid,$FILESTATUSCAPTURE);
208         system ("$toolpath/perl/captureimagemaker.pl $outputfilename");
209 &changefilestatus($pid,$FILESTATUSCAPEND);
210 }
211 }#非ラジオ局
212
213 # MPEG4 ------------------------------------------------------
214 #MPEG4トラコン必要かどうか
215 $sth = $dbh->prepare($stmt{'recwrap.3'});
216 $sth->execute($tid);
217  @psptrcn= $sth->fetchrow_array;
218 if ($psptrcn[0]  == 1 ){#トラコン番組
219         &writelog("recwrap Launch ipodtranscode.pl");
220         exec ("$toolpath/perl/ipodtranscode.pl");
221         exit;
222 }#PSPトラコンあり
223
224 sub continuousrecordingcheck(){
225     my $now = time() + 60 * 2;
226 &writelog("recwrap DEBUG continuousrecordingcheck() now $now");
227 my @processes =`ps ax | grep -e recpt1 -e recfriio`; #foltiaBBS もうすぐ終了する番組のプロセスをkill 投稿日 2010年08月05日03時19分33秒 投稿者 Nis
228
229 my $psline = "";
230 my @processline = "";
231 my $pid = "";
232 my @pid;
233 my $sth;
234 foreach (@processes){
235         if (/recpt1|friiodetect/) {
236                 if (/^.[0-9]*\s/){
237                         push(@pid, $&);
238                 }#if
239         }#if
240 }#foreach
241
242 if (@pid > 0){
243 my @filenameparts;
244 my $tid = "";
245 my $startdate = "";
246 my $starttime = "";
247 my $startdatetime = "";
248 my @recfile;
249 my $endtime = "";
250 my $endtimeepoch = "";
251 foreach $pid (@pid){
252 #print "DEBUG  PID $pid\n";
253 &writelog("recwrap DEBUG continuousrecordingcheck() PID $pid");
254
255         my @lsofoutput = `/usr/sbin/lsof -p $pid`;
256         my $filename = "";
257         #print "recfolferpath $recfolderpath\n";
258         foreach (@lsofoutput){
259                 if (/m2t/){
260                 @processline = split(/\s+/,$_);
261                 $filename = $processline[8];
262                 $filename =~ s/$recfolderpath\///;
263                 &writelog("recwrap DEBUG continuousrecordingcheck()  FILENAME $filename");
264                 # 1520-9-20081201-0230.m2t
265                 @filenameparts = split(/-/,$filename);
266                 $tid = $filenameparts[0];
267                 $startdate = $filenameparts[2];
268                 $starttime = $filenameparts[3];
269                 @filenameparts = split(/\./,$starttime);
270                 $startdatetime = $startdate.$filenameparts[0];
271                 #DBから録画中番組のデータ探す
272                     &writelog("recwrap DEBUG continuousrecordingcheck() $stmt{'recwrap.7'}");
273                     $sth = $dbh->prepare($stmt{'recwrap.7'});
274         &writelog("recwrap DEBUG continuousrecordingcheck() prepare");
275                     $sth->execute($tid, $startdatetime);
276         &writelog("recwrap DEBUG continuousrecordingcheck() execute");
277         @recfile = $sth->fetchrow_array;
278         &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] ");
279         #終了時刻
280         $endtime = $recfile[4];
281         $endtimeepoch = &foldate2epoch($endtime);
282         &writelog("recwrap DEBUG continuousrecordingcheck() $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] endtimeepoch $endtimeepoch");
283         if ($endtimeepoch < $now){#まもなく終わる番組なら
284                 #kill
285                 system("kill $pid");
286                 &writelog("recwrap recording process killed $pid/$endtimeepoch/$now");
287         }
288                 }#endif m2t
289         }#foreach lsofoutput
290 }#foreach
291 }else{
292 #print "DEBUG fecfriio NO PID\n";
293 &writelog("recwrap No recording process killed.");
294 }
295 }#endsub
296
297
298
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed