1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
use DBI; |
---|
15 |
use DBD::Pg; |
---|
16 |
use Schedule::At; |
---|
17 |
use Time::Local; |
---|
18 |
|
---|
19 |
$path = $0; |
---|
20 |
$path =~ s/addpidatq.pl$//i; |
---|
21 |
if ($pwd ne "./"){ |
---|
22 |
push( @INC, "$path"); |
---|
23 |
} |
---|
24 |
|
---|
25 |
require "foltialib.pl"; |
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 |
$pid = $ARGV[0] ; |
---|
30 |
if ($pid eq "" ){ |
---|
31 |
|
---|
32 |
print "usage;addpidatq.pl <PID>\n"; |
---|
33 |
exit; |
---|
34 |
} |
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 |
my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", |
---|
39 |
$DBDriv,$DBName,$DBHost,$DBPort); |
---|
40 |
$dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; |
---|
41 |
|
---|
42 |
$DBQuery = "SELECT count(*) FROM foltia_subtitle WHERE pid = '$pid' "; |
---|
43 |
$sth = $dbh->prepare($DBQuery); |
---|
44 |
$sth->execute(); |
---|
45 |
@titlecount= $sth->fetchrow_array; |
---|
46 |
|
---|
47 |
if ($titlecount[0] == 1 ){ |
---|
48 |
|
---|
49 |
$DBQuery = "SELECT bitrate FROM foltia_tvrecord , foltia_subtitle WHERE foltia_tvrecord.tid = foltia_subtitle.tid AND pid='$pid' "; |
---|
50 |
$sth = $dbh->prepare($DBQuery); |
---|
51 |
$sth->execute(); |
---|
52 |
@titlecount= $sth->fetchrow_array; |
---|
53 |
$bitrate = $titlecount[0]; |
---|
54 |
|
---|
55 |
|
---|
56 |
$now = &epoch2foldate(`date +%s`); |
---|
57 |
|
---|
58 |
$DBQuery = "SELECT stationrecch FROM foltia_station,foltia_subtitle WHERE foltia_subtitle.pid = '$pid' AND foltia_subtitle.stationid = foltia_station.stationid "; |
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 |
$stationh = $dbh->prepare($DBQuery); |
---|
63 |
$stationh->execute(); |
---|
64 |
@stationl = $stationh->fetchrow_array; |
---|
65 |
$recch = $stationl[0]; |
---|
66 |
|
---|
67 |
$DBQuery = "SELECT * FROM foltia_subtitle WHERE pid='$pid' "; |
---|
68 |
$sth = $dbh->prepare($DBQuery); |
---|
69 |
$sth->execute(); |
---|
70 |
($pid , |
---|
71 |
$tid , |
---|
72 |
$stationid , |
---|
73 |
$countno, |
---|
74 |
$subtitle, |
---|
75 |
$startdatetime, |
---|
76 |
$enddatetime, |
---|
77 |
$startoffset , |
---|
78 |
$lengthmin, |
---|
79 |
$atid ) = $sth->fetchrow_array(); |
---|
80 |
|
---|
81 |
|
---|
82 |
if($now< $startdatetime){ |
---|
83 |
|
---|
84 |
$startafter = &calclength($now,$startdatetime); |
---|
85 |
&writelog("addpidatq DEBUG \$startafter $startafter \$now $now \$startdatetime $startdatetime"); |
---|
86 |
|
---|
87 |
if ($startafter > 14 ){ |
---|
88 |
|
---|
89 |
|
---|
90 |
Schedule::At::remove ( TAG => "$pid"."_X"); |
---|
91 |
&writelog("addpidatq remove que $pid"); |
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
$atdateparam = &calcatqparam(300); |
---|
97 |
Schedule::At::add (TIME => "$atdateparam", COMMAND => "$toolpath/perl/folprep.pl $pid" , TAG => "$pid"."_X"); |
---|
98 |
&writelog("addpidatq TIME $atdateparam COMMAND $toolpath/perl/folprep.pl $pid "); |
---|
99 |
}else{ |
---|
100 |
$atdateparam = &calcatqparam(60); |
---|
101 |
$reclength = $lengthmin * 60; |
---|
102 |
|
---|
103 |
|
---|
104 |
Schedule::At::remove ( TAG => "$pid"."_R"); |
---|
105 |
&writelog("addpidatq remove que $pid"); |
---|
106 |
|
---|
107 |
if ($countno eq ""){ |
---|
108 |
$countno = "0"; |
---|
109 |
} |
---|
110 |
|
---|
111 |
Schedule::At::add (TIME => "$atdateparam", COMMAND => "$toolpath/perl/recwrap.pl $recch $reclength $bitrate $tid $countno $pid" , TAG => "$pid"."_R"); |
---|
112 |
&writelog("addpidatq TIME $atdateparam COMMAND $toolpath/perl/recwrap.pl $recch $reclength $bitrate $tid $countno $pid"); |
---|
113 |
|
---|
114 |
} |
---|
115 |
|
---|
116 |
}else{ |
---|
117 |
&writelog("addpidatq drop:expire $pid $startafter $now $startdatetime"); |
---|
118 |
} |
---|
119 |
|
---|
120 |
}else{ |
---|
121 |
print "error record TID=$tid SID=$station $titlecount[0] match:$DBQuery\n"; |
---|
122 |
&writelog("addpidatq error record TID=$tid SID=$station $titlecount[0] match:$DBQuery"); |
---|
123 |
|
---|
124 |
} |
---|
125 |
|
---|
126 |
|
---|