1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
use DBI; |
---|
21 |
use DBD::Pg; |
---|
22 |
use DBD::SQLite; |
---|
23 |
|
---|
24 |
|
---|
25 |
use Jcode; |
---|
26 |
|
---|
27 |
$path = $0; |
---|
28 |
$path =~ s/epgimport.pl$//i; |
---|
29 |
if ($path ne "./"){ |
---|
30 |
push( @INC, "$path"); |
---|
31 |
} |
---|
32 |
|
---|
33 |
require "foltialib.pl"; |
---|
34 |
|
---|
35 |
my $ontvcode = ""; |
---|
36 |
my $channel = ""; |
---|
37 |
my @date = (); |
---|
38 |
my $recpt1path = $toolpath . "/perl/tool/recpt1"; |
---|
39 |
my $epgdumppath = $toolpath ."/perl/tool"; |
---|
40 |
my $xmloutpath = "/tmp"; |
---|
41 |
my %stations; |
---|
42 |
my $uset = ""; |
---|
43 |
my $usebs = ""; |
---|
44 |
my $usecs = ""; |
---|
45 |
my $stationid = "" ; |
---|
46 |
my $rectime = 0; |
---|
47 |
my $bsrectime = 0; |
---|
48 |
my $cs1rectime = 0; |
---|
49 |
my $cs2rectime = 0; |
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 |
if ( $ARGV[0] eq "long" ){ |
---|
54 |
|
---|
55 |
$rectime = 60; |
---|
56 |
$bsrectime = 120; |
---|
57 |
$cs1rectime = 60; |
---|
58 |
$cs2rectime = 60; |
---|
59 |
}elsif( $ARGV[0] > 0 ){ |
---|
60 |
$stationid = $ARGV[0]; |
---|
61 |
$rectime = 3; |
---|
62 |
$bsrectime = 36; |
---|
63 |
$cs1rectime = 15; |
---|
64 |
$cs2rectime = 5; |
---|
65 |
}else{ |
---|
66 |
|
---|
67 |
$rectime = 3; |
---|
68 |
$bsrectime = 36; |
---|
69 |
$cs1rectime = 15; |
---|
70 |
$cs2rectime = 5; |
---|
71 |
} |
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 |
|
---|
78 |
$processes = &processfind("epgimport.pl"); |
---|
79 |
if ($processes > 1 ){ |
---|
80 |
&writelog("epgimport processes exist. exit:"); |
---|
81 |
exit; |
---|
82 |
} |
---|
83 |
|
---|
84 |
|
---|
85 |
$dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;; |
---|
86 |
|
---|
87 |
|
---|
88 |
if ($stationid > 0){ |
---|
89 |
$sth = $dbh->prepare($stmt{'epgimport.1'}); |
---|
90 |
$sth->execute($stationid); |
---|
91 |
@data = $sth->fetchrow_array(); |
---|
92 |
unless($data[0] == 1){ |
---|
93 |
&writelog("epgimport ERROR Invalid station id ($stationid)."); |
---|
94 |
exit 1; |
---|
95 |
}else{ |
---|
96 |
$sth = $dbh->prepare($stmt{'epgimport.2'}); |
---|
97 |
$sth->execute($stationid); |
---|
98 |
@data = $sth->fetchrow_array(); |
---|
99 |
$channel = $data[0]; |
---|
100 |
$ontvcode = $data[1]; |
---|
101 |
if ($channel > 0){ |
---|
102 |
&writelog("epgimport DEBUG Single station mode (ch:$channel / $ontvcode)."); |
---|
103 |
}else{ |
---|
104 |
&writelog("epgimport ABORT SID $stationid is not Digital TV ch."); |
---|
105 |
exit; |
---|
106 |
} |
---|
107 |
} |
---|
108 |
} |
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
if ($channel >= 13 && $channel <= 62){ |
---|
113 |
$stations{$channel} = $ontvcode; |
---|
114 |
$uset = 1; |
---|
115 |
}elsif($channel >= 100){ |
---|
116 |
$uset = 0; |
---|
117 |
}else{ |
---|
118 |
$sth = $dbh->prepare($stmt{'epgimport.3'}); |
---|
119 |
$sth->execute(); |
---|
120 |
|
---|
121 |
while (@data = $sth->fetchrow_array()) { |
---|
122 |
$stations{$data[0]} = $data[1]; |
---|
123 |
} |
---|
124 |
$uset = 1; |
---|
125 |
} |
---|
126 |
|
---|
127 |
if ($uset == 1){ |
---|
128 |
foreach $channel ( keys %stations ) { |
---|
129 |
$ontvcode = $stations{$channel}; |
---|
130 |
|
---|
131 |
&chkrecordingschedule; |
---|
132 |
|
---|
133 |
$oserr = `$recpt1path $channel $rectime $recfolderpath/__$channel.m2t`; |
---|
134 |
|
---|
135 |
$oserr = `$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`; |
---|
136 |
|
---|
137 |
$oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`; |
---|
138 |
unlink "$recfolderpath/__$channel.m2t"; |
---|
139 |
unlink "$xmloutpath/__$channel-epg.xml"; |
---|
140 |
} |
---|
141 |
} |
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
if ($channel >= 100 && $channel <= 222 ){ |
---|
146 |
$usebs = 1; |
---|
147 |
}elsif($channel >= 13 && $channel <= 62){ |
---|
148 |
$usebs = 0; |
---|
149 |
}elsif($channel >= 223){ |
---|
150 |
$usebs = 0; |
---|
151 |
}else{ |
---|
152 |
$sth = $dbh->prepare($stmt{'epgimport.4'}); |
---|
153 |
$sth->execute(); |
---|
154 |
@data = $sth->fetchrow_array(); |
---|
155 |
if ($data[0] > 0 ){ |
---|
156 |
$usebs = 1; |
---|
157 |
} |
---|
158 |
} |
---|
159 |
|
---|
160 |
if ($usebs == 1){ |
---|
161 |
|
---|
162 |
$channel = 211; |
---|
163 |
|
---|
164 |
&chkrecordingschedule; |
---|
165 |
|
---|
166 |
$oserr = `$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t`; |
---|
167 |
|
---|
168 |
$oserr = `$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`; |
---|
169 |
|
---|
170 |
$oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`; |
---|
171 |
unlink "$recfolderpath/__$channel.m2t"; |
---|
172 |
unlink "$xmloutpath/__$channel-epg.xml"; |
---|
173 |
}else{ |
---|
174 |
&writelog("epgimport DEBUG Skip BS.$channel:$usebs"); |
---|
175 |
} |
---|
176 |
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
if ($channel >= 223 ){ |
---|
183 |
$usecs = 1; |
---|
184 |
}else{ |
---|
185 |
$sth = $dbh->prepare($stmt{'epgimport.5'}); |
---|
186 |
$sth->execute(); |
---|
187 |
@data = $sth->fetchrow_array(); |
---|
188 |
if ($data[0] > 0 ){ |
---|
189 |
$usecs = 1; |
---|
190 |
} |
---|
191 |
} |
---|
192 |
|
---|
193 |
if ($usecs == 1){ |
---|
194 |
|
---|
195 |
$channela = "CS8"; |
---|
196 |
|
---|
197 |
&chkrecordingschedule; |
---|
198 |
|
---|
199 |
$oserr = `$recpt1path $channela $cs1rectime $recfolderpath/__$channela.m2t`; |
---|
200 |
|
---|
201 |
$channelb = "CS24"; |
---|
202 |
&chkrecordingschedule; |
---|
203 |
|
---|
204 |
$oserr = `$recpt1path $channelb $cs2rectime $recfolderpath/__$channelb.m2t`; |
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 |
$oserr = `$epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml`; |
---|
209 |
|
---|
210 |
$oserr = `cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl`; |
---|
211 |
unlink "$recfolderpath/__$channela.m2t"; |
---|
212 |
unlink "$xmloutpath/__$channela-epg.xml"; |
---|
213 |
|
---|
214 |
|
---|
215 |
$oserr = `$epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml`; |
---|
216 |
|
---|
217 |
$oserr = `cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl`; |
---|
218 |
unlink "$recfolderpath/__$channelb.m2t"; |
---|
219 |
unlink "$xmloutpath/__$channelb-epg.xml"; |
---|
220 |
}else{ |
---|
221 |
&writelog("epgimport DEBUG Skip CS."); |
---|
222 |
} |
---|
223 |
|
---|
224 |
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 |
sub chkrecordingschedule{ |
---|
231 |
|
---|
232 |
my $now = time() ; |
---|
233 |
my $fiveminitsafter = time() + 60 * 4; |
---|
234 |
my $rows = -2; |
---|
235 |
$now = &epoch2foldate($now); |
---|
236 |
$fiveminitsafter = &epoch2foldate($fiveminitsafter); |
---|
237 |
|
---|
238 |
|
---|
239 |
$sth = $dbh->prepare($stmt{'epgimport.6'}); |
---|
240 |
$sth->execute($now,$fiveminitsafter,$now,$fiveminitsafter); |
---|
241 |
|
---|
242 |
while (@data = $sth->fetchrow_array()) { |
---|
243 |
|
---|
244 |
} |
---|
245 |
|
---|
246 |
$rows = $sth->rows; |
---|
247 |
|
---|
248 |
if ($rows > 0 ){ |
---|
249 |
&writelog("epgimport ABORT The recording schedule had approached."); |
---|
250 |
exit ; |
---|
251 |
}else{ |
---|
252 |
&writelog("epgimport DEBUG Near rec program is $rows.:$now:$fiveminitsafter"); |
---|
253 |
} |
---|
254 |
} |
---|
255 |
|
---|