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