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