root/trunk/install/perl/foltialib.pl

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

MP4録画ライブラリでの削除機能追加

  • svn:executable 属性の設定値:
Line 
1
2 #config load
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 #  foltia lib
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 }#end writelog
58
59 sub syobocaldate2foltiadate{
60 #20041114213000 -> 200411142130
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 #EPGをEPOCに
73 # 2004 11 14 21 30
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 #foltia開始時刻、folti終了時刻
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 #引き数:foltia時刻、オフセット(+/-)分
131 #戻り値]foltia時刻
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 #引き数:局文字列(NHK総合)
143 #戻り値:1
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 #チャンネルID取得
155         $sth = $dbh->prepare($stmt{'foltialib.getstationid.2'});
156         $sth->execute($item{'ChName'});
157  @stationinfo= $sth->fetchrow_array;
158 #局ID
159 $stationid  = $stationinfo[0];
160 #print "StationID:$stationid \n";
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 ##$DBQuery =  "insert into  foltia_station values ('$stationid'  ,'$item{ChName}','0','','','','','','')";
170 #新規局追加時は非受信局をデフォルトに
171         $sth = $dbh->prepare($stmt{'foltialib.getstationid.4'});
172         $sth->execute($stationid, $item{'ChName'}, -10);
173 #print "Add station;$DBQuery\n";
174         &writelog("foltialib Add station;$stmt{'foltialib.getstationid.4'}");
175 }else{
176
177 #print "Error  getstationid $stationcount[0] stations found. $DBQuery\n";
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++;#範囲を0-11から1-12へ
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                 #print "process found:$_\n";
221                 $chkflag++ ;
222                 }else{
223                 #print "process NOT found:$_\n";
224                 }
225         }
226
227 }
228 return ($chkflag);
229 }#endsub
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  # read
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 }#end if -r $phpconfigpath
270 return ($configline);
271 }#end sub getphpstyleconfig
272
273
274 sub getpidbympegfilename {
275 #引き数:m2pfilename
276 #戻り値:PID
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 #print "$stmt{'foltialib.getpidbympegfilename.1'}\n";
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 }#end sub getpidbympegfilename
295
296 sub changefilestatus {
297 #引き数:PID,updatestatus
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 }# end sub changefilestatus
315
316
317 sub getfilestatus {
318 #引き数:PID
319 #戻り値:ステータス
320
321 #10:予約中(5分以上先)
322 #20:予約中(5分以内)
323 #30:録画中
324 #40:TSSplit中
325 #50:MPEG2録画終了
326 #55 静止画キャプチャ待
327 #60:静止画キャプ中
328 #70:静止画キャプ終了
329 #72:サムネイル作成済み(.THM)
330 #80:トラコン待
331 #90:トラコン中:TSsplit
332 #100:トラコン中:H264
333 #110:トラコン中:WAVE
334 #120:トラコン中:AAC
335 #130:トラコン中:MP4Box
336 #140:トラコン中:ATOM
337 #150:トラコン完了
338 #200:全完了
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 }# end sub getfilestatus
359
360
361 sub makemp4dir{
362 #TIDが100以上の3桁の場合はそのまま
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         #&writelog("recwrap mkdir $pspdirname");
372 }
373 $pspdirname = "$tid.localized/mp4/";
374 $pspdirname = $recfolderpath."/".$pspdirname;
375 #なければ作る
376 unless (-e $pspdirname ){
377         mkdir $pspdirname ,0777;
378         #&writelog("recwrap mkdir $pspdirname");
379 }
380 return ("$pspdirname");
381 }#endsub makemp4dir
382
383 sub pid2sid{
384 #番組IDからStation IDを取得
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 }#end sub pid2sid
399
400
401 sub mp4filename2tid{
402 #MPEG4ファイル名からTIDを得る
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 }#end sub mp4filename2tid
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
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed