1 |
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
use LWP::Simple; |
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
use Jcode; |
---|
25 |
|
---|
26 |
use Time::Local; |
---|
27 |
use DBI; |
---|
28 |
use DBD::Pg; |
---|
29 |
|
---|
30 |
$path = $0; |
---|
31 |
$path =~ s/xmltv2foltia.pl$//i; |
---|
32 |
if ($pwd ne "./"){ |
---|
33 |
push( @INC, "$path"); |
---|
34 |
} |
---|
35 |
require "foltialib.pl"; |
---|
36 |
|
---|
37 |
$currentworkdate = "" ; |
---|
38 |
$currentworkch = "" ; |
---|
39 |
$today =`date "+%Y%m%d"`; |
---|
40 |
$todaytime =`date "+%Y%m%d%H%M"`; |
---|
41 |
|
---|
42 |
|
---|
43 |
my $data_source = sprintf("dbi:%s:dbname=%s;host=%s;port=%d", |
---|
44 |
$DBDriv,$DBName,$DBHost,$DBPort); |
---|
45 |
$dbh = DBI->connect($data_source,$DBUser,$DBPass) ||die $DBI::error;; |
---|
46 |
|
---|
47 |
while(<>){ |
---|
48 |
|
---|
49 |
Jcode::convert(\$_,'euc','utf8'); |
---|
50 |
|
---|
51 |
if(/<channel/){ |
---|
52 |
|
---|
53 |
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 |
s/^[\s]*//gio; |
---|
59 |
s/<channel//i; |
---|
60 |
|
---|
61 |
s/\"\>/\" /i; |
---|
62 |
s/\"[\s]/\";\n/gio; |
---|
63 |
s/[\w]*=/\$channel{$&}=/gio; |
---|
64 |
s/\=}=/}=/gio; |
---|
65 |
chomp(); |
---|
66 |
eval("$_"); |
---|
67 |
|
---|
68 |
|
---|
69 |
}elsif(/<display-name lang=\"ja_JP/){ |
---|
70 |
s/^[\s]*//gio; |
---|
71 |
chomp(); |
---|
72 |
$channel{ja} = &removetag($_); |
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 |
|
---|
77 |
}elsif(/<display-name lang=\"ja_JP/){ |
---|
78 |
s/^[\s]*//gio; |
---|
79 |
chomp(); |
---|
80 |
$channel{ja} = &removetag($_); |
---|
81 |
|
---|
82 |
|
---|
83 |
}elsif(/<display-name lang=\"en/){ |
---|
84 |
s/^[\s]*//gio; |
---|
85 |
chomp(); |
---|
86 |
$channel{en} = &removetag($_); |
---|
87 |
|
---|
88 |
|
---|
89 |
|
---|
90 |
}elsif(/<\/channel>/){ |
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 |
|
---|
96 |
|
---|
97 |
|
---|
98 |
$channel{id} = ""; |
---|
99 |
$channel{ja} = ""; |
---|
100 |
$channel{en} = ""; |
---|
101 |
|
---|
102 |
}elsif (/<programme /){ |
---|
103 |
|
---|
104 |
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 |
|
---|
112 |
s/<programme //i; |
---|
113 |
|
---|
114 |
s/\"\>/\" /i; |
---|
115 |
s/\"[\s]/\";\n/gio; |
---|
116 |
s/[\w]*=/\$item{$&}=/gio; |
---|
117 |
s/\=}=/}=/gio; |
---|
118 |
chomp(); |
---|
119 |
eval("$_"); |
---|
120 |
|
---|
121 |
|
---|
122 |
|
---|
123 |
|
---|
124 |
}elsif(/<sub-title /){ |
---|
125 |
s/^[\s]*//gio; |
---|
126 |
chomp(); |
---|
127 |
$item{subtitle} = &removetag($_); |
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 |
}elsif(/<title /){ |
---|
132 |
s/^[\s]*//gio; |
---|
133 |
chomp(); |
---|
134 |
$item{title} = &removetag($_); |
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
}elsif(/<desc /){ |
---|
139 |
s/^[\s]*//gio; |
---|
140 |
chomp(); |
---|
141 |
$item{desc} = &removetag($_); |
---|
142 |
|
---|
143 |
|
---|
144 |
|
---|
145 |
}elsif(/<category lang=\"ja_JP/){ |
---|
146 |
s/^[\s]*//gio; |
---|
147 |
chomp(); |
---|
148 |
$item{category} = &removetag($_); |
---|
149 |
|
---|
150 |
|
---|
151 |
|
---|
152 |
|
---|
153 |
}elsif(/<\/programme>/){ |
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
&chkerase($item{start},$item{channel}); |
---|
158 |
if ($item{subtitle} ne "" ){ |
---|
159 |
$registdesc = $item{subtitle}." ".$item{desc}; |
---|
160 |
}else{ |
---|
161 |
$registdesc = $item{desc}; |
---|
162 |
} |
---|
163 |
®istdb($item{start},$item{stop},$item{channel},$item{title},$registdesc ,$item{category}); |
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 |
$item{start} = ""; |
---|
174 |
$item{stop} = ""; |
---|
175 |
$item{channel} = ""; |
---|
176 |
$item{title} = ""; |
---|
177 |
$item{subtitle} = ""; |
---|
178 |
$item{desc} = ""; |
---|
179 |
$item{category} = ""; |
---|
180 |
$registdesc = ""; |
---|
181 |
} |
---|
182 |
} |
---|
183 |
|
---|
184 |
sub chkerase{ |
---|
185 |
|
---|
186 |
my $foltiastarttime = $_[0]; |
---|
187 |
my $ontvepgchannel = $_[1]; |
---|
188 |
my $epgstartdate = substr($foltiastarttime,0,8); |
---|
189 |
my @epgcounts = ""; |
---|
190 |
my $DBQuery = ""; |
---|
191 |
|
---|
192 |
|
---|
193 |
if ( $currentworkch ne $ontvepgchannel){ |
---|
194 |
|
---|
195 |
|
---|
196 |
if ($epgstartdate >= $today){ |
---|
197 |
my $epgstartdatetime = $today * 10000 ; |
---|
198 |
|
---|
199 |
|
---|
200 |
$DBQuery = "DELETE from foltia_epg where startdatetime > $todaytime AND ontvchannel = '$ontvepgchannel' "; |
---|
201 |
$sth = $dbh->prepare($DBQuery); |
---|
202 |
$sth->execute(); |
---|
203 |
&writelog("xmltv2foltia DELETE EPG $epgstartdatetime:$DBQuery"); |
---|
204 |
|
---|
205 |
$currentworkch = $ontvepgchannel ; |
---|
206 |
}else{ |
---|
207 |
&writelog("xmltv2foltia ERROR EPG INVALID:$epgstartdate:$today"); |
---|
208 |
|
---|
209 |
} |
---|
210 |
} |
---|
211 |
|
---|
212 |
} |
---|
213 |
sub registdb{ |
---|
214 |
my $foltiastarttime = $_[0]; |
---|
215 |
my $foltiaendtime = $_[1]; |
---|
216 |
my $channel = $_[2]; |
---|
217 |
my $title = $_[3]; |
---|
218 |
my $desc = $_[4]; |
---|
219 |
my $category = $_[5]; |
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
$foltiastarttime = substr($foltiastarttime,0,12); |
---|
225 |
$foltiaendtime = substr($foltiaendtime,0,12); |
---|
226 |
|
---|
227 |
if($foltiastarttime > $todaytime){ |
---|
228 |
|
---|
229 |
my $DBQuery = "SELECT max(epgid) FROM foltia_epg "; |
---|
230 |
$sth = $dbh->prepare($DBQuery); |
---|
231 |
$sth->execute(); |
---|
232 |
@currentepgid = $sth->fetchrow_array; |
---|
233 |
|
---|
234 |
if ($currentepgid[0] < 1 ){ |
---|
235 |
$newepgid = 1; |
---|
236 |
}else{ |
---|
237 |
$newepgid = $currentepgid[0]; |
---|
238 |
$newepgid++; |
---|
239 |
} |
---|
240 |
|
---|
241 |
my $lengthmin = &calclength($foltiastarttime , $foltiaendtime); |
---|
242 |
$newepgid = $dbh->quote($newepgid ); |
---|
243 |
$foltiastarttime = $dbh->quote($foltiastarttime); |
---|
244 |
$foltiaendtime = $dbh->quote($foltiaendtime ); |
---|
245 |
$lengthmin = $dbh->quote($lengthmin ); |
---|
246 |
$channel = $dbh->quote($channel ); |
---|
247 |
$title = $dbh->quote($title); |
---|
248 |
$desc = $dbh->quote($desc); |
---|
249 |
$category = $dbh->quote($category); |
---|
250 |
|
---|
251 |
$DBQuery = "insert into foltia_epg values ($newepgid,$foltiastarttime,$foltiaendtime,$lengthmin,$channel,$title,$desc,$category)"; |
---|
252 |
|
---|
253 |
$sth = $dbh->prepare($DBQuery); |
---|
254 |
$sth->execute(); |
---|
255 |
|
---|
256 |
|
---|
257 |
|
---|
258 |
|
---|
259 |
}else{ |
---|
260 |
|
---|
261 |
} |
---|
262 |
|
---|
263 |
} |
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 |
|
---|
269 |
|
---|
270 |
|
---|
271 |
|
---|
272 |
sub removetag(){ |
---|
273 |
my $str = $_[0]; |
---|
274 |
|
---|
275 |
|
---|
276 |
my $tag_regex_ = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}} |
---|
277 |
my $comment_tag_regex = |
---|
278 |
'<!(?:--[^-]*-(?:[^-]+-)*?-(?:[^>-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)'; |
---|
279 |
my $tag_regex = qq{$comment_tag_regex|<$tag_regex_}; |
---|
280 |
|
---|
281 |
|
---|
282 |
my $text_regex = q{[^<]*}; |
---|
283 |
|
---|
284 |
my $result = ''; |
---|
285 |
while ($str =~ /($text_regex)($tag_regex)?/gso) { |
---|
286 |
last if $1 eq '' and $2 eq ''; |
---|
287 |
$result .= $1; |
---|
288 |
$tag_tmp = $2; |
---|
289 |
if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) { |
---|
290 |
$str =~ /(.*?)(?:<\/$1(?![0-9A-Za-z])$tag_regex_|$)/gsi; |
---|
291 |
($text_tmp = $1) =~ s/</</g; |
---|
292 |
$text_tmp =~ s/>/>/g; |
---|
293 |
$result .= $text_tmp; |
---|
294 |
} |
---|
295 |
} |
---|
296 |
|
---|
297 |
|
---|
298 |
return $result ; |
---|
299 |
|
---|
300 |
} |
---|