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); |
---|
229 |
while (@data = $sth->fetchrow_array()) { |
---|
230 |
push(@deleteepgid,$data[0]); |
---|
231 |
|
---|
232 |
} |
---|
233 |
|
---|
234 |
|
---|
235 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.replaceepg.2'}); |
---|
236 |
$sth->execute($foltiastarttime , $foltiaendtime , $ontvepgchannel); |
---|
237 |
while (@data = $sth->fetchrow_array()) { |
---|
238 |
push(@deleteepgid,$data[0]); |
---|
239 |
|
---|
240 |
} |
---|
241 |
|
---|
242 |
} |
---|
243 |
|
---|
244 |
sub registdb{ |
---|
245 |
my $foltiastarttime = $_[0]; |
---|
246 |
my $foltiaendtime = $_[1]; |
---|
247 |
my $channel = $_[2]; |
---|
248 |
my $title = $_[3]; |
---|
249 |
my $desc = $_[4]; |
---|
250 |
my $category = $_[5]; |
---|
251 |
|
---|
252 |
|
---|
253 |
$title = jcode($title)->tr('A-Za-z0-9!#$%&()*+,−./:;<=>?@[\]^_`{|}','A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|}'); |
---|
254 |
$desc = jcode($desc)->tr('A-Za-z0-9!#$%&()*+,−./:;<=>?@[\]^_`{|}','A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_`{|}'); |
---|
255 |
|
---|
256 |
|
---|
257 |
$foltiastarttime = substr($foltiastarttime,0,12); |
---|
258 |
$foltiaendtime = substr($foltiaendtime,0,12); |
---|
259 |
|
---|
260 |
|
---|
261 |
|
---|
262 |
|
---|
263 |
|
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 |
|
---|
269 |
|
---|
270 |
|
---|
271 |
|
---|
272 |
|
---|
273 |
my $lengthmin = &calclength($foltiastarttime , $foltiaendtime); |
---|
274 |
|
---|
275 |
|
---|
276 |
push (@foltiastarttime,$foltiastarttime); |
---|
277 |
push (@foltiaendtime,$foltiaendtime); |
---|
278 |
push (@lengthmin,$lengthmin); |
---|
279 |
push (@channel,$channel); |
---|
280 |
push (@title,$title); |
---|
281 |
push (@desc,$desc); |
---|
282 |
push (@category,$category); |
---|
283 |
|
---|
284 |
|
---|
285 |
|
---|
286 |
|
---|
287 |
|
---|
288 |
|
---|
289 |
|
---|
290 |
} |
---|
291 |
|
---|
292 |
sub commitdb{ |
---|
293 |
$dbh->{AutoCommit} = 0; |
---|
294 |
|
---|
295 |
my $loopcount = @foltiastarttime; |
---|
296 |
my $i = 0; |
---|
297 |
|
---|
298 |
|
---|
299 |
foreach $delid (@deleteepgid){ |
---|
300 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.commitdb.1'}); |
---|
301 |
$sth->execute( $delid ) || warn "$delid\n"; |
---|
302 |
|
---|
303 |
} |
---|
304 |
|
---|
305 |
for ($i=0;$i<$loopcount;$i++){ |
---|
306 |
$sth = $dbh->prepare($stmt{'xmltv2foltia.commitdb.2'}); |
---|
307 |
$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"; |
---|
308 |
|
---|
309 |
} |
---|
310 |
$dbh->commit; |
---|
311 |
$dbh->{AutoCommit} = 1; |
---|
312 |
} |
---|
313 |
|
---|
314 |
sub removetag(){ |
---|
315 |
my $str = $_[0]; |
---|
316 |
|
---|
317 |
|
---|
318 |
my $tag_regex_ = q{[^"'<>]*(?:"[^"]*"[^"'<>]*|'[^']*'[^"'<>]*)*(?:>|(?=<)|$(?!\n))}; #'}}}} |
---|
319 |
my $comment_tag_regex = |
---|
320 |
'<!(?:--[^-]*-(?:[^-]+-)*?-(?:[^>-]*(?:-[^>-]+)*?)??)*(?:>|$(?!\n)|--.*$)'; |
---|
321 |
my $tag_regex = qq{$comment_tag_regex|<$tag_regex_}; |
---|
322 |
|
---|
323 |
|
---|
324 |
my $text_regex = q{[^<]*}; |
---|
325 |
|
---|
326 |
my $result = ''; |
---|
327 |
while ($str =~ /($text_regex)($tag_regex)?/gso) { |
---|
328 |
last if $1 eq '' and $2 eq ''; |
---|
329 |
$result .= $1; |
---|
330 |
$tag_tmp = $2; |
---|
331 |
if ($tag_tmp =~ /^<(XMP|PLAINTEXT|SCRIPT)(?![0-9A-Za-z])/i) { |
---|
332 |
$str =~ /(.*?)(?:<\/$1(?![0-9A-Za-z])$tag_regex_|$)/gsi; |
---|
333 |
($text_tmp = $1) =~ s/</</g; |
---|
334 |
$text_tmp =~ s/>/>/g; |
---|
335 |
$result .= $text_tmp; |
---|
336 |
} |
---|
337 |
} |
---|
338 |
|
---|
339 |
|
---|
340 |
return $result ; |
---|
341 |
|
---|
342 |
} |
---|