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