1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
use DBI; |
---|
17 |
use DBD::Pg; |
---|
18 |
use Schedule::At; |
---|
19 |
use Time::Local; |
---|
20 |
|
---|
21 |
$path = $0; |
---|
22 |
$path =~ s/addatq.pl$//i; |
---|
23 |
if ($pwd ne "./"){ |
---|
24 |
push( @INC, "$path"); |
---|
25 |
} |
---|
26 |
|
---|
27 |
require "foltialib.pl"; |
---|
28 |
|
---|
29 |
|
---|
30 |
$tid = $ARGV[0] ; |
---|
31 |
$station = $ARGV[1]; |
---|
32 |
|
---|
33 |
if (($tid eq "" )|| ($station eq "")){ |
---|
34 |
|
---|
35 |
print "usage;addatq.pl <TID> <StationID> [DELETE]\n"; |
---|
36 |
exit; |
---|
37 |
} |
---|
38 |
|
---|
39 |
|
---|
40 |
$data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", |
---|
41 |
$DBDriv,$DBName,$DBHost,$DBPort); |
---|
42 |
$dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; |
---|
43 |
|
---|
44 |
if ($station == 0){ |
---|
45 |
$DBQuery = "SELECT count(*) FROM foltia_tvrecord WHERE tid = '$tid' "; |
---|
46 |
}else{ |
---|
47 |
$DBQuery = "SELECT count(*) FROM foltia_tvrecord WHERE tid = '$tid' AND stationid = '$station' "; |
---|
48 |
} |
---|
49 |
$sth = $dbh->prepare($DBQuery); |
---|
50 |
$sth->execute(); |
---|
51 |
@titlecount = $sth->fetchrow_array; |
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
if ($titlecount[0] >= 2){ |
---|
56 |
|
---|
57 |
$DBQuery = "SELECT count(*) FROM foltia_tvrecord WHERE tid = '$tid' AND stationid ='0' "; |
---|
58 |
$kth = $dbh->prepare($DBQuery); |
---|
59 |
$kth->execute(); |
---|
60 |
@reservecounts = $kth->fetchrow_array; |
---|
61 |
|
---|
62 |
if($reservecounts[0] >= 1 ){ |
---|
63 |
if($tid == 0){ |
---|
64 |
|
---|
65 |
|
---|
66 |
|
---|
67 |
&addcue; |
---|
68 |
}else{ |
---|
69 |
|
---|
70 |
|
---|
71 |
exit; |
---|
72 |
} |
---|
73 |
} |
---|
74 |
}elsif($titlecount[0] == 1){ |
---|
75 |
&addcue; |
---|
76 |
}else{ |
---|
77 |
&writelog("addatq error; reserve impossible . TID=$tid SID=$station $titlecount[0] match:$DBQuery"); |
---|
78 |
} |
---|
79 |
|
---|
80 |
|
---|
81 |
|
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 |
sub addcue{ |
---|
88 |
|
---|
89 |
if ($station == 0){ |
---|
90 |
$DBQuery = "SELECT * FROM foltia_tvrecord WHERE tid = '$tid' "; |
---|
91 |
}else{ |
---|
92 |
$DBQuery = "SELECT * FROM foltia_tvrecord WHERE tid = '$tid' AND stationid = '$station' "; |
---|
93 |
} |
---|
94 |
$sth = $dbh->prepare($DBQuery); |
---|
95 |
$sth->execute(); |
---|
96 |
@titlecount= $sth->fetchrow_array; |
---|
97 |
$bitrate = $titlecount[2]; |
---|
98 |
|
---|
99 |
|
---|
100 |
$now = &epoch2foldate(`date +%s`); |
---|
101 |
$twodaysafter = &epoch2foldate(`date +%s` + (60 * 60 * 24 * 2)); |
---|
102 |
|
---|
103 |
if ($station == 0 ){ |
---|
104 |
$DBQuery = " |
---|
105 |
SELECT * from foltia_subtitle WHERE tid = '$tid' AND startdatetime > '$now' AND startdatetime < '$twodaysafter' "; |
---|
106 |
}else{ |
---|
107 |
$DBQuery = " |
---|
108 |
SELECT * from foltia_subtitle WHERE tid = '$tid' AND stationid = '$station' AND startdatetime > '$now' AND startdatetime < '$twodaysafter' "; |
---|
109 |
|
---|
110 |
$getrecchquery="SELECT stationid , stationrecch FROM foltia_station where stationid = '$station' "; |
---|
111 |
$stationh = $dbh->prepare($getrecchquery); |
---|
112 |
$stationh->execute(); |
---|
113 |
@stationl = $stationh->fetchrow_array; |
---|
114 |
$recch = $stationl[1]; |
---|
115 |
} |
---|
116 |
|
---|
117 |
$sth = $dbh->prepare($DBQuery); |
---|
118 |
$sth->execute(); |
---|
119 |
|
---|
120 |
while (($pid , |
---|
121 |
$tid , |
---|
122 |
$stationid , |
---|
123 |
$countno, |
---|
124 |
$subtitle, |
---|
125 |
$startdatetime, |
---|
126 |
$enddatetime, |
---|
127 |
$startoffset , |
---|
128 |
$lengthmin, |
---|
129 |
$atid ) = $sth->fetchrow_array()) { |
---|
130 |
|
---|
131 |
if ($station == 0 ){ |
---|
132 |
|
---|
133 |
$getrecchquery="SELECT stationid , stationrecch FROM foltia_station where stationid = '$stationid' "; |
---|
134 |
$stationh = $dbh->prepare($getrecchquery); |
---|
135 |
$stationh->execute(); |
---|
136 |
@stationl = $stationh->fetchrow_array; |
---|
137 |
$recch = $stationl[1]; |
---|
138 |
} |
---|
139 |
|
---|
140 |
|
---|
141 |
$atdateparam = &calcatqparam(300); |
---|
142 |
$reclength = $lengthmin * 60; |
---|
143 |
|
---|
144 |
|
---|
145 |
Schedule::At::remove ( TAG => "$pid"."_X"); |
---|
146 |
&writelog("addatq remove $pid"); |
---|
147 |
if ( $ARGV[2] eq "DELETE"){ |
---|
148 |
&writelog("addatq remove only $pid"); |
---|
149 |
}else{ |
---|
150 |
Schedule::At::add (TIME => "$atdateparam", COMMAND => "$toolpath/perl/folprep.pl $pid" , TAG => "$pid"."_X"); |
---|
151 |
&writelog("addatq TIME $atdateparam COMMAND $toolpath/perl/folprep.pl $pid "); |
---|
152 |
} |
---|
153 |
|
---|
154 |
|
---|
155 |
} |
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 |
} |
---|
160 |
|
---|