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 |
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 |
|
---|
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 |
|
---|
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 |
|
---|
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; |
---|
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{ |
---|
132 |
|
---|
133 |
|
---|
134 |
if ($haveirdaunit == 1){ |
---|
135 |
|
---|
136 |
if ($recch == 0){ |
---|
137 |
|
---|
138 |
&writelog("recwrap Call Change STB CH :$pid"); |
---|
139 |
system ("$toolpath/perl/changestbch.pl $pid &"); |
---|
140 |
} |
---|
141 |
} |
---|
142 |
|
---|
143 |
if($recch == -10){ |
---|
144 |
|
---|
145 |
&writelog("recwrap Not recordable channel;exit:PID $pid"); |
---|
146 |
exit; |
---|
147 |
} |
---|
148 |
|
---|
149 |
&writelog("recwrap RECSTART $recch $reclength 0 $outputfilename $bitrate $tid $countno $pid $usedigital $digitalstationband $digitalch"); |
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
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 |
} |
---|
163 |
|
---|
164 |
|
---|
165 |
$now = time(); |
---|
166 |
if ($now < $starttime + 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 |
} |
---|
186 |
$retrycounter++; |
---|
187 |
} |
---|
188 |
} |
---|
189 |
|
---|
190 |
&writelog("recwrap RECEND [$outputfilename] $recch $reclength 0 0 $bitrate $tid $countno $pid"); |
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
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 |
|
---|
200 |
$sth = $dbh->prepare($stmt{'recwrap.2'}); |
---|
201 |
$sth->execute($outputfilename); |
---|
202 |
&writelog("recwrap DEBUG UPDATEDB $stmt{'recwrap.2'}"); |
---|
203 |
|
---|
204 |
|
---|
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 |
|
---|
214 |
|
---|
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 |
} |
---|
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`; |
---|
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 |
} |
---|
239 |
} |
---|
240 |
} |
---|
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 |
|
---|
253 |
&writelog("recwrap DEBUG continuousrecordingcheck() PID $pid"); |
---|
254 |
|
---|
255 |
my @lsofoutput = `/usr/sbin/lsof -p $pid`; |
---|
256 |
my $filename = ""; |
---|
257 |
|
---|
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 |
|
---|
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 |
|
---|
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 |
|
---|
285 |
system("kill $pid"); |
---|
286 |
&writelog("recwrap recording process killed $pid/$endtimeepoch/$now"); |
---|
287 |
} |
---|
288 |
} |
---|
289 |
} |
---|
290 |
} |
---|
291 |
}else{ |
---|
292 |
|
---|
293 |
&writelog("recwrap No recording process killed."); |
---|
294 |
} |
---|
295 |
} |
---|
296 |
|
---|
297 |
|
---|
298 |
|
---|