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 |
$titlebackup = $item{title}; |
---|
130 |
$item{title} =~ s/【.*?】//g;#【解】とか |
---|
131 |
$item{title} =~ s/\[.*?\]//g;#[二]とか |
---|
132 |
|
---|
133 |
|
---|
134 |
if ($item{title} eq ""){ |
---|
135 |
|
---|
136 |
$item{title} = $titlebackup; |
---|
137 |
} |
---|
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 |
}else{ |
---|
182 |
$item{category} = "etc"; |
---|
183 |
} |
---|
184 |
|
---|
185 |
|
---|
186 |
|
---|
187 |
|
---|
188 |
|
---|
189 |
}elsif(/<\/programme>/){ |
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
&replaceepg($item{'start'}, $item{'channel'},$item{'stop'}); |
---|
194 |
if ($item{'subtitle'} ne "" ){ |
---|
195 |
$registdesc = $item{'subtitle'}." ".$item{'desc'}; |
---|
196 |
}else{ |
---|
197 |
$registdesc = $item{'desc'}; |
---|
198 |
} |
---|
199 |
®istdb($item{'start'},$item{'stop'},$item{'channel'},$item{'title'},$registdesc ,$item{'category'}); |
---|
200 |
|
---|
201 |
|
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 |
|
---|
207 |
|
---|
208 |
|
---|
209 |
$item{start} = ""; |
---|
210 |
$item{stop} = ""; |
---|
211 |
$item{channel} = ""; |
---|
212 |
$item{title} = ""; |
---|
213 |
$item{subtitle} = ""; |
---|
214 |
$item{desc} = ""; |
---|
215 |
$item{category} = ""; |
---|
216 |
$registdesc = ""; |
---|
217 |
} |
---|
218 |
} |
---|
219 |
&commitdb; |
---|
220 |
|
---|
221 |
|
---|
222 |
|
---|
223 |
|
---|
224 |
|
---|
225 |
sub replaceepg{ |
---|
226 |
|
---|
227 |
my $foltiastarttime = $_[0]; |
---|
228 |
my $ontvepgchannel = $_[1]; |
---|
229 |
my $foltiaendtime = $_[2]; |
---|
230 |
my @data = (); |
---|
231 |
|
---|
232 |
$foltiastarttime = substr($foltiastarttime,0,12); |
---|
233 |
$foltiaendtime = substr($foltiaendtime,0,12); |
---|
234 |
|
---|
235 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.replaceepg.1'}); |
---|
236 |
my $now = &epoch2foldate(time()); |
---|
237 |
$sth->execute($foltiastarttime , $foltiaendtime , $ontvepgchannel); |
---|
238 |
while (@data = $sth->fetchrow_array()) { |
---|
239 |
push(@deleteepgid,$data[0]); |
---|
240 |
|
---|
241 |
} |
---|
242 |
|
---|
243 |
|
---|
244 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.replaceepg.2'}); |
---|
245 |
$sth->execute($foltiastarttime , $foltiaendtime , $ontvepgchannel); |
---|
246 |
while (@data = $sth->fetchrow_array()) { |
---|
247 |
push(@deleteepgid,$data[0]); |
---|
248 |
|
---|
249 |
} |
---|
250 |
|
---|
251 |
} |
---|
252 |
|
---|
253 |
sub registdb{ |
---|
254 |
my $foltiastarttime = $_[0]; |
---|
255 |
my $foltiaendtime = $_[1]; |
---|
256 |
my $channel = $_[2]; |
---|
257 |
my $title = $_[3]; |
---|
258 |
my $desc = $_[4]; |
---|
259 |
my $category = $_[5]; |
---|
260 |
|
---|
261 |
|
---|
262 |
$title = jcode($title)->tr('A-Za-z0-9!#$%&()*+,−./:;<=>?@[\]^_`{|} ','A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|} '); |
---|
263 |
$desc = jcode($desc)->tr('A-Za-z0-9!#$%&()*+,−./:;<=>?@[\]^_`{|} ','A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|} '); |
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 |
$foltiastarttime = substr($foltiastarttime,0,12); |
---|
269 |
$foltiaendtime = substr($foltiaendtime,0,12); |
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 |
|
---|
274 |
|
---|
275 |
|
---|
276 |
|
---|
277 |
|
---|
278 |
|
---|
279 |
|
---|
280 |
|
---|
281 |
|
---|
282 |
|
---|
283 |
|
---|
284 |
my $lengthmin = &calclength($foltiastarttime , $foltiaendtime); |
---|
285 |
|
---|
286 |
|
---|
287 |
push (@foltiastarttime,$foltiastarttime); |
---|
288 |
push (@foltiaendtime,$foltiaendtime); |
---|
289 |
push (@lengthmin,$lengthmin); |
---|
290 |
push (@channel,$channel); |
---|
291 |
push (@title,$title); |
---|
292 |
push (@desc,$desc); |
---|
293 |
push (@category,$category); |
---|
294 |
|
---|
295 |
|
---|
296 |
|
---|
297 |
|
---|
298 |
|
---|
299 |
|
---|
300 |
|
---|
301 |
} |
---|
302 |
|
---|
303 |
sub commitdb{ |
---|
304 |
$dbh->{AutoCommit} = 0; |
---|
305 |
|
---|
306 |
my $loopcount = @foltiastarttime; |
---|
307 |
my $i = 0; |
---|
308 |
|
---|
309 |
|
---|
310 |
foreach $delid (@deleteepgid){ |
---|
311 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.commitdb.1'}); |
---|
312 |
$sth->execute( $delid ) || warn "$delid\n"; |
---|
313 |
|
---|
314 |
} |
---|
315 |
|
---|
316 |
for ($i=0;$i<$loopcount;$i++){ |
---|
317 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.commitdb.2'}); |
---|
318 |
$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"; |
---|
319 |
|
---|
320 |
} |
---|
321 |
$dbh->commit; |
---|
322 |
$dbh->{AutoCommit} = 1; |
---|
323 |
} |
---|
324 |
|
---|
325 |
sub removetag(){ |
---|
326 |
my $str = $_[0]; |
---|
327 |
|
---|
328 |
|
---|
329 |
my $tag_regex_ = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}} |
---|
330 |
my $comment_tag_regex = |
---|
331 |
'<!(?:--[^-]*-(?:[^-]+-)*?-(?:[^>-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)'; |
---|
332 |
my $tag_regex = qq{$comment_tag_regex|<$tag_regex_}; |
---|
333 |
|
---|
334 |
|
---|
335 |
my $text_regex = q{[^<]*}; |
---|
336 |
|
---|
337 |
my $result = ''; |
---|
338 |
while ($str =~ /($text_regex)($tag_regex)?/gso) { |
---|
339 |
last if $1 eq '' and $2 eq ''; |
---|
340 |
$result .= $1; |
---|
341 |
$tag_tmp = $2; |
---|
342 |
if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) { |
---|
343 |
$str =~ /(.*?)(?:<\/$1(?![0-9A-Za-z])$tag_regex_|$)/gsi; |
---|
344 |
($text_tmp = $1) =~ s/</</g; |
---|
345 |
$text_tmp =~ s/>/>/g; |
---|
346 |
$result .= $text_tmp; |
---|
347 |
} |
---|
348 |
} |
---|
349 |
|
---|
350 |
|
---|
351 |
return $result ; |
---|
352 |
|
---|
353 |
} |
---|