1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
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 |
|
---|
49 |
$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;; |
---|
50 |
|
---|
51 |
|
---|
52 |
if ($usedigital == 1){ |
---|
53 |
$extension = ".m2t"; |
---|
54 |
}else{ |
---|
55 |
$extension = ".m2p"; |
---|
56 |
} |
---|
57 |
if ($recch == -2 ){ |
---|
58 |
$extension = ".aac"; |
---|
59 |
} |
---|
60 |
|
---|
61 |
$outputfile = strftime("%Y%m%d-%H%M", localtime(time + 60)); |
---|
62 |
chomp($outputfile); |
---|
63 |
|
---|
64 |
if ($tid == 0){ |
---|
65 |
$outputfilename = "0--".$outputfile."-".$recch.$extension; |
---|
66 |
$mp4newstylefilename = "-0--".$outputfile."-".$recch; |
---|
67 |
}else{ |
---|
68 |
if ($countno == 0){ |
---|
69 |
$outputfilename = $tid ."--".$outputfile.$extension; |
---|
70 |
$mp4newstylefilename = "-" . $tid ."--".$outputfile; |
---|
71 |
}else{ |
---|
72 |
$outputfilename = $tid ."-".$countno."-".$outputfile.$extension; |
---|
73 |
$mp4newstylefilename = "-" . $tid ."-".$countno."-".$outputfile; |
---|
74 |
} |
---|
75 |
} |
---|
76 |
|
---|
77 |
if ($recch == -2 ){ |
---|
78 |
|
---|
79 |
$sth = $dbh->prepare($stmt{'recwrap.8'}); |
---|
80 |
$sth->execute($stationid); |
---|
81 |
@stationline= $sth->fetchrow_array; |
---|
82 |
$radikostationname = $stationline[3]; |
---|
83 |
|
---|
84 |
$oserr = system("$toolpath/perl/digitalradiorecording.pl $radikostationname $reclength $outputfilename"); |
---|
85 |
$oserr = $oserr / 256; |
---|
86 |
&writelog("recwrap DEBUG radiko rec finished. $oserr"); |
---|
87 |
|
---|
88 |
|
---|
89 |
$sth = $dbh->prepare($stmt{'recwrap.1'}); |
---|
90 |
$sth->execute($outputfilename, $pid); |
---|
91 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}"); |
---|
92 |
&changefilestatus($pid,$FILESTATUSTRANSCODEMP4BOX); |
---|
93 |
|
---|
94 |
|
---|
95 |
$sth = $dbh->prepare($stmt{'recwrap.2'}); |
---|
96 |
$sth->execute($outputfilename); |
---|
97 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}"); |
---|
98 |
|
---|
99 |
|
---|
100 |
}else{ |
---|
101 |
|
---|
102 |
if ($usedigital == 1){ |
---|
103 |
|
---|
104 |
&writelog("recwrap RECSTART DIGITAL $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio"); |
---|
105 |
|
---|
106 |
$starttime = time(); |
---|
107 |
$oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno friio"); |
---|
108 |
$oserr = $oserr / 256; |
---|
109 |
|
---|
110 |
if ($oserr == 1){ |
---|
111 |
&writelog("recwrap ABORT recfile exist. [$outputfilename] $digitalstationband $digitalch $reclength $stationid 0 $outputfilename $tid $countno"); |
---|
112 |
exit; |
---|
113 |
}elsif ($oserr == 2){ |
---|
114 |
&writelog("recwrap ERR 2:friio busy;retry."); |
---|
115 |
&continuousrecordingcheck; |
---|
116 |
sleep(2); |
---|
117 |
$oserr = system("$toolpath/perl/digitaltvrecording.pl $digitalstationband $digitalch $reclength $stationid N $outputfilename $tid $countno friio"); |
---|
118 |
$oserr = $oserr / 256; |
---|
119 |
if ($oserr == 2){ |
---|
120 |
&writelog("recwrap ERR 2:friio busy;Giving up digital recording."); |
---|
121 |
} |
---|
122 |
}elsif ($oserr == 3){ |
---|
123 |
&writelog("recwrap ABORT:ERR 3"); |
---|
124 |
exit ; |
---|
125 |
} |
---|
126 |
}else{ |
---|
127 |
|
---|
128 |
|
---|
129 |
if ($haveirdaunit == 1){ |
---|
130 |
|
---|
131 |
if ($recch == 0){ |
---|
132 |
|
---|
133 |
&writelog("recwrap Call Change STB CH :$pid"); |
---|
134 |
system ("$toolpath/perl/changestbch.pl $pid &"); |
---|
135 |
} |
---|
136 |
} |
---|
137 |
|
---|
138 |
if($recch == -10){ |
---|
139 |
|
---|
140 |
&writelog("recwrap Not recordable channel;exit:PID $pid"); |
---|
141 |
exit; |
---|
142 |
} |
---|
143 |
|
---|
144 |
&writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch"); |
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 |
$starttime = time(); |
---|
149 |
|
---|
150 |
$oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength 0 $outputfilename $bitrate $tid $countno"); |
---|
151 |
$oserr = $oserr / 256; |
---|
152 |
if ($oserr == 1){ |
---|
153 |
&writelog("recwrap ABORT recfile exist. [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
154 |
exit; |
---|
155 |
} |
---|
156 |
|
---|
157 |
} |
---|
158 |
|
---|
159 |
|
---|
160 |
$now = time(); |
---|
161 |
if ($now < $starttime + 100){ |
---|
162 |
$retrycounter = 0; |
---|
163 |
while($now < $starttime + 100){ |
---|
164 |
if($retrycounter >= 5){ |
---|
165 |
&writelog("recwrap WARNING Giving up recording."); |
---|
166 |
last; |
---|
167 |
} |
---|
168 |
&writelog("recwrap retry recording $now $starttime"); |
---|
169 |
|
---|
170 |
$starttime = time(); |
---|
171 |
if($outputfilename =~ /.m2t$/){ |
---|
172 |
$outputfilename =~ s/.m2t$/.m2p/; |
---|
173 |
} |
---|
174 |
$oserr = system("$toolpath/perl/tvrecording.pl $recch $reclength N $outputfilename $bitrate $tid $countno"); |
---|
175 |
$now = time(); |
---|
176 |
$oserr = $oserr / 256; |
---|
177 |
if ($oserr == 1){ |
---|
178 |
&writelog("recwrap ABORT recfile exist. in resume process.[$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
179 |
exit; |
---|
180 |
} |
---|
181 |
$retrycounter++; |
---|
182 |
} |
---|
183 |
} |
---|
184 |
|
---|
185 |
&writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
186 |
|
---|
187 |
|
---|
188 |
|
---|
189 |
$sth = $dbh->prepare($stmt{'recwrap.1'}); |
---|
190 |
$sth->execute($outputfilename, $pid); |
---|
191 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.1'}"); |
---|
192 |
&changefilestatus($pid,$FILESTATUSRECEND); |
---|
193 |
|
---|
194 |
|
---|
195 |
$sth = $dbh->prepare($stmt{'recwrap.2'}); |
---|
196 |
$sth->execute($outputfilename); |
---|
197 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}"); |
---|
198 |
|
---|
199 |
|
---|
200 |
if (-e "$toolpath/perl/captureimagemaker.pl"){ |
---|
201 |
&writelog("recwrap Call captureimagemaker $outputfilename"); |
---|
202 |
&changefilestatus($pid,$FILESTATUSCAPTURE); |
---|
203 |
system ("$toolpath/perl/captureimagemaker.pl $outputfilename"); |
---|
204 |
&changefilestatus($pid,$FILESTATUSCAPEND); |
---|
205 |
} |
---|
206 |
} |
---|
207 |
|
---|
208 |
|
---|
209 |
|
---|
210 |
$sth = $dbh->prepare($stmt{'recwrap.3'}); |
---|
211 |
$sth->execute($tid); |
---|
212 |
@psptrcn= $sth->fetchrow_array; |
---|
213 |
if ($psptrcn[0] == 1 ){ |
---|
214 |
&writelog("recwrap Launch ipodtranscode.pl"); |
---|
215 |
exec ("$toolpath/perl/ipodtranscode.pl"); |
---|
216 |
exit; |
---|
217 |
} |
---|
218 |
|
---|
219 |
sub continuousrecordingcheck(){ |
---|
220 |
my $now = time() + 60 * 2; |
---|
221 |
&writelog("recwrap DEBUG continuousrecordingcheck() now $now"); |
---|
222 |
my @processes =`ps ax | grep recfriio`; |
---|
223 |
|
---|
224 |
my $psline = ""; |
---|
225 |
my @processline = ""; |
---|
226 |
my $pid = ""; |
---|
227 |
my @pid; |
---|
228 |
my $sth; |
---|
229 |
foreach (@processes){ |
---|
230 |
if (/friiodetect/) { |
---|
231 |
if (/^.[0-9]*\s/){ |
---|
232 |
push(@pid, $&); |
---|
233 |
} |
---|
234 |
} |
---|
235 |
} |
---|
236 |
|
---|
237 |
if (@pid > 0){ |
---|
238 |
my @filenameparts; |
---|
239 |
my $tid = ""; |
---|
240 |
my $startdate = ""; |
---|
241 |
my $starttime = ""; |
---|
242 |
my $startdatetime = ""; |
---|
243 |
my @recfile; |
---|
244 |
my $endtime = ""; |
---|
245 |
my $endtimeepoch = ""; |
---|
246 |
foreach $pid (@pid){ |
---|
247 |
|
---|
248 |
&writelog("recwrap DEBUG continuousrecordingcheck() PID $pid"); |
---|
249 |
|
---|
250 |
my @lsofoutput = `/usr/sbin/lsof -p $pid`; |
---|
251 |
my $filename = ""; |
---|
252 |
|
---|
253 |
foreach (@lsofoutput){ |
---|
254 |
if (/m2t/){ |
---|
255 |
@processline = split(/\s+/,$_); |
---|
256 |
$filename = $processline[8]; |
---|
257 |
$filename =~ s/$recfolderpath\///; |
---|
258 |
&writelog("recwrap DEBUG continuousrecordingcheck() FILENAME $filename"); |
---|
259 |
|
---|
260 |
@filenameparts = split(/-/,$filename); |
---|
261 |
$tid = $filenameparts[0]; |
---|
262 |
$startdate = $filenameparts[2]; |
---|
263 |
$starttime = $filenameparts[3]; |
---|
264 |
@filenameparts = split(/\./,$starttime); |
---|
265 |
$startdatetime = $startdate.$filenameparts[0]; |
---|
266 |
|
---|
267 |
&writelog("recwrap DEBUG continuousrecordingcheck() $stmt{'recwrap.7'}"); |
---|
268 |
$sth = $dbh->prepare($stmt{'recwrap.7'}); |
---|
269 |
&writelog("recwrap DEBUG continuousrecordingcheck() prepare"); |
---|
270 |
$sth->execute($tid, $startdatetime); |
---|
271 |
&writelog("recwrap DEBUG continuousrecordingcheck() execute"); |
---|
272 |
@recfile = $sth->fetchrow_array; |
---|
273 |
&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] "); |
---|
274 |
|
---|
275 |
$endtime = $recfile[4]; |
---|
276 |
$endtimeepoch = &foldate2epoch($endtime); |
---|
277 |
&writelog("recwrap DEBUG continuousrecordingcheck() $recfile[0] $recfile[1] $recfile[2] $recfile[3] $recfile[4] $recfile[5] endtimeepoch $endtimeepoch"); |
---|
278 |
if ($endtimeepoch < $now){ |
---|
279 |
|
---|
280 |
system("kill $pid"); |
---|
281 |
&writelog("recwrap recording process killed $pid/$endtimeepoch/$now"); |
---|
282 |
} |
---|
283 |
} |
---|
284 |
} |
---|
285 |
} |
---|
286 |
}else{ |
---|
287 |
|
---|
288 |
&writelog("recwrap No recording process killed."); |
---|
289 |
} |
---|
290 |
} |
---|
291 |
|
---|
292 |
|
---|
293 |
|
---|