root/trunk/install/perl/foltialib.pl

リビジョン 83, 8.2 kB (コミッタ: sorshi, コミット時期: 16 年 前)

foltiaHD最初のリリース。
デジタル録画はFriio/Friio BS/CSのみに対応。
ivtvは1.0系使用になりました。

  • svn:executable 属性の設定値:
Line 
1
2 #config load
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 #  foltia lib
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 }#end writelog
60
61 sub syobocaldate2foltiadate{
62 #20041114213000 -> 200411142130
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 #EPGをEPOCに
75 # 2004 11 14 21 30
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 #foltia開始時刻、folti終了時刻
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 #引き数:foltia時刻、オフセット(+/-)分
133 #戻り値]foltia時刻
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 #引き数:局文字列(NHK総合)
145 #戻り値:1
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 #チャンネルID取得
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 #局ID
163 $stationid  = $stationinfo[0];
164 #print "StationID:$stationid \n";
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 ##$DBQuery =  "insert into  foltia_station values ('$stationid'  ,'$item{ChName}','0','','','','','','')";
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 #print "Add station;$DBQuery\n";
181 &writelog("foltialib Add station;$DBQuery");
182 }else{
183
184 #print "Error  getstationid $stationcount[0] stations found. $DBQuery\n";
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++;#範囲を0-11から1-12へ
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                 #print "process found:$_\n";
228                 $chkflag++ ;
229                 }else{
230                 #print "process NOT found:$_\n";
231                 }
232         }
233
234 }
235 return ($chkflag);
236 }#endsub
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  # read
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 }#end if -r $phpconfigpath
277 return ($configline);
278 }#end sub getphpstyleconfig
279
280
281 sub getpidbympegfilename {
282 #引き数:m2pfilename
283 #戻り値:PID
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 #print "$DBQuery\n";
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 }#end sub getpidbympegfilename
303
304 sub changefilestatus {
305 #引き数:PID,updatestatus
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 }# end sub changefilestatus
324
325
326 sub getfilestatus {
327 #引き数:PID
328 #戻り値:ステータス
329
330 #10:予約中(5分以上先)
331 #20:予約中(5分以内)
332 #30:録画中
333 #40:TSSplit中
334 #50:MPEG2録画終了
335 #55 静止画キャプチャ待
336 #60:静止画キャプ中
337 #70:静止画キャプ終了
338 #72:サムネイル作成済み(.THM)
339 #80:トラコン待
340 #90:トラコン中:TSsplit
341 #100:トラコン中:H264
342 #110:トラコン中:WAVE
343 #120:トラコン中:AAC
344 #130:トラコン中:MP4Box
345 #140:トラコン中:ATOM
346 #150:トラコン完了
347 #200:全完了
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 }# end sub getfilestatus
369
370
371 sub makemp4dir{
372 #TIDが100以上の3桁の場合はそのまま
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         #&writelog("recwrap mkdir $pspdirname");
382 }
383 $pspdirname = "$tid.localized/mp4/";
384 $pspdirname = $recfolderpath."/".$pspdirname;
385 #なければ作る
386 unless (-e $pspdirname ){
387         mkdir $pspdirname ,0777;
388         #&writelog("recwrap mkdir $pspdirname");
389 }
390 return ("$pspdirname");
391 }#endsub makemp4dir
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
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed