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