1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
$path = $0; |
---|
5 |
$path =~ s/foltialib.pl$//i; |
---|
6 |
if ($path ne "./"){ |
---|
7 |
push( @INC, "$path"); |
---|
8 |
} |
---|
9 |
require "foltia_conf1.pl"; |
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
use DBI; |
---|
14 |
use DBD::Pg; |
---|
15 |
use DBD::SQLite; |
---|
16 |
use POSIX qw(strftime); |
---|
17 |
|
---|
18 |
$DSN=$main::DSN; |
---|
19 |
$DBUser=$main::DBUser; |
---|
20 |
$DBPass=""; |
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
$FILESTATUSRESERVINGLONG = 10; |
---|
25 |
$FILESTATUSRESERVINGSHORT = 20; |
---|
26 |
$FILESTATUSRECORDING = 30; |
---|
27 |
$FILESTATUSRECTSSPLITTING = 40; |
---|
28 |
$FILESTATUSRECEND = 50; |
---|
29 |
$FILESTATUSWAITINGCAPTURE = 55; |
---|
30 |
$FILESTATUSCAPTURE = 60; |
---|
31 |
$FILESTATUSCAPEND = 70; |
---|
32 |
$FILESTATUSTHMCREATE = 72; |
---|
33 |
$FILESTATUSWAITINGTRANSCODE = 80; |
---|
34 |
$FILESTATUSTRANSCODETSSPLITTING = 90; |
---|
35 |
$FILESTATUSTRANSCODEFFMPEG = 100; |
---|
36 |
$FILESTATUSTRANSCODEWAVE = 110; |
---|
37 |
$FILESTATUSTRANSCODEAAC = 120; |
---|
38 |
$FILESTATUSTRANSCODEMP4BOX = 130; |
---|
39 |
$FILESTATUSTRANSCODEATOM = 140; |
---|
40 |
$FILESTATUSTRANSCODECOMPLETE = 150; |
---|
41 |
$FILESTATUSALLCOMPLETE = 200; |
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
sub writelog{ |
---|
46 |
my $messages = $_[0]; |
---|
47 |
my $timestump = strftime("%Y/%m/%d_%H:%M:%S", localtime); |
---|
48 |
chomp($timestump); |
---|
49 |
if ($debugmode == 1){ |
---|
50 |
open (DEBUGLOG , ">>$toolpath/debuglog.txt") || die "Cant write log file.$! \n "; |
---|
51 |
}else{ |
---|
52 |
open (DEBUGLOG , '>-') || die "Cant write log file.$! \n "; |
---|
53 |
} |
---|
54 |
$messages =~ s/\n//gio; |
---|
55 |
print DEBUGLOG "$timestump $messages\n"; |
---|
56 |
close (DEBUGLOG); |
---|
57 |
} |
---|
58 |
|
---|
59 |
sub syobocaldate2foltiadate{ |
---|
60 |
|
---|
61 |
my $foltiadate = $_[0] ; |
---|
62 |
|
---|
63 |
$foltiadate = substr($foltiadate,0,12); |
---|
64 |
|
---|
65 |
return $foltiadate; |
---|
66 |
|
---|
67 |
} |
---|
68 |
|
---|
69 |
|
---|
70 |
sub foldate2epoch{ |
---|
71 |
my $foltiadate = $_[0] ; |
---|
72 |
|
---|
73 |
|
---|
74 |
my $eyear = substr($foltiadate , 0, 4); |
---|
75 |
my $emon = substr($foltiadate, 4, 2); |
---|
76 |
$emon--; |
---|
77 |
my $emday = substr($foltiadate , 6, 2); |
---|
78 |
my $q_start_time_hour = substr($foltiadate , 8, 2); |
---|
79 |
my $q_start_time_min = substr($foltiadate , 10, 2); |
---|
80 |
|
---|
81 |
my $epoch = timelocal(0,$q_start_time_min,$q_start_time_hour, $emday, $emon , $eyear); |
---|
82 |
|
---|
83 |
return $epoch; |
---|
84 |
} |
---|
85 |
|
---|
86 |
|
---|
87 |
sub epoch2foldate{ |
---|
88 |
my $s; |
---|
89 |
my $mi; |
---|
90 |
my $h; |
---|
91 |
my $d; |
---|
92 |
my $mo; |
---|
93 |
my $y; |
---|
94 |
my $w; |
---|
95 |
|
---|
96 |
($s, $mi, $h, $d, $mo, $y, $w) = localtime($_[0]); |
---|
97 |
$mo++; $y += 1900; |
---|
98 |
|
---|
99 |
my $foltiadate; |
---|
100 |
$mo = sprintf("%02d",$mo); |
---|
101 |
$d = sprintf("%02d",$d); |
---|
102 |
|
---|
103 |
$h = sprintf("%02d",$h); |
---|
104 |
$mi = sprintf("%02d",$mi); |
---|
105 |
$foltiadate = "$y$mo$d$h$mi"; |
---|
106 |
|
---|
107 |
return $foltiadate; |
---|
108 |
} |
---|
109 |
|
---|
110 |
sub calclength{ |
---|
111 |
|
---|
112 |
|
---|
113 |
my $sttime = $_[0] ; |
---|
114 |
my $edtime = $_[1] ; |
---|
115 |
my $length = -1; |
---|
116 |
$sttime = &foldate2epoch($sttime); |
---|
117 |
$edtime = &foldate2epoch($edtime); |
---|
118 |
|
---|
119 |
if ($edtime >= $sttime){ |
---|
120 |
$length = $edtime - $sttime; |
---|
121 |
}else{ |
---|
122 |
$length = $sttime - $edtime; |
---|
123 |
} |
---|
124 |
$length = $length / 60; |
---|
125 |
|
---|
126 |
return $length ; |
---|
127 |
} |
---|
128 |
|
---|
129 |
sub calcoffsetdate{ |
---|
130 |
|
---|
131 |
|
---|
132 |
my $foltime = $_[0] ; |
---|
133 |
my $offsetmin = $_[1] ; |
---|
134 |
|
---|
135 |
my $epoch = &foldate2epoch($foltime ); |
---|
136 |
$epoch = $epoch + ($offsetmin * 60 ); |
---|
137 |
$foltime = &epoch2foldate($epoch); |
---|
138 |
return $foltime ; |
---|
139 |
} |
---|
140 |
|
---|
141 |
sub getstationid{ |
---|
142 |
|
---|
143 |
|
---|
144 |
my $stationname = $_[0] ; |
---|
145 |
my $stationid ; |
---|
146 |
|
---|
147 |
my $sth; |
---|
148 |
$sth = $dbh->prepare($stmt{'foltialib.getstationid.1'}); |
---|
149 |
$sth->execute($item{'ChName'}); |
---|
150 |
my @stationcount; |
---|
151 |
@stationcount= $sth->fetchrow_array; |
---|
152 |
|
---|
153 |
if ($stationcount[0] == 1){ |
---|
154 |
|
---|
155 |
$sth = $dbh->prepare($stmt{'foltialib.getstationid.2'}); |
---|
156 |
$sth->execute($item{'ChName'}); |
---|
157 |
@stationinfo= $sth->fetchrow_array; |
---|
158 |
|
---|
159 |
$stationid = $stationinfo[0]; |
---|
160 |
|
---|
161 |
|
---|
162 |
}elsif($stationcount[0] == 0){ |
---|
163 |
|
---|
164 |
$sth = $dbh->prepare($stmt{'foltialib.getstationid.3'}); |
---|
165 |
$sth->execute(); |
---|
166 |
@stationinfo= $sth->fetchrow_array; |
---|
167 |
my $stationid = $stationinfo[0] ; |
---|
168 |
$stationid ++; |
---|
169 |
|
---|
170 |
|
---|
171 |
$sth = $dbh->prepare($stmt{'foltialib.getstationid.4'}); |
---|
172 |
$sth->execute($stationid, $item{'ChName'}, -10); |
---|
173 |
|
---|
174 |
&writelog("foltialib Add station;$stmt{'foltialib.getstationid.4'}"); |
---|
175 |
}else{ |
---|
176 |
|
---|
177 |
|
---|
178 |
&writelog("foltialib [ERR] getstationid $stationcount[0] stations found. $DBQuery"); |
---|
179 |
} |
---|
180 |
|
---|
181 |
|
---|
182 |
return $stationid ; |
---|
183 |
} |
---|
184 |
|
---|
185 |
sub calcatqparam{ |
---|
186 |
my $seconds = $_[0]; |
---|
187 |
my $processstarttimeepoch = ""; |
---|
188 |
$processstarttimeepoch = &foldate2epoch($startdatetime); |
---|
189 |
$processstarttimeepoch = $processstarttimeepoch - $seconds ; |
---|
190 |
my $sec = ""; |
---|
191 |
my $min = ""; |
---|
192 |
my $hour = ""; |
---|
193 |
my $mday = ""; |
---|
194 |
my $mon = ""; |
---|
195 |
my $year = ""; |
---|
196 |
my $wday = ""; |
---|
197 |
my $yday = ""; |
---|
198 |
my $isdst = ""; |
---|
199 |
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($processstarttimeepoch) ; |
---|
200 |
$year+=1900; |
---|
201 |
$mon++; |
---|
202 |
my $atdateparam = ""; |
---|
203 |
$atdateparam = sprintf ("%04d%02d%02d%02d%02d",$year,$mon,$mday,$hour,$min); |
---|
204 |
|
---|
205 |
return $atdateparam ; |
---|
206 |
} |
---|
207 |
|
---|
208 |
|
---|
209 |
|
---|
210 |
sub processfind{ |
---|
211 |
my $findprocess = $_[0]; |
---|
212 |
|
---|
213 |
my @processes ; |
---|
214 |
@processes = `ps ax | grep -i $findprocess `; |
---|
215 |
my $chkflag = 0; |
---|
216 |
|
---|
217 |
foreach (@processes ){ |
---|
218 |
if (/$findprocess/i){ |
---|
219 |
unless (/grep/){ |
---|
220 |
|
---|
221 |
$chkflag++ ; |
---|
222 |
}else{ |
---|
223 |
|
---|
224 |
} |
---|
225 |
} |
---|
226 |
|
---|
227 |
} |
---|
228 |
return ($chkflag); |
---|
229 |
} |
---|
230 |
|
---|
231 |
|
---|
232 |
sub filenameinjectioncheck{ |
---|
233 |
my $filename = $_[0]; |
---|
234 |
$filename =~ s/\///gi; |
---|
235 |
$filename =~ s/\;//gi; |
---|
236 |
$filename =~ s/\&//gi; |
---|
237 |
$filename =~ s/\|//gi; |
---|
238 |
|
---|
239 |
return ($filename ); |
---|
240 |
} |
---|
241 |
|
---|
242 |
|
---|
243 |
sub getphpstyleconfig{ |
---|
244 |
my $key = $_[0]; |
---|
245 |
my $phpconfigpath = ""; |
---|
246 |
my $configline = ""; |
---|
247 |
|
---|
248 |
if (-e "$phptoolpath/php/foltia_config2.php"){ |
---|
249 |
$phpconfigpath = "$phptoolpath/php/foltia_config2.php"; |
---|
250 |
}elsif(-e "$toolpath/php/foltia_config2.php"){ |
---|
251 |
$phpconfigpath = "$toolpath/php/foltia_config2.php"; |
---|
252 |
}else{ |
---|
253 |
$phpconfigpath = `locate foltia_config2.php | head -1`; |
---|
254 |
chomp($phpconfigpath); |
---|
255 |
} |
---|
256 |
|
---|
257 |
|
---|
258 |
if (-r $phpconfigpath ){ |
---|
259 |
open (CONFIG ,"$phpconfigpath") || die "File canot read.$!"; |
---|
260 |
while(<CONFIG>){ |
---|
261 |
if (/$key/){ |
---|
262 |
$configline = $_; |
---|
263 |
$configline =~ s/\/\/.*$//; |
---|
264 |
$configline =~ s/\/\*.*\*\///; |
---|
265 |
}else{ |
---|
266 |
} |
---|
267 |
} |
---|
268 |
close(CONFIG); |
---|
269 |
} |
---|
270 |
return ($configline); |
---|
271 |
} |
---|
272 |
|
---|
273 |
|
---|
274 |
sub getpidbympegfilename { |
---|
275 |
|
---|
276 |
|
---|
277 |
my $m2pfilename = $_[0] ; |
---|
278 |
if ($m2pfilename eq ""){ |
---|
279 |
return 0 ; |
---|
280 |
} |
---|
281 |
|
---|
282 |
my $sth; |
---|
283 |
$sth = $dbh->prepare($stmt{'foltialib.getpidbympegfilename.1'}); |
---|
284 |
$sth->execute($m2pfilename); |
---|
285 |
|
---|
286 |
my @pidinfo = $sth->fetchrow_array; |
---|
287 |
my $pid = $pidinfo[0]; |
---|
288 |
|
---|
289 |
if ($pid eq ""){ |
---|
290 |
return 0 ; |
---|
291 |
}else{ |
---|
292 |
return $pid; |
---|
293 |
} |
---|
294 |
} |
---|
295 |
|
---|
296 |
sub changefilestatus { |
---|
297 |
|
---|
298 |
|
---|
299 |
my $pid = $_[0] ; |
---|
300 |
my $updatestatus = $_[1]; |
---|
301 |
if (($pid eq "" ) || ($updatestatus eq "")){ |
---|
302 |
return 0 ; |
---|
303 |
} |
---|
304 |
|
---|
305 |
if ($updatestatus > 0 ){ |
---|
306 |
my $sth; |
---|
307 |
$sth = $dbh->prepare($stmt{'foltialib.changefilestatus.1'}); |
---|
308 |
$sth->execute($updatestatus, $pid); |
---|
309 |
return 1; |
---|
310 |
}else{ |
---|
311 |
&writelog("foltialib changefilestatus ERR Sttus invalid:$updatestatus"); |
---|
312 |
return 0 ; |
---|
313 |
} |
---|
314 |
} |
---|
315 |
|
---|
316 |
|
---|
317 |
sub getfilestatus { |
---|
318 |
|
---|
319 |
|
---|
320 |
|
---|
321 |
|
---|
322 |
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 |
|
---|
327 |
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 |
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 |
|
---|
338 |
|
---|
339 |
my $pid = $_[0] ; |
---|
340 |
if ($pid eq "" ){ |
---|
341 |
return 0 ; |
---|
342 |
} |
---|
343 |
|
---|
344 |
my $sth; |
---|
345 |
$sth = $dbh->prepare($stmt{'foltialib.getfilestatus.1'}); |
---|
346 |
$sth->execute($pid); |
---|
347 |
|
---|
348 |
my @statusinfo = $sth->fetchrow_array; |
---|
349 |
my $status = $statusinfo[0]; |
---|
350 |
|
---|
351 |
if ($status eq ""){ |
---|
352 |
return 0 ; |
---|
353 |
}else{ |
---|
354 |
return $status; |
---|
355 |
} |
---|
356 |
|
---|
357 |
|
---|
358 |
} |
---|
359 |
|
---|
360 |
|
---|
361 |
sub makemp4dir{ |
---|
362 |
|
---|
363 |
my $pspfilnamehd = $_[0]; |
---|
364 |
my $tid = $_[0]; |
---|
365 |
my $pspdirname = "$tid.localized/"; |
---|
366 |
$pspdirname = $recfolderpath."/".$pspdirname; |
---|
367 |
|
---|
368 |
|
---|
369 |
unless (-e $pspdirname ){ |
---|
370 |
system("$toolpath/perl/mklocalizeddir.pl $tid"); |
---|
371 |
|
---|
372 |
} |
---|
373 |
$pspdirname = "$tid.localized/mp4/"; |
---|
374 |
$pspdirname = $recfolderpath."/".$pspdirname; |
---|
375 |
|
---|
376 |
unless (-e $pspdirname ){ |
---|
377 |
mkdir $pspdirname ,0777; |
---|
378 |
|
---|
379 |
} |
---|
380 |
return ("$pspdirname"); |
---|
381 |
} |
---|
382 |
|
---|
383 |
sub pid2sid{ |
---|
384 |
|
---|
385 |
my $pid = $_[0]; |
---|
386 |
my $sth; |
---|
387 |
$sth = $dbh->prepare($stmt{'foltialib.pid2sid.1'}); |
---|
388 |
$sth->execute($pid); |
---|
389 |
my @statusinfo = $sth->fetchrow_array; |
---|
390 |
my $sid = $statusinfo[0]; |
---|
391 |
|
---|
392 |
if ($sid eq ""){ |
---|
393 |
return 0 ; |
---|
394 |
}else{ |
---|
395 |
return $sid; |
---|
396 |
} |
---|
397 |
|
---|
398 |
} |
---|
399 |
|
---|
400 |
|
---|
401 |
sub mp4filename2tid{ |
---|
402 |
|
---|
403 |
my $mp4filename = $_[0]; |
---|
404 |
|
---|
405 |
my $sth; |
---|
406 |
$sth = $dbh->prepare($stmt{'foltialib.mp4filename2tid.1'}); |
---|
407 |
$sth->execute($mp4filename); |
---|
408 |
my @statusinfo = $sth->fetchrow_array; |
---|
409 |
my $tid = $statusinfo[0]; |
---|
410 |
|
---|
411 |
if ($tid eq ""){ |
---|
412 |
return 0 ; |
---|
413 |
}else{ |
---|
414 |
return $tid; |
---|
415 |
} |
---|
416 |
} |
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|
421 |
|
---|
422 |
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 |
|
---|
428 |
|
---|
429 |
|
---|
430 |
|
---|
431 |
|
---|
432 |
|
---|
433 |
|
---|
434 |
|
---|
435 |
|
---|
436 |
|
---|
437 |
|
---|
438 |
|
---|
439 |
|
---|
440 |
|
---|
441 |
|
---|
442 |
|
---|
443 |
|
---|
444 |
|
---|
445 |
|
---|
446 |
|
---|
447 |
|
---|
448 |
|
---|
449 |
|
---|
450 |
|
---|
451 |
|
---|
452 |
|
---|
453 |
|
---|
454 |
|
---|
455 |
|
---|
456 |
|
---|
457 |
|
---|
458 |
|
---|
459 |
1; |
---|
460 |
|
---|