8 #Date_Init("TZ=JST","ConvTZ=JST");
13 use Algorithm::Diff qw(LCS);
16 use CGI::Carp qw( fatalsToBrowser warningsToBrowser );
18 use Data::Dumper::Concise;
35 use XML::Generator::DBI;
38 #%DB::packages = ( 'main' => 1 );
41 ################ バージョン定義 ################
44 my $rectool_version = 102;
47 ################ 初期化ここから ################
50 my $tz = DateTime::TimeZone->new( name => 'local' );
51 my $hires = Time::HiRes::time();
53 my $cfg = new Config::Simple;
54 if ( -e 'rec10.conf' ) {
55 $cfg->read( 'rec10.conf' );
57 elsif ( -e '/etc/rec10.conf' ) {
58 $cfg->read( '/etc/rec10.conf' );
61 die 'rec10.confが見つかりません。';
64 my $sql = $cfg->param( 'db.db' );
66 if ( $sql eq 'MySQL' ) {
67 my $name = $cfg->param( 'db.mysql_dbname' );
68 my $host = $cfg->param( 'db.mysql_host' );
69 my $port = $cfg->param( 'db.mysql_port' );
70 my $user = $cfg->param( 'db.mysql_user' );
71 my $pass = $cfg->param( 'db.mysql_passwd' );
72 $dbh = DBI->connect("dbi:mysql:$name:$host:$port", $user, $pass, {
75 mysql_enable_utf8 => 1, # only availavle for MySQL
77 $dbh->do( 'SET NAMES utf8' );
80 my $rec10_version = eval {
81 $dbh->selectrow_array( "SELECT version FROM in_status " );
86 $HTTP_HEADER = "Content-Type: text/html\n\n";
88 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
91 <title>Rec10%HTML_TITLE_OPT%</title>
92 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
93 <meta http-equiv="Content-Script-Type" content="text/javascript">
94 <meta http-equiv="Content-Style-Type" content="text/css">
95 <meta name="robots" content="noindex,nofollow,noarchive">
96 <link rev="made" href="Rea10">
97 <link rel="alternate" type="application/atom+xml" title= "Rec10 Atom Feed" href="./rectool.pl?mode=atom">
106 my ( $user, $pass, $auth );
107 ( $user, $pass ) = eval {
108 $dbh->selectrow_array( "SELECT webuser, webpass FROM in_settings " );
111 if ( $user and $pass ) {
112 if ( $ENV{'HTTP_AUTHORIZATION'} ) {
113 my ( $base64 ) = $ENV{'HTTP_AUTHORIZATION'} =~ /Basic\s(.*)/;
114 if ( $base64 eq encode_base64( "$user:$pass" ) ) {
130 my ( $base64 ) = $ENV{'REMOTE_USER'} =~ /Basic (.*)/;
131 $HTTP_HEADER = qq {Status: 401 Authorization Required\nWWW-Authenticate: Basic realm="Protected Rec10 $ENV{'HTTP_AUTHORIZATION'}"\n} . $HTTP_HEADER;
135 if ( $rec10_version != $rectool_version ) {
136 $HTML .= qq {<div style="font-size: 200%; font-weight: bold; color: red">\n};
138 if ( $rec10_version > $rectool_version ) {
139 $HTML .= qq {Rec10本体のバージョンが新しいため、実行できません。<br>\n};
140 $HTML .= qq {rectoolのバージョンアップを行ってください。<br>\n};
143 if ( $rec10_version < $rectool_version ) {
144 $HTML .= qq {Rec10本体のバージョンが古いため、実行できません。<br>\n};
145 $HTML .= qq {Rec10のバージョンアップを行ってください。<br>\n};
148 $HTML .= qq {Rec10のバージョンは$rec10_version 、rectoolのバージョンは$rectool_version です。<br>\n};
149 $HTML .= qq {<a href="http://sourceforge.jp/projects/rec10/">公式ページ</a>\n};
155 $mode = $params{ 'mode' };
156 $mode_sub = $params{ 'mode_sub' };
158 ################ %chtxt_chnameの準備 ################
162 tie %chtxt_0_chname, 'Tie::IxHash';
164 my $ary_ref = $dbh->selectall_arrayref(
165 "SELECT chtxt, chname, ch, bctype FROM epg_ch
171 %chtxt_chname = map { $_->[0], $_->[1] } @{$ary_ref};
175 my @te_ary = grep $_->[0]=~ /^\d/, @{$ary_ref};
176 my @bc_ary = grep $_->[0]!~ /^\d/, @{$ary_ref};
179 foreach my $line ( @te_ary ) {
180 # te xx_yyyy(chtxt) -> xx(ch)
181 if ( $line->[3] =~ /te/ ) {
182 push @{ $chtxt_0_chname{ $line->[2] . '_0'} }, $line->[1];
185 push @{ $chtxt_0_chname{'BS_' . $line->[2] } }, $line->[1];
188 foreach my $key ( keys %chtxt_0_chname ) {
189 my @chname = @{ $chtxt_0_chname{$key} };
190 if ( @chname >= 2 ) {
192 my @tmp = map { my @ary = split //, $_; \@ary } @chname;
195 $chtxt_0_chname{$key} = join '', LCS( $tmp[0], $tmp[1] );
199 $chtxt_0_chname{$key} = $chname[0];
204 foreach my $line ( @bc_ary ) {
205 $chtxt_0_chname{$line->[0]} = $line->[1];
210 ################ 定数宣言 ################
213 tie %type, 'Tie::IxHash';
215 'search_everyday' => '隔日検索',
216 'search_today' => '当日検索',
217 'reserve_flexible' => '浮動予約',
218 'reserve_fixed' => '確定予約',
220 'reserve_running' => '録画途中',
222 'convert_b25_ts' => '解読予約',
223 'convert_b25_ts_running' => '解読途中',
224 'convert_b25_ts_miss' => '解読失敗',
226 'convert_ts_mp4' => '縁故予約',
227 'convert_ts_mp4_running' => '縁故於鯖',
228 'convert_ts_mp4_network' => '縁故於網',
229 'convert_ts_mp4_finished' => '縁故完了',
231 'convert_avi_mkv' => '変換旧露',
232 'convert_avi_mp4' => '変換旧四',
233 'convert_mkv_mp4' => '変換露四',
234 'convert_mkv_mp4_runnings' => '換途露四',
236 'auto_suggest_dec' => '予測解読',
237 'auto_suggest_enc' => '予測縁故',
238 'auto_suggest_avi2fp' => '予測旧四',
239 'auto_suggest_ap2fp' => '予測露四',
241 'move_end' => '移動完了',
245 'auto_suggest_dec' => 'convert_b25_ts',
246 'auto_suggest_enc' => 'convert_ts_mp4',
247 'auto_suggest_avi2fp' => 'convert_avi_mkv',
248 'auto_suggest_ap2fp' => 'convert_mp4_mkv',
252 'search_everyday' => '#8B008B',
253 'search_today' => '#8B008B',
254 'reserve_flexible' => '#4169E1',
255 'reserve_fixed' => '#4169E1',
256 'reserve_running' => '#FF8C00',
257 'convert_b25_ts' => '#CD5C5C',
258 'convert_b25_ts_running' => '#DC143C',
259 'convert_ts_mp4' => '#32CD32',
260 'convert_ts_mp4_running' => '#2E8B57',
261 'convert_ts_mp4_network' => '#808000',
263 'other' => '#A0A0A0',
266 $type_user_made = "( 'search_everyday', 'search_today', 'reserve_flexible', 'reserve_fixed', 'reserve_running' )";
268 tie %category, 'Tie::IxHash';
270 'news' => { name => 'ニュース・報道' , color => '#ff0000' },
271 'sports' => { name => 'スポーツ' , color => '#ff8000' },
272 'information' => { name => '情報' , color => '#ffff00' },
273 'drama' => { name => 'ドラマ' , color => '#80ff00' },
274 'music' => { name => '音楽' , color => '#00ff00' },
275 'variety' => { name => 'バラエティ' , color => '#00ff80' },
276 'cinema' => { name => '映画' , color => '#00ffff' },
277 'anime' => { name => 'アニメ・特撮' , color => '#0080ff' },
278 'documentary' => { name => 'ドキュメンタリー・教養' , color => '#0000ff' },
279 'stage' => { name => '演劇' , color => '#8000ff' },
280 'hobby' => { name => '趣味・実用' , color => '#ff00ff' },
281 'etc' => { name => 'その他' , color => '#ff0080' },
284 ################ 初期化ここまで ################
287 ################ mode=schedule ################
289 if ( $mode eq 'schedule' ) {
291 $HTML =~ s/%HTML_TITLE_OPT%/ - Schedule Viewer/;
292 #$HTML =~ s|%REFRESH%|<meta http-equiv="refresh" content="300">|;
294 <style type="text/css">
300 $css =~ s/^\t{2}//gm;
301 $HTML =~ s/%CSS%/$css/;
303 my $order = $params{ 'order' };
304 my $extra = $params{ 'extra' };
305 if ( $order ne 'id' ) {
308 $reverse_extra = $extra ? '' : '&extra=1';
309 $forward_order = $order eq 'btime' ? '' : '&order=id';
311 my $ary_ref = $dbh->selectall_arrayref(
312 "SELECT id, type, timeline.chtxt, epg_ch.chname, title, btime, etime, opt, deltaday, deltatime,
313 epgtitle, epgbtime, epgetime, epgexp, epgduplicate, epgchange, counter
315 LEFT OUTER JOIN epg_ch ON timeline.chtxt = epg_ch.chtxt
319 $HTML .= qq {<div style="font-size: 80%; float: left">\n};
320 $HTML .= qq {<form method="get" action="rectool.pl">\n};
321 $HTML .= qq {<div>\n};
322 $HTML .= qq {<input type="hidden" name="mode" value="change">\n};
323 $HTML .= qq {<table summary="rectimetable" border=1 cellspacing=0>\n<tr>\n};
324 $HTML .= qq {<th><a href="rectool.pl?mode=schedule$forward_order$reverse_extra">■</a></th>\n};
325 $HTML .= qq {<th><a href="rectool.pl?mode=schedule&order=id">ID</a></th>\n};
326 $HTML .= qq {<th>タイプ</th>\n};
327 $HTML .= qq {<th>チャンネル</th>\n};
328 $HTML .= qq {<th>タイトル</th>\n};
329 $HTML .= qq {<th><a href="rectool.pl?mode=schedule">開始時刻</a></th>\n};
330 $HTML .= qq {<th>終了時刻</th>\n};
331 $HTML .= qq {<th>録画時間</th>\n};
332 $HTML .= qq {<th>オプション</th>\n};
333 $HTML .= qq {<th>dd</th>\n};
334 $HTML .= qq {<th>dt</th>\n};
335 $HTML .= qq {<th>残り</th>\n};
336 $HTML .= qq {</tr>\n};
337 foreach my $line ( @{ $ary_ref } ) {
339 $type = $type{$line->{type}} || $line->{type};
340 if ( $line->{type} =~ /^search/ ) {
341 $type = qq {<span style="color: #8B008B">$type</span>};
342 $line->{deltaday} = qq {<span style="color: #FF0000">空</span>} if ( !$line->{deltaday} && $line->{type} eq 'search_everyday' );
343 $line->{deltatime} = qq {<span style="color: #FF0000">空</span>} if ( !$line->{deltatime} );
346 my $color = $color{$line->{type}} ? $color{$line->{type}} : $color{'other'};
347 $type = qq {<span style="color: $color">$type</span>};
349 # 地上波の場合、xx_yyyをxx_0に置換する
350 ( $line->{chtxt_0} = $line->{chtxt} ) =~ s/(\d+)_/$1_0/;
351 # chnameが無いとき(移動縁故など)、chtxtを代わりに使う
354 $chtxt_0_chname{$line->{chtxt}} ||
355 $chtxt_0_chname{$line->{chtxt_0}};
356 if ( !$line->{chname} ) {
357 # chnameが無いとき、リンクを作成しない
358 $line->{chname} = $line->{chtxt};
359 $line->{chname_link} = qq {$line->{chname}</a>};
362 $line->{chname_link} = qq {<a href="rectool.pl?mode=program&chtxt=$line->{chtxt}">$line->{chname}</a>};
364 $line->{title} = 'タイトルなし' if ( !$line->{title} );
365 $line->{tr_style} = '';
366 $line->{title_2} = '';
367 my $unix_b = str2datetime( $line->{btime} );
368 my $unix_e = str2datetime( $line->{etime} );
370 my $btime = $unix_b->strftime( '%Y%m%d%H%M%S' );
371 my $etime = $unix_e->strftime( '%Y%m%d%H%M%S' );
372 if ( $extra and $line->{type} =~ /^search_|^reserve_(?!running)/ ) {
373 #my @ary = $dbh->selectrow_array(
374 # "SELECT title, exp FROM epg_timeline
375 # WHERE channel = '$line->{chname}'
376 # AND start = '$btime'
377 # AND stop = '$etime' ");
378 #my @ary = ( $line->{epgtitle}, $line->{epgexp} );
379 my ( $epgtitle, $epgexp ) = ( $line->{epgtitle}, $line->{epgexp} );
382 $epgtitle =~ s/無料≫//;
384 if ( $epgtitle ne $line->{title} ) {
385 # epgtitleとtitleが一致しない
387 my @brackets = $line->{title} =~ /(\[.+\])+/;
388 my $epgtitle_nobrackets = $epgtitle;
389 my $title_nobrackets = $line->{title};
390 if ( @brackets && $epgtitle =~ /(\[.+\])+/ >= @brackets ) {
391 foreach ( @brackets ) {
392 $epgtitle_nobrackets =~ s/\Q$_\E//;
395 $title_nobrackets =~ s/(\[.+\])+//;
396 if ( !scalar $epgtitle_nobrackets =~ s/\Q$title_nobrackets\E// ) {
397 # epgtitleにtitleが含まれていない
398 my $href = qq {<a href="rectool.pl?mode=edit&id=$line->{id}&suggest=auto">自動検索</a>};
399 $epgtitle = qq {<span style="color: #FF4000">$epgtitle■$href■</span>};
402 # epgtitleにtitleが含まれている
403 $epgtitle = $epgtitle_nobrackets;
407 # epgtitleとtitleが一致している
411 $line->{title_2} = qq {<div style="float: right; cursor: help" title="$epgexp">$epgtitle</div>};
415 my $href = qq {<a href="rectool.pl?mode=edit&id=$line->{id}&suggest=auto">自動検索</a>};
416 $line->{title_2} = qq {<span style="float: right; color: #FF0000">■$href■</span>};
417 $line->{tr_style} = qq {style="background-color: #A0A0A0"};
421 my ( $begin, $end, $diff ) = &str2readable( $unix_b, $unix_e );
425 $line->{type} eq 'reserve_running'
427 $unix_b->epoch <= time && time <= $unix_e->epoch
430 $percent = int( ( 100 * ( time - $unix_b->epoch ) ) / ( $unix_e->epoch - $unix_b->epoch ) );
431 $hr .= qq {<hr style="margin: 0 auto 0 0; height: 4px; width: $percent%;};
432 $hr .= qq { background-color: blue; border: none" title="$percent%">};
435 $line->{title} = qq {<a href="rectool.pl?mode=edit&id=$line->{id}">$line->{title}</a>};
436 #$line->{title} = qq {<div style="float: left">$line->{title}</div>} if ( $line->{title_2} );
437 $HTML .= qq {<tr align="center" $line->{tr_style}>\n};
438 $HTML .= qq {<td><input type="checkbox" name="id" value="$line->{id}"></td>\n};
439 $HTML .= qq {<td>$line->{id}</td>\n};
440 $HTML .= qq {<td>$type</td>\n};
441 $HTML .= qq {<td>$line->{chname_link}</td>\n};
442 $HTML .= qq {<td align="left" style="white-space: normal">$line->{title}$line->{title_2}</td>\n};
443 $HTML .= qq {<td>$begin</td>\n<td>$end</td>\n};
444 $HTML .= qq {<td>$hr$diff</td>\n};
445 $HTML .= qq {<td>$line->{opt}</td>\n<td>$line->{deltaday}</td>\n<td>$line->{deltatime}</td>\n<td>$line->{counter}</td>\n};
446 $HTML .= qq {</tr>\n};
448 $HTML .= qq {</table>\n};
449 #$HTML .= qq {<input type="submit" name="edit" value="編集(要JS)">\n};
450 $HTML .= qq {<input type="submit" name="delete" value="削除">\n</div>\n</form>\n};
454 ################ mode=graph ################
456 if ( $mode eq 'graph' ) {
458 my $date = $params{ 'date' };
462 print "Content-Type: image/svg+xml\n\n";
464 $date = Date::Simple->new( split /-/, $date );
465 $graph_bgn = $date->format('%Y-%m-%d');
466 $graph_end = $date->next->format('%Y-%m-%d');
468 $today = $date eq Date::Simple->today() ? 1 : 0;
470 $tuner{terrestrial} = $cfg->param( 'env.te_max' );# 2;
471 $tuner{satellite} = $cfg->param( 'env.bscs_max' );# 2;
472 $tuner{all} = $tuner{terrestrial} + $tuner{satellite};
474 $width = 30 * $hours;
475 my %category_color = map { $_->{name}, $_->{color} } values %category;
477 $svg = new SVG( width => 820, height => $tuner{all} * 20 + 40 );
478 $svg->rectangle( 'x' => 40, 'y' => 20,
479 width => $width + 20, height => $tuner{all} * 20 + 10,
481 style => { stroke => 'blue', fill => 'white' } );
482 for ( 1..$tuner{terrestrial} ) {
483 $svg->text( 'x' => 10, 'y' => ( $_ + 1 ) * 20 )
486 for ( 1..$tuner{satellite} ) {
487 $svg->text( 'x' => 10, 'y' => ( $_ + $tuner{terrestrial} + 1 ) * 20 )
491 $svg->text( 'x' => $_ * 30 + 65, 'y' => 15,
492 style => { 'text-anchor' => 'middle' } )
493 ->cdata( sprintf( '%02d', $_ ) ) if ( $_ < $hours );
494 # $svg->line( ); # can't be used when required
495 $svg->tag( 'line', x1 => $_ * 30 + 50, x2 => $_ * 30 + 50, y1 => 30, y2 => $tuner{all} * 20 + 20,
496 style => { stroke => 'gray' } );
498 for ( 1..$tuner{all} ) {
499 # $svg->tag( 'line', x1 =>50, x2 => 50 + $width, y1 => $_ * 20 + 10, y2 => $_ * 20 + 10,
500 # style => { stroke => 'gray' } );
501 # $svg->rectangle( 'x' => 50, 'y' => $_ * 20 + 10, width => $width, height => 10 );
502 $svg->rectangle( 'x' => 50, 'y' => $_ * 20 + 14, width => $width, height => 2 );
505 my $time = Time::Piece->localtime;
506 my $x = ( $time->hour * 60 + $time->minute ) * 0.5 + 50;
507 $svg->tag( 'line', x1 => $x, x2 => $x, y1 => 30, y2 => $tuner{all} * 20 + 20,
508 style => { stroke => 'red', 'fill-opacity' => '1.0' } );
510 my $ary_ref = $dbh->selectall_arrayref(
511 # epg_timeline.channel = timeline.chtxt &&
512 "SELECT id, title, chtxt, btime, etime, epgcategory, opt FROM timeline
513 WHERE type IN $type_user_made
516 '$graph_bgn 00:00' <= btime AND btime < '$graph_end 00:00'
518 '$graph_bgn 00:00' < etime AND etime <= '$graph_end 00:00'
524 foreach my $bctype ( '\d+_', 'S_' ) {
525 my $tuner = $bctype eq '\d+_' ? $tuner{terrestrial} : $tuner{satellite};
526 my @ary_ref = grep { $_->{chtxt} =~ /$bctype/ } @{ $ary_ref };
527 my @y_drawn = ('') x $tuner;
528 foreach my $line ( @ary_ref ) {
529 @start = $line->{btime} =~ /(.{4})-(.{2})-(.{2}) (.{2}):(.{2})/;
530 @stop = $line->{etime} =~ /(.{4})-(.{2})-(.{2}) (.{2}):(.{2})/;
531 $start = ( ( $day == $start[2] ? 0 : 24 * 60 ) + $start[3] * 60 + $start[4] ) * 0.5;
532 $stop = ( ( $day == $stop [2] ? 0 : 24 * 60 ) + $stop [3] * 60 + $stop [4] ) * 0.5;
533 $start = 0 if ( $start < 0 || $day > $start[2] ); # 月の変わり目はスルー
534 $stop = $width if ( $stop > $width );
535 $begin = $line->{btime};
536 $end = $line->{etime};
538 my @ary = grep { ( $_->{etime} cmp $line->{btime} ) > 0 and ( $_->{btime} cmp $line->{etime} ) < 0 and $_->{id} != $line->{id} } @ary_ref;
539 foreach my $i ( 0..$tuner - 1 ) {
540 next if ( ( $y_drawn[$i] cmp $line->{btime} ) > 0 );
541 #for ( 'chtxt', 'btime', 'etime' ) {
542 # $f = 0 if ( $line->{$_} ne $ary[$i]->{$_} );
545 $y_drawn[$i] = $line->{etime};
548 my ( $r, $g, $b ) = ( 0, 0, 0 );
549 $r += 255 if ( $line->{opt} =~ /a/ );
550 $g += 255 if ( $line->{opt} =~ /H/ );
551 $b += 255 if ( $line->{opt} =~ /I/ );
552 if ( $r + $g + $b == 255 * 3 ){
557 if ( $r + $g + $b == 0 ){
560 my %escaped = ( '&' => 'amp', '<' => 'lt', '>' => 'gt', '"' => 'quot' );
562 my $str = shift or return;
564 $result .= $escaped{$_} ? '&' . $escaped{$_} . ';' : $_
565 for (split //, $str);
569 -href => "rectool.pl?mode=edit&id=$line->{id}",
571 -title => html_escape( $line->{title} ),
574 'y' => 30 + ( $bctype eq '\d+_' ? 0 : $tuner{terrestrial} * 20 ) + $line->{slot} * 20,
575 width => $stop - $start,
577 style => { fill => $category_color{$line->{epgcategory}} || $category_color{'その他'} } );
578 #style => { fill => "rgb($r,$g,$b)" } );
581 my $xml = $svg->xmlify;
582 utf8::encode( $xml );
584 #warningsToBrowser(true);
589 $HTML =~ s/%HTML_TITLE_OPT%/ - Schedule Viewer - Graphical/;
590 $HTML .= qq {<div style="float: left">\n};
591 # $base64 = encode_base64( $svg->xmlify );
592 # $HTML .= qq {<object data="data:image/svg+xml;base64,$base64">\n</object>\n};
593 $HTML .= qq {予約状況一覧です。T1,T2は地上波、S1,S2はBS/CSを示しています。<br>\n};
594 $HTML .= qq {SVGが利用可能なブラウザでご覧ください。<br>\n};
595 $HTML .= qq {色とジャンルの対応\n};
597 $HTML .= qq {<span style="background: $_->{color}; top: 10px; left: 250px;">$_->{name}</span>\n};
599 $HTML .= qq {<br>\n};
601 $ary_ref = $dbh->selectcol_arrayref(
602 "SELECT DISTINCT DATE( btime )
604 WHERE type in $type_user_made
607 foreach my $date ( @{ $ary_ref } ) {
608 my @date = $date =~ /(.{4})-(.{2})-(.{2})/;
609 my $dn = DateTime->new( year => $date[0], month => $date[1], day => $date[2], locale => 'ja_JP' )->day_name;
610 #utf8::encode( $dn );
611 $HTML .= qq {$date[1]/$date[2]($dn)の予約状況<br>\n};
613 $HTML .= qq {<object type="image/svg+xml" data="rectool.pl?mode=graph&date=$date" width="820">\n};
614 $HTML .= qq {SVG Image $date\n</object>\n<br>\n};
616 $date2 = Date::Simple->new( @date )->next->format('%Y-%m-%d');
617 my $ary_ref = $dbh->selectall_arrayref(
618 "SELECT chtxt, title, btime, etime FROM timeline
619 WHERE '$date 00:00' <= btime AND etime <= '$date2 01:00'
623 foreach my $line ( @{ $ary_ref } ) {
624 #$HTML .= qq {$line->[0] $line->[1] $line->[2] $line->[3]<br>\n};
633 ################ mode=atom ################
635 if ( $mode eq 'atom' ) {
636 my $recording_count = $encoding_count = $jbk_count = 0;
637 my $ary_ref = $dbh->selectall_arrayref(
638 "SELECT chtxt, title, btime, etime, opt
640 WHERE type = 'reserve_running' ");
641 foreach my $line ( @{$ary_ref} ) {
642 my ( $begin, $end, $diff ) = &str2readable( $line->[2], $line->[3] );
643 $recording_status .= qq {$line->[0] $line->[1] $begin - $end $diff $line->[4]<br />\n};
646 $ary_ref = $dbh->selectall_arrayref(
647 "SELECT chtxt, title, btime, etime, opt
649 WHERE type = 'convert_ts_mp4_running' ");
650 foreach my $line ( @{$ary_ref} ) {
651 my ( $begin, $end, $diff ) = &str2readable( $line->[2], $line->[3] );
652 $encoding_status .= qq {$line->[0] $line->[1] $begin - $end $diff $line->[4]<br />\n};
655 $ary_ref = $dbh->selectall_arrayref(
656 "SELECT id, chtxt, title, btime, etime
657 FROM auto_timeline_keyword " );
658 foreach my $line ( @{$ary_ref} ) {
659 my ( $begin, $end, $diff ) = &str2readable( $line->[3], $line->[4] );
660 $jbk_status .= qq {$line->[0] $line->[1] $line->[2] $begin - $end $diff<br />\n};
664 my $feed = XML::Atom::Feed->new( Version => 1.0 );
665 $feed->title('Rec10 フィード');
667 my $entry = XML::Atom::Entry->new( Version => 1.0 );
668 $entry->title("Rec10 録画状況 ($recording_count)");
669 $entry->id('tag:recording_status');
670 $entry->content($recording_status);
671 $entry->add_link(str_to_link( './rectool.pl?mode=schedule' ) );
672 $feed->add_entry($entry);
674 $entry = XML::Atom::Entry->new( Version => 1.0 );
675 $entry->title("Rec10 縁故状況 ($encoding_count)");
676 $entry->id('tag:encoding_status');
677 $entry->content($encoding_status);
678 $entry->add_link(str_to_link( './rectool.pl?mode=schedule' ) );
679 $feed->add_entry($entry);
681 $entry = XML::Atom::Entry->new( Version => 1.0 );
682 $entry->title("Rec10 地引状況 ($jbk_count)");
683 $entry->id('tag:jbk_status');
684 $entry->content($jbk_status);
685 $entry->add_link(str_to_link( './rectool.pl?mode=jbk' ) );
686 $feed->add_entry($entry);
688 my $xml = $feed->as_xml;
689 print "Content-Type: application/atom+xml\n\n";
694 my $link = XML::Atom::Link->new( Version => 1.0 );
695 $link->type('text/html');
696 $link->rel('alternate');
702 ################ mode=edit ################
704 if ( $mode eq 'edit' ) {
705 my $id = $params{ 'id' };
707 $HTML =~ s/%HTML_TITLE_OPT%/ - Schedule Editor/;
708 $HTML .= qq {<div style="float: left">\n};
711 <script type="text/javascript" src="http://www.enjoyxstudy.com/javascript/dateformat/dateformat.js">
713 <script type="text/javascript">
714 function setType(value){
715 var index = document.reserve.type.selectedIndex;
716 var value = document.reserve.type[index].value;
717 if ( value == 'search_everyday' ) {
718 document.reserve.deltaday.value = 7;
719 document.reserve.deltatime.value = 3;
721 if ( value == 'convert_b25_ts' || value == 'convert_ts_mp4' ){
722 var date = new Date();
723 var dateFormat = new DateFormat("yyyy-MM-dd HH:mm:ss");
724 var minutes = date.getMinutes();
725 minutes = minutes - minutes % 5 + 10;
726 date.setMinutes(minutes, 0, 0);
727 document.reserve.begin.value = dateFormat.format(date);
728 date.setSeconds( date.getSeconds() + 3600 );
729 document.reserve.end.value = dateFormat.format(date);
732 function setSuggest(start, stop){
733 document.reserve.begin.value = start;
734 document.reserve.end.value = stop;
736 function shiftEndTime(value){
737 var dateFormat = new DateFormat("yyyy-MM-dd HH:mm:ss");
738 var date = dateFormat.parse(document.reserve.end.value || document.reserve.begin.value);
739 date.setSeconds( date.getSeconds() + value );
740 document.reserve.end.value = dateFormat.format(date);
744 $script =~ s/^\t{2}//gm;
745 $HTML =~ s/%SCRIPT%/$script/;
747 $HTML .= "スケジュール編集画面です。<br>\n";
748 $HTML .= "実装がとても適当なので、利用には細心の注意を払ってください。<br>\n<br>\n";
752 $button_bgn = $button_end = '';
756 $type = 'reserve_flexible';
758 $datetime_now = DateTime->now( time_zone => $tz )->set_second( 0 )->add( minutes => 1)->strftime( '%Y-%m-%d %H:%M:%S' );
759 $button_bgn = qq{<button type="button" onClick="document.reserve.begin.value='$datetime_now'">現在</button>\n<br>\n};
761 qq{<button type="button" onClick="document.reserve.end.value=document.reserve.begin.value">一致</button>}
762 .qq{<button type="button" onClick="shiftEndTime(300);">+5m</button>}
763 .qq{<button type="button" onClick="shiftEndTime(1800);">+30m</button>};
766 if ( $params{ 'suggest' } eq 'auto' ) {
767 my @btime = $begin =~ /(.{4})-(.{2})-(.{2}) (.{2}):(.{2}):(.{2})/;
768 my @etime = $end =~ /(.{4})-(.{2})-(.{2}) (.{2}):(.{2}):(.{2})/;
769 my $btime = DateTime->new(
770 year => $btime[0], month => $btime[1], day => $btime[2],
771 hour => $btime[3], minute => $btime[4], second => $btime[5],
773 my $etime = DateTime->new(
774 year => $etime[0], month => $etime[1], day => $etime[2],
775 hour => $etime[3], minute => $etime[4], second => $etime[5],
777 my %hash = &sqlgetsuggested( $btime, $etime );
779 $HTML .= qq {可能性のある番組<br>\n};
780 $HTML .= qq {<table summary="suggesttable" border=1 cellspacing=0>\n<tr>\n};
781 $HTML .= qq {<th>優先度</th>\n};
782 $HTML .= qq {<th>タイトル</th>\n};
783 $HTML .= qq {<th>開始時刻</th>\n};
784 $HTML .= qq {<th>終了時刻</th>\n};
785 $HTML .= qq {<th>説明</th>\n};
786 $HTML .= qq {<th>適用</th>\n};
787 $HTML .= qq {</tr>\n};
789 foreach my $key (sort keys %hash){
790 my $val = $hash{$key};
791 foreach my $val ( @{$val} ) {
792 my $style = qq {style="white-space: nowrap"};
793 $val->[0] =~ s/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/$1-$2-$3 $4:$5:$6/;
794 $val->[1] =~ s/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/$1-$2-$3 $4:$5:$6/;
795 $HTML .= qq {<tr>\n<td>$key</td>\n<td>$val->[2]</td>\n};
796 $HTML .= qq {<td $style>$val->[0]</td>\n<td $style>$val->[1]</td>\n<td>$val->[3]</td>\n};
797 $HTML .= qq {<td><button onClick="setSuggest('$val->[0]','$val->[1]');">適用</button></td>\n</tr>\n};
800 $HTML .= qq {</table>\n<br>\n};
803 my $len = length $id;
804 $HTML .= qq {<form method="get" action="rectool.pl" name="reserve">\n};
805 $HTML .= qq {<input type="hidden" name="mode" value="change">\n};
806 $HTML .= qq {<input type="hidden" name="mode_sub" value="update">\n};
807 $HTML .= qq {<input type="hidden" name="id" value="$id">\n};
808 $HTML .= qq {ID\n<input type="text" name="id" value="$id" size=$len disabled>\n};
809 $HTML .= qq {タイプ\n<select name="type" onChange="setType();">\n};
810 foreach my $key ( keys %type ) {
811 next if ( $key !~ /^search|^reserve_flexible$|^reserve_fixed$|^convert_b25_ts$|^convert_ts_mp4$|^$type$/ );
812 $value = $type{$key};
813 if ( $key eq $type ) {
814 $HTML .= qq {<option value="$key" selected>$value</option>\n};
817 $HTML .= qq {<option value="$key">$value</option>\n};
820 $HTML .= qq {</select>\n};
822 $HTML .= qq {チャンネル\n<select name="chtxt">\n};
823 # 移動縁故など、チャンネルリスト内にchtxtが存在しない場合に備えて
824 $chtxt_0_chname{$chtxt} = $chname || $chtxt if ( !$chtxt_0_chname{$chtxt} );
825 foreach my $key ( sort keys %chtxt_0_chname ) {
826 if ( $key eq $chtxt || $key eq $chtxt_0 ) {
827 $HTML .= qq {<option value="$key" selected>$chtxt_0_chname{$key}</option>\n};
830 $HTML .= qq {<option value="$key">$chtxt_0_chname{$key}</option>\n};
833 $HTML .= qq {</select><br>\n};
834 $HTML .= qq {タイトル\n<input type="text" name="title" value="$title" size=64><br>\n};
835 $HTML .= qq {開始時刻\n<input type="text" name="begin" value="$begin" maxlength=19 size=24>\n};
836 $HTML .= $button_bgn;
837 $HTML .= qq {終了時刻\n<input type="text" name="end" value="$end" maxlength=19 size=24>\n};
838 $HTML .= $button_end . "<br>\n";
839 $HTML .= qq {隔日周期\n<input type="text" name="deltaday" value="$deltaday" maxlength=2 size=2 >\n};
840 $HTML .= qq {時刻誤差\n<input type="text" name="deltatime" value="$deltatime" maxlength=2 size=2 >\n};
841 $HTML .= qq {オプション\n<input type="text" name="opt" value="$opt">\n};
842 $HTML .= qq {回数\n<input type="text" name="counter" value="$counter" size=2 >\n};
843 $HTML .= qq {<input type="submit" name="update" value="更新">\n</form>\n};
846 ################ mode=change ################
848 if ( $mode eq 'change' ) {
849 @id = $q->param( 'id' );
851 $HTML =~ s/%HTML_TITLE_OPT%/ - Change/;
852 $HTML .= qq {<div style="float: left">\n};
854 if ( $params{ 'delete' } )
857 foreach my $id ( @id ) {
858 $dbh->do( "DELETE FROM timeline WHERE id = '$id'" );
860 $HTML .= "削除しました。<br>\n5秒後に予約確認画面に移動します。<br>\n";
861 $HTML =~ s|%REFRESH%|<meta http-equiv="refresh" content="5; url=rectool.pl?mode=schedule">|;
865 if ( $params{ 'update' } )
867 $type = $params{ 'type' };
868 $chtxt = $params{ 'chtxt' };
869 $title = $params{ 'title' };
870 $begin = $params{ 'begin' };
871 $end = $params{ 'end' };
872 $deltaday = $params{ 'deltaday' };
873 $deltatime = $params{ 'deltatime' };
874 $opt = $params{ 'opt' };
875 $counter = $params{ 'counter' };
879 "UPDATE timeline SET type = '$type', chtxt = '$chtxt', title = '$title',
880 btime = '$begin', etime = '$end',
881 deltaday = '$deltaday', deltatime = '$deltatime', opt = '$opt', counter = '$counter'
887 "INSERT INTO timeline ( type, chtxt, title, btime, etime, deltaday, deltatime, opt, counter )
888 VALUES ( '$type', '$chtxt', '$title', '$begin', '$end', '$deltaday', '$deltatime', '$opt', '$counter' )"
891 $HTML .= "更新しました。<br>\n5秒後に予約確認画面に移動します。<br>\n";
892 $HTML =~ s|%REFRESH%|<meta http-equiv="refresh" content="5; url=rectool.pl?mode=schedule">|;
895 if ( $mode_sub eq 'proc' ) {
896 my $type = $params{ 'type' };
897 my $chtxt = $params{ 'chtxt' } || 'nhk-k';
898 my $title = $params{ 'title' };
899 my @opt = $q->param( 'opt' );
900 my $opt = join '', @opt;
902 my $datetime_now = DateTime->now( time_zone => $tz )->set_second( 0 )->add( minutes => 10);
903 my $sql_type = $type_suggest{$type};
904 my $begin = $datetime_now->strftime( '%Y-%m-%d %H:%M:%S' );
905 $datetime_now = $datetime_now->add( minutes => 60 );
906 my $end = $datetime_now->strftime( '%Y-%m-%d %H:%M:%S' );
909 "INSERT INTO timeline ( type, chtxt, title, btime, etime, opt )
910 VALUES ( '$sql_type', '$chtxt', '$title', '$begin', '$end', '$opt' )"
915 if ( $mode_sub eq 'move' ) {
916 my $mode_sub2 = $params{ 'mode_sub2' };
917 my $title = $params{ 'title' };
920 $ENV{'LANG'} = 'ja_JP.UTF-8';
921 if ( $mode_sub2 eq 'predict' ) {
922 $HTML .= "移動後のシミュレーション結果です。\n<br>";
923 eval '$response = `python26 ' . $cfg->param( 'path.rec10' ) . "/classify.py -s '$title'`";
925 elsif ( $mode_sub2 eq 'exec' ) {
926 eval '$response = `python26 ' . $cfg->param( 'path.rec10' ) . "/classify.py -e '$title'`";
928 utf8::decode( $response );
933 if ( $mode_sub eq 'setting' ) {
934 my $jbk = $params{ 'jbk' } || '0';
935 my $bayes = $params{ 'bayes' } || '0';
936 my $del_tmp = $params{ 'del_tmp' } || '0';
937 my $opt = $params{ 'opt' } || '';
938 my $user = $params{ 'user' } || '';
939 my $pass = $params{ 'pass' } || '';
942 "UPDATE in_settings SET auto_jbk = '$jbk', auto_bayes = '$bayes',
943 auto_del_tmp = '$del_tmp', auto_opt = '$opt'"
948 if ( $mode_sub eq 'fixstatus' ) {
949 my $key = $params{ 'terec' } ? 'terec' : $params{ 'bscsrec' } ? 'bscsrec' :
950 $params{ 'b252ts' } ? 'b252ts' : $params{ 'ts2avi' } ? 'ts2avi' : '';
953 "UPDATE in_status SET $key = 0"
961 ################ mode=confirm ################
963 if ( $mode eq 'confirm' ) {
964 if ( $mode_sub eq 'reserve' ) {
965 $HTML =~ s/%HTML_TITLE_OPT%/ - Reserver/;
966 $HTML .= qq {<div style="float: left">\n};
969 my $duration = ( str2datetime( $end ) - str2datetime( $begin ) )->delta_minutes;
970 $HTML .= "番組名:$title<br>\nチャンネル:$chname<br>\n放送継続時間:$duration 分<br>\n番組内容:$desc<br>\nジャンル:$category<br>\n";
972 $longdesc =~ s/\\n/<br>\n/gs;
973 $HTML .= "番組内容(長):$longdesc<br>\n";
975 my $error = &check_error();
980 $ary_ref = $dbh->selectall_arrayref(
981 "SELECT start, stop FROM epg_timeline WHERE channel = '$chtxt' AND title = '$title' "
984 $HTML .= "同一の番組の他の放送予定です。<br>\n";
985 foreach my $line ( @{$ary_ref} ) {
988 $begin =~ s/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/$1-$2-$3 $4:$5:$6/;
989 $end =~ s/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/$1-$2-$3 $4:$5:$6/;
990 $overlap = &get_overlap() >= 2 ? '不可能' :
991 qq {<a href="rectool.pl?mode=confirm&mode_sub=reserve&chtxt=$chtxt&start=$line->[0]&stop=$line->[1]">可能</a>};
992 $HTML .= "開始:$begin\n終了:$end\n録画は$overlap<br>\n";
997 $HTML .= "録画予約の詳細設定を行ってください。<br>\n";
998 $HTML .= qq {<form method="get" action="rectool.pl">\n};
999 $HTML .= qq {<input type="hidden" name="mode" value="reserve">\n};
1000 $HTML .= qq {<input type="hidden" name="chtxt" value="$chtxt">\n};
1001 $HTML .= qq {<input type="hidden" name="start" value="$start">\n};
1002 $HTML .= qq {<input type="hidden" name="stop" value="$stop">\n};
1003 $HTML .= qq {<input type="hidden" name="title" value="$title">\n} if ( $params{ 'title' } );
1004 &draw_form_opt( 'reserve' );
1005 $HTML .= qq {<input type="submit" value="予約">\n</form>\n};
1009 # End of $mode_sub eq 'reserve';
1011 if ( $mode_sub eq 'proc' ) {
1012 my $type = $params{ 'type' };
1013 local $chtxt = $params{ 'chtxt' };
1014 my $title = $params{ 'title' };
1015 local $opt = $params{ 'opt' };
1016 utf8::decode( $title );
1018 $HTML .= "詳細設定を行ってください。<br>\n";
1019 $HTML .= "タイトル:$title\n<br>\n";
1021 $HTML .= qq {<form method="get" action="rectool.pl">\n};
1022 $HTML .= qq {<input type="hidden" name="mode" value="change">\n};
1023 $HTML .= qq {<input type="hidden" name="mode_sub" value="proc">\n};
1024 $HTML .= qq {<input type="hidden" name="type" value="$type">\n};
1025 $HTML .= qq {<input type="hidden" name="title" value="$title">\n};
1026 &draw_form_channel( 'nonone' );
1028 $HTML .= qq {<input type="submit" value="予約">\n</form>\n};
1033 ################ mode=reserve ################
1035 if ( $mode eq 'reserve' ) {
1036 $HTML .= qq {<div style="float: left">\n};
1038 $title = $params{ 'title' } if ( !$title );
1039 @opt = $q->param( 'opt' );
1040 $opt = join '', @opt;
1041 my ( $deltaday, $deltatime );
1043 if ( $params{'every'} eq '1' ) {
1044 $type = 'search_everyday';
1045 ( $changed_t ) = $title =~ /(.*)#/;
1046 $title = $changed_t if ( $changed_t );
1047 ( $changed_t ) = $title =~ /(.*)第/;
1048 $title = $changed_t if ( $changed_t );
1049 ( $changed_t ) = $title =~ /(.*)▽/;
1050 $title = $changed_t if ( $changed_t );
1054 $title =~ s/\[新\]//;
1061 $type = 'reserve_flexible';
1063 $chtxt = $chtxt_0 if ( $chtxt_0 );
1064 if ( !&check_error ) {
1066 "INSERT INTO timeline ( type, chtxt, title, btime, etime, opt, deltaday, deltatime )
1067 VALUES ( '$type', '$chtxt', '$title', '$begin', '$end', '$opt', '$deltaday', '$deltatime' )"
1070 $HTML .= "録画予約を実行しました。<br>\n5秒後にトップへ移動します。<br>\n";
1071 $HTML =~ s|%REFRESH%|<meta http-equiv="refresh" content="5; url=rectool.pl">|;
1075 ################ mode=program ################
1077 if ( $mode eq 'program' ) {
1080 $HTML =~ s/%HTML_TITLE_OPT%/ - Program Viewer/;
1081 $unix = DateTime->now( time_zone => $tz )->strftime( '%Y%m%d%H%M%S' );
1083 "SELECT channel, epg_ch.chname, start, stop, title, category
1085 INNER JOIN epg_ch ON epg_timeline.channel = epg_ch.chtxt
1086 WHERE $unix <= stop %CH% %DATE% %CATEGORY% %KEY% ORDER BY start";
1090 if ( $chtxt =~ /^\d+(_0)?$/ ) {
1093 $ch = "AND channel LIKE '$chtxt\_%'";
1096 $ch = "AND channel = '$chtxt'";
1098 $sql =~ s/%CH%/$ch/;
1101 $date_1 = $date_sel . '000000';
1102 $date_2 = Date::Simple->new( $date_sel =~ /(.{4})(.{2})(.{2})/ )->next->format('%Y%m%d') . '000000';
1103 my $date = "AND '$date_1' <= stop AND start <= '$date_2'";
1104 $sql =~ s/%DATE%/$date/;
1106 if ( $category_sel ) {
1108 # $category_tmp = $category{$category_sel} . $category_sel;
1109 my $category = "AND category = '$category{$category_sel}->{name}'";
1110 $sql =~ s/%CATEGORY%/$category/;
1113 my $key = "AND TITLE LIKE '%$key%'";
1114 $sql =~ s/%KEY%/$key/;
1119 $sql =~ s/%CATEGORY%//;
1121 $ary_ref = $dbh->selectall_arrayref( $sql );
1122 foreach my $prg ( @{ $ary_ref } ) {
1123 my @date = $prg->[2] =~ /(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/;
1126 if ( $date != $prev ) {
1127 my $date = DateTime->new(
1128 year => $date[0], month => $date[1], day => $date[2],
1132 my $dn = $date->day_name;
1133 #utf8::encode( $dn );
1134 $HTML .= qq {--------$date[1]/$date[2]($dn)--------<br>\n};
1136 $HTML .= qq {$date[1]/$date[2] $date[3]:$date[4] };
1137 $HTML .= qq {$prg->[1] } if ( !$chtxt );
1138 $HTML .= qq {<a href="rectool.pl?mode=confirm&mode_sub=reserve&chtxt=$prg->[0]&start=$prg->[2]&stop=$prg->[3]">$prg->[4]</a><br>\n};
1143 ################ mode=list ################
1145 if ( $mode eq 'list' ) {
1146 $HTML =~ s/%HTML_TITLE_OPT%/ - List/;
1147 $HTML .= qq {<div>\n};
1150 <link rel="stylesheet" type="text/css" href="http://cdn.sencha.io/ext-3.4.0/resources/css/ext-all.css" />
1151 <script type="text/javascript" src="http://cdn.sencha.io/ext-3.4.0/adapter/ext/ext-base.js"></script>
1152 <script type="text/javascript" src="http://cdn.sencha.io/ext-3.4.0/ext-all.js"></script>
1154 Ext.onReady(function() {
1155 Ext.select('.ffmpeg').on('contextmenu', function(eventObj, elRef) {
1156 var win = new Ext.Window({
1157 title: 'FFmpeg info',
1159 autoLoad: "rectool.pl?mode=list&mode_sub=ffmpeg&path=" + Ext.Element(elRef).getAttribute("path") +
1160 "&pathtype=" + Ext.Element(elRef).getAttribute("pathtype"),
1163 }, null, {stopEvent:true});
1165 Ext.select( '.ffmpeg' , true ).each(function (elem) {
1166 // elem.dom.textContent
1167 var tooltip = new Ext.ToolTip({
1170 autoLoad: {url: "rectool.pl?mode=list&mode_sub=ffmpeg&path=" + elem.getAttribute("path")},
1174 title: 'FFmpeg info',
1181 $script =~ s/^\t{2}//gm;
1182 $HTML =~ s/%SCRIPT%/$script/;
1184 my $recording = $cfg->param( 'path.recpath' );
1185 my $movedest = $cfg->param( 'path.ts_movepath' );
1186 my $recorded = $cfg->param( 'path.recorded' );
1188 if ( $mode_sub eq 'log' ) {
1189 my $title = $params{ 'title' };
1190 my $log = read_file( "$recording/$title.log" ) if ( -e "$recording/$title.log" );
1191 utf8::decode( $log );
1192 $HTML .= '<pre>'.$log."</pre>\n";
1195 if ( $mode_sub eq 'logzip' ) {
1196 my $title = $params{ 'title' };
1197 my $zip = Archive::Zip->new();
1199 die 'read error' unless $zip->read("$recording/$title.log.zip") == AZ_OK;
1200 my @members = $zip->members();
1201 foreach (@members) {
1202 $logzip .= $_->fileName() . "\n";
1203 my @lines = split /\n|\r/, $zip->contents( $_->fileName() );
1205 @lines = grep {!$count{$_}++} @lines;
1206 $logzip .= join "\n", @lines;
1207 $logzip .= "\n<hr>\n";
1210 utf8::decode( $logzip );
1211 $HTML .= '<pre>'.$logzip."</pre>\n";
1214 if ( $mode_sub eq 'ffmpeg' ) {
1215 my $path = $params{ 'path' };
1216 my $pathtype = $params{ 'pathtype' };
1218 $pathdir = $recording if ( $pathtype eq 'ing');
1219 $pathdir = $recorded if ( $pathtype eq 'ed' );
1220 $pathdir = $movedest if ( $pathtype eq 'dst');
1221 # mediainfo (not working)
1224 my $ffmpeg = `ffmpeg -i "$pathdir/$path" 2>&1` if ( -f "$pathdir/$path" );
1225 utf8::decode($ffmpeg);
1226 $ffmpeg = join "<br>\n", grep /Duration|Stream/, split /\n/, $ffmpeg;
1231 $HTML .= qq {<a href="rectool.pl?mode=list&mode_sub=new">録画中のみ</a>\n};
1232 $HTML .= qq {<a href="rectool.pl?mode=list&mode_sub=old">録画後のみ</a>\n<br>\n};
1234 if ( !$mode_sub || $mode_sub eq 'new' ) {
1235 $HTML .= "録画中のファイル一覧<br>\n";
1236 &list( $recording );
1241 if ( !$mode_sub || $mode_sub eq 'old' ) {
1242 $HTML .= "録画後のファイル一覧<br>\n";
1243 &simple_list( $movedest );
1244 &simple_list( $recorded );
1248 local $path = shift;
1250 my @exp = ( 'log', 'log.zip', 'ts.b25', 'ts.tsmix', 'ts', 'ts.log',
1251 'aac', 'srt', 'm2v', 'wav', '264', 'mp4', 'mkv' );
1253 $exp{$exp[$_]} = $_;
1255 my $exp_count = scalar keys %exp;
1257 &get_file_list_wrapper( $path, \&wanted );
1260 foreach my $name ( sort { $exp{$a} <=> $exp{$b} } keys %exp ) {
1261 $help .= $exp{$name} + 1 . " = $name / ";
1264 $help = qq {<tr style="background-color: #87CEEB"><td>$help\n</td>\n};
1265 $help .= qq {<td>$_</td>\n} for ( 1..$exp_count );
1267 $HTML .= qq {<br>\n○ = 完了 / ● = 書き込み中 / ◆ = ファイルサイズ異常<br>\n};
1268 $HTML .= qq {<table summary="listtable" border=1 cellspacing=0>\n<tr>\n};
1269 $HTML .= qq {<th>タイトル</th>\n};
1270 $HTML .= qq {<th>$_</th>\n} for ( 1..$exp_count );
1271 $HTML .= qq {</tr>\n};
1275 foreach my $title ( sort keys %list ) {
1276 my $value = $list{$title};
1277 my @flag = ( 0 ) x ( $exp_count );
1278 $HTML .= qq {<tr>\n<td width="600" style="width: 600px; white-space: normal">$title</td>\n};
1279 foreach my $exp ( keys %{$value} ) {
1280 if ( $exp eq 'log' ) {
1282 my $title = $q->escape( $title );
1283 my $extra = qq {<td><a href="rectool.pl?mode=list&mode_sub=log&title=$title">○</a></td>\n};
1285 $value->{$exp}->{extra} = $extra;
1287 elsif ( $exp eq 'log.zip' ) {
1289 my $title = $q->escape( $title );
1290 my $extra = qq {<td><a href="rectool.pl?mode=list&mode_sub=logzip&title=$title">○</a></td>\n};
1292 $value->{$exp}->{extra} = $extra;
1294 elsif ( $exp eq 'mp4' ) {
1296 # $value->{$exp}->{style} = $value->{$exp}->{size};
1297 my $size = $value->{$exp}->{size};
1298 my $extra = qq {<td><span class="ffmpeg" path="$title.mp4" pathtype="ing">$size</span></td>\n};
1299 $value->{$exp}->{extra} = $extra;
1301 elsif ( $exp eq 'mkv' ) {
1303 my $title = $q->escape( $title );
1305 my $extra = qq {<td><a title="$value->{$exp}->{size}" href="rectool.pl?mode=thumb&title=$title">■</a></td>\n};
1306 $value->{$exp}->{extra} = $extra;
1308 $flag[$exp{$exp}] = $value->{$exp};
1311 my $size = $_->{size};
1312 my $style = $_->{style};
1313 my $span = $size ? qq {<span title="$size">$style</span>} : '<br>';
1314 $HTML .= $_->{extra} || qq {<td>$span</td>\n};
1316 $HTML .= qq {</tr>\n};
1317 $HTML .= $help unless ( ++$count % 20 );
1319 $HTML .= qq {</table>\n};
1325 return if ( $rel =~ /Thumbs\.db/ );
1326 return if ( $rel =~ /\.idx/ );
1328 $rel =~ s/\.temp$//;
1329 my $regexp = join '|', keys %exp;
1330 my ( $title, $exp ) = $rel =~ /(.*?)\.($regexp)$/;
1331 my ( $size, $style ) = &get_size( $abs );
1332 $rel =~ s/\.temp$//;
1334 $title = '_error_exp_'.$rel;
1337 if ( $title !~ /[^0-9A-F]+/ ) {
1338 my $tmp = pack( 'H*', $title );
1340 $title = '_error_b16_'.$rel;
1344 $title = 'Base16_'.$tmp;
1347 $list{$title}->{$exp} = { 'style' => $style, 'size' => $size };
1352 local $path = shift;
1355 &get_file_list_wrapper( $path, \&simple_wanted );
1357 @list = nsort @list;
1360 $HTML .= "$_<br>\n";
1367 my ( $size ) = &get_size( $abs );
1368 $rel = qq {<span class="ffmpeg" path="$rel" pathtype="ed">$rel</span>};
1369 push @list, $rel ."\t\t". $size;
1375 my ( $size, $last ) = (stat( $file ))[7,9];
1376 my @unim = ("B","KiB","MiB","GiB","TiB","PiB");
1379 while($size >= 1024 ){
1381 $size = $size / 1024;
1384 $size = int( $size );
1386 if ( time - $last < 10 ) {
1389 elsif ( $size == 0 ) {
1395 return ( "$size $unim[$count]", $style );
1399 ################ mode=thumb ################
1401 if ( $mode eq 'thumb' ) {
1402 my $title = $params{ 'title' };
1403 my $pos = $params{ 'pos' };
1404 my $recording = $cfg->param( 'path.recpath' );
1406 print "Content-Type: image/jpeg\n\n";
1407 exec "ffmpeg -ss 300 -i '$recording/$title.mkv' -f image2 -pix_fmt jpg -vframes 1 -s 320x240 -";
1411 ################ mode=check ################
1413 if ( $mode eq 'check' ) {
1416 ################ mode=bravia ################
1418 if ( $mode eq 'bravia' ) {
1419 $HTML =~ s/%HTML_TITLE_OPT%/ - Bravia/;
1420 $HTML .= qq {<div>\n};
1421 $HTML .= qq {<form method="get" action="rectool.pl">\n};
1422 $HTML .= qq {<div>\n};
1423 $HTML .= qq {<table summary="bayestable" border=1 cellspacing=0>\n<tr>\n};
1424 $HTML .= qq {<th>ID</th>\n};
1425 $HTML .= qq {<th>チャンネル</th>\n};
1426 $HTML .= qq {<th>タイトル</th>\n};
1427 $HTML .= qq {<th><a href="rectool.pl?mode=bravia">開始時刻</a></th>\n};
1428 $HTML .= qq {<th>終了時刻</th>\n};
1429 $HTML .= qq {<th>録画時間</th>\n};
1430 $HTML .= qq {<th><a href="rectool.pl?mode=bravia&order=point">ポイント</a></th>\n};
1431 $HTML .= qq {<th>予約</th>\n};
1432 $HTML .= qq {</tr>\n};
1433 my $order = $params{ 'order' };
1434 if ( $order ne 'point' ) {
1438 $order = 'point DESC';
1440 my $ary_ref = $dbh->selectall_arrayref(
1441 "SELECT id, chtxt, title, btime, etime, point
1442 FROM auto_timeline_bayes
1445 foreach my $line ( @{ $ary_ref } ) {
1446 my ( $begin, $end, $diff ) = &str2readable( $line->[3], $line->[4] );
1448 $line->[1] = $chtxt_chname{$line->[1]} || $line->[1];
1449 $HTML .= qq {<tr align="center">\n};
1450 $HTML .= qq {<td>$line->[0]</td>\n};
1451 $HTML .= qq {<td>$line->[1]</td>\n};
1452 $HTML .= qq {<td>$line->[2]</td>\n};
1453 $HTML .= qq {<td>$begin</td>\n<td>$end</td>\n<td>$diff</td>\n};
1454 $HTML .= qq {<td>$line->[5]</td>\n};
1455 $HTML .= qq {<td><a href="rectool.pl?mode=confirm&mode_sub=reserve&bayesid=$line->[0]">予約</a></td>\n};
1456 $HTML .= qq {</tr>\n};
1458 $HTML .= qq {</table>\n};
1459 $HTML .= qq {</div>\n};
1460 $HTML .= qq {</form>\n};
1464 ################ mode=proc ################
1466 if ( $mode eq 'proc' ) {
1467 $HTML =~ s/%HTML_TITLE_OPT%/ - Proposal/;
1468 $HTML .= qq {<div>\n};
1469 $HTML .= qq {<table summary="proctable" border=1 cellspacing=0>\n<tr>\n};
1470 $HTML .= qq {<th>タイプ</th>\n};
1471 $HTML .= qq {<th>タイトル</th>\n};
1472 $HTML .= qq {<th>予約</th>\n};
1473 $HTML .= qq {</tr>\n};
1475 my $ary_ref = $dbh->selectall_arrayref(
1476 "SELECT type, chtxt, title
1480 foreach my $line ( @{ $ary_ref } ) {
1482 $line->[3] = $q->escape( $line->[2] );
1483 my $opt = $dbh->selectrow_array(
1484 "SELECT opt FROM in_timeline_log
1485 WHERE title = '$line->[2]' "
1488 if ( $line->[0] eq 'auto_suggest_dec' ) {
1489 unless ( $dbh->selectrow_array(
1490 "SELECT 1 FROM timeline
1491 WHERE ( type = 'convert_b25_ts' OR type = 'convert_b25_ts_running' )
1492 AND title = '$line->[2]' "
1494 $url = qq {rectool.pl?mode=confirm&mode_sub=proc&type=$line->[0]&chtxt=$line->[1]&title=$line->[3]&opt=$opt};
1497 elsif ( $line->[0] eq 'auto_suggest_enc' ) {
1498 unless ( $dbh->selectrow_array(
1499 "SELECT 1 FROM timeline
1500 WHERE ( type = 'convert_ts_mp4' OR type = 'convert_ts_mp4_running' )
1501 AND title = '$line->[2]' "
1503 $url = qq {rectool.pl?mode=confirm&mode_sub=proc&type=$line->[0]&chtxt=$line->[1]&title=$line->[3]&opt=$opt};
1507 unless ( $dbh->selectrow_array(
1508 "SELECT 1 FROM timeline
1509 WHERE ( type LIKE 'convert_avi%' OR type = 'convert_mkv' )
1510 AND title = '$line->[2]' "
1512 $url = qq {rectool.pl?mode=confirm&mode_sub=proc&type=$line->[0]&chtxt=$line->[1]&title=$line->[3]};
1516 $href = qq {<a href="$url">予約</a>};
1522 my $color = $color{$type_suggest{$line->[0]}} ? $color{$type_suggest{$line->[0]}} : '';
1523 $line->[0] = $type{$line->[0]} ? $type{$line->[0]} : $line->[0];
1524 $line->[0] = qq {<span style="color: $color">$line->[0]</span>} if ( $color );
1525 $HTML .= qq {<tr align="center">\n};
1526 $HTML .= qq {<td>$line->[0]</td>\n};
1527 $HTML .= qq {<td align="left">$line->[2]</td>\n};
1528 $HTML .= qq {<td>$href</td>\n};
1529 $HTML .= qq {</tr>\n};
1532 $HTML .= qq {</table>\n};
1535 ################ mode=jbk ################
1537 if ( $mode eq 'jbk' ) {
1538 $HTML =~ s/%HTML_TITLE_OPT%/ - JBK/;
1539 $HTML .= qq {<div>\n};
1541 if ( $mode_sub eq 'add' ) {
1542 my $keyword = $params{ 'keyword' };
1543 utf8::decode( $keyword );
1544 $HTML .= "キーワード「$keyword」を追加しました。<br>\n";
1546 "INSERT INTO in_auto_jbk_key ( keyword )
1547 VALUES ( '$keyword' )"
1550 elsif ( $mode_sub eq 'del' ) {
1551 my $id = $params{ 'id' };
1552 my $keyword = $dbh->selectrow_array(
1553 "SELECT keyword FROM in_auto_jbk_key
1554 WHERE id = '$id' " );
1555 $HTML .= "キーワード「$keyword」を削除しました。<br>\n";
1557 "DELETE FROM in_auto_jbk_key WHERE id = '$id'"
1560 elsif ( $mode_sub eq 'on' ) {
1561 my $id = $params{ 'id' };
1562 $HTML .= "キーワード「$keyword」を自動録画対象にしました。<br>\n";
1564 "UPDATE in_auto_jbk_key SET auto = 1 WHERE id = '$id'"
1567 elsif ( $mode_sub eq 'off' ) {
1568 my $id = $params{ 'id' };
1569 $HTML .= "キーワード「$keyword」を自動録画対象から外しました。<br>\n";
1571 "UPDATE in_auto_jbk_key SET auto = 0 WHERE id = '$id'"
1575 $HTML .= qq {<table summary="jbktable" border=1 cellspacing=0>\n<tr>\n};
1576 $HTML .= qq {<th>ID</th>\n};
1577 $HTML .= qq {<th>キーワード</th>\n};
1578 $HTML .= qq {<th>自動録画</th>\n};
1579 $HTML .= qq {<th>切り替え</th>\n};
1580 $HTML .= qq {<th>録画オプション</th>\n};
1581 $HTML .= qq {<th>削除</th>\n};
1582 $HTML .= qq {</tr>\n};
1584 my $ary_ref = $dbh->selectall_arrayref(
1585 "SELECT id, keyword, auto, opt
1586 FROM in_auto_jbk_key
1589 foreach my $line ( @{ $ary_ref } ) {
1590 my $delurl = "rectool.pl?mode=jbk&mode_sub=del&id=$line->[0]";
1591 my $auto = $line->[2] ? 'on' : 'off';
1592 my $oppo = $line->[2] ? 'off' : 'on';
1593 my $oppourl = "rectool.pl?mode=jbk&mode_sub=$oppo&id=$line->[0]";
1596 $HTML .= qq {<tr align="center">\n};
1597 $HTML .= qq {<td>$line->[0]</td>\n};
1598 $HTML .= qq {<td>$line->[1]</td>\n};
1599 $HTML .= qq {<td>$auto</td>\n};
1600 $HTML .= qq {<td><a href="$oppourl">$oppo</a></td>\n};
1601 $HTML .= qq {<td>$line->[3]</a></td>\n};
1602 $HTML .= qq {<td><a href="$delurl">削除</a></td>\n};
1603 $HTML .= qq {</tr>\n};
1606 $HTML .= qq {</table>\n};
1608 $HTML .= qq {<form method="get" action="rectool.pl">\n};
1609 $HTML .= qq {<div>\n};
1610 $HTML .= qq {<input type="hidden" name="mode" value="jbk">\n};
1611 $HTML .= qq {<input type="hidden" name="mode_sub" value="add">\n};
1612 $HTML .= qq {<input name="keyword" type="text">\n};
1613 $HTML .= qq {<input type="submit" value="追加">\n</div>\n</form>\n<br>\n};
1615 $HTML .= qq {<table summary="jbkrestable" border=1 cellspacing=0>\n<tr>\n};
1616 $HTML .= qq {<th>ID</th>\n};
1617 $HTML .= qq {<th>チャンネル</th>\n};
1618 $HTML .= qq {<th>タイトル</th>\n};
1619 $HTML .= qq {<th>開始時刻</th>\n};
1620 $HTML .= qq {<th>終了時刻</th>\n};
1621 $HTML .= qq {<th>録画時間</th>\n};
1622 $HTML .= qq {<th>予約</th>\n};
1623 $HTML .= qq {</tr>\n};
1625 $ary_ref = $dbh->selectall_arrayref(
1626 "SELECT id, auto_timeline_keyword.chtxt, epg_ch.chname, title, btime, etime
1627 FROM auto_timeline_keyword
1628 INNER JOIN epg_ch ON auto_timeline_keyword.chtxt = epg_ch.chtxt
1632 foreach my $line ( @{ $ary_ref } ) {
1633 my ( $begin, $end, $diff ) = &str2readable( $line->{btime}, $line->{etime} );
1634 $line->{btime} =~ s/(.{4})-(.{2})-(.{2}) (.{2}):(.{2}):(.{2})/$1$2$3$4$5$6/;
1635 $line->{etime} =~ s/(.{4})-(.{2})-(.{2}) (.{2}):(.{2}):(.{2})/$1$2$3$4$5$6/;
1636 my $url = qq "rectool.pl?mode=confirm&mode_sub=reserve&chtxt=$line->{chtxt}&start=$line->{btime}&stop=$line->{etime}";
1638 $HTML .= qq {<tr align="center">\n};
1639 $HTML .= qq {<td>$line->{id}</td>\n};
1640 $HTML .= qq {<td>$line->{chname}</td>\n};
1641 $HTML .= qq {<td>$line->{title}</td>\n};
1642 $HTML .= qq {<td>$begin</td>\n};
1643 $HTML .= qq {<td>$end</td>\n};
1644 $HTML .= qq {<td>$diff</td>\n};
1645 $HTML .= qq {<td><a href="$url">予約</a></td>\n};
1646 $HTML .= qq {</tr>\n};
1649 $HTML .= qq {</table>\n};
1653 ################ mode=recognize ################
1655 if ( $mode eq 'recognize' ) {
1656 $HTML =~ s/%HTML_TITLE_OPT%/ - Recognizer/;
1658 my $text = $params{ 'text' };
1659 utf8::decode( $text );
1660 $chtxt = $params{ 'chtxt' };
1661 my $title = $params{ 'title' };
1662 utf8::decode( $title );
1664 $HTML .= qq {<div>\n};
1665 $HTML .= qq {与えられた文字列のうち、番組の放送時刻と思われる文字列を認識します。<br>\n};
1666 $HTML .= qq {番組表が取得できない一週間以上先の予約ができます。<br>\n};
1667 $HTML .= qq {<form method="post" action="rectool.pl">\n};
1668 $HTML .= qq {<div>\n};
1669 &draw_form_channel( 'nonone' );
1670 $HTML .= qq {<input type="text" name="title" value="$title">\n};
1671 $HTML .= qq {<br>\n};
1672 $HTML .= qq {<input type="hidden" name="mode" value="recognize">\n};
1673 $HTML .= qq {<textarea name="text" cols=40 rows=4>\n$text</textarea>\n};
1674 $HTML .= qq {<input type="submit" value="実行">\n</div>\n</form>\n};
1676 my $ch_list = join '|', grep /.+/, values %chtxt_0_chname;
1677 my %ch_reverse = reverse %chtxt_0_chname;
1680 my ( $year, $month, $day );
1681 my ( $bhour, $bminute, $ehour, $eminute );
1683 foreach ( split /\n/, $text ) {
1684 my @bdate = /(\d{4}).(\d{1,2}).(\d{1,2})/;
1685 s/(\d{4}).(\d{2}).(\d{2})//;
1686 my @btime = /(\d{1,2})[::](\d{1,2})/;
1687 s/(\d{1,2})[::](\d{2})//;
1688 my @etime = /(\d{1,2})[::](\d{1,2})/;
1689 s/(\d{1,2})[::](\d{2})//;
1692 $bdate[0] = Time::Piece->localtime->year;
1693 ( $bdate[1], $bdate[2] ) = /(\d{1,2})月(\d{1,2})日/;
1694 s/(\d{1,2})月(\d{1,2})日//;
1696 next if (!( @bdate || @btime ));
1697 ( $year, $month, $day ) = @bdate if ( $bdate[0] && $bdate[1] && $bdate[2] );
1698 ( $bhour, $bminute ) = @btime if ( defined $btime[0] && defined $btime[1] );
1699 ( $ehour, $eminute ) = @etime if ( defined $etime[0] && defined $etime[1] );
1700 $next_day = 1 if ( /深夜/ );
1701 my ( $ch ) = /($ch_list)/;
1702 my $chtxt = $ch_reverse{$ch} if ( $ch && $ch_reverse{$ch} );
1705 if ( $year && $month && $day && defined $bhour && defined $bminute ) {
1706 my $tp = Time::Piece->strptime( "$year-$month-$day $bhour:$bminute", '%Y-%m-%d %H:%M' );
1707 my $etp = Time::Piece->strptime( "$year-$month-$day $ehour:$eminute", '%Y-%m-%d %H:%M' ) if ( defined $ehour && defined $eminute );
1708 $tp += ONE_DAY if ( $next_day );
1709 my $start = $tp->strftime( '%Y%m%d%H%M%S' );
1710 my $stop = defined $etp ?
1711 $etp->strftime( '%Y%m%d%H%M%S' ) :
1712 ( $tp + ONE_MINUTE * 30 )->strftime( '%Y%m%d%H%M%S' );
1713 $title = $_ if ( !$title );
1714 my $url = qq "rectool.pl?mode=confirm&mode_sub=reserve&chtxt=$chtxt&start=$start&stop=$stop&title=$title";
1715 $HTML .= qq {認識結果:$year-$month-$day $bhour:$bminute -> $ehour:$eminute 残り:$_<a href="$url">リンク</a> <br>\n};
1721 ################ mode=expert ################
1723 if ( $mode eq 'expert' ) {
1726 $HTML =~ s/%HTML_TITLE_OPT%/ - Expert/;
1727 $HTML .= qq {<div>\n};
1729 if ( $mode_sub eq 'reget' ) {
1730 my $bctype = $params{ 'bctype' };
1731 my ( $chtxt, $chname ) = $dbh->selectrow_array(
1732 "SELECT chtxt, chname FROM epg_ch
1733 WHERE bctype = '$bctype' " );
1734 $HTML .= "Update for $chname ( chtxt: $chtxt ) has been reserved.<br>\n";
1735 $dbh->do( "UPDATE epg_ch SET status = '2' WHERE chtxt = '$chtxt' " );
1739 if ( $params{ 'dump' } ) {
1741 my $sth = $dbh->prepare(
1742 "SELECT type, chtxt, title, btime, etime, deltatime, deltaday, opt, counter
1745 # my $yaw = XML::Handler::YAWriter->new;
1747 my $wri = XML::SAX::Writer->new( Output => \$output );
1748 my $gen = XML::Generator::DBI->new(
1752 $gen->execute($sth);
1753 # $HTML .= join "\n", @{$yaw->{Strings}};
1754 utf8::encode($output);
1755 my $len = length $output;
1756 print "Content-Type: text/xml\n";
1757 print "Content-Length: $len\n";
1758 print "Content-Disposition: attachment; filename=\"rec10-reserve-dump.xml\"\n\n";
1763 if ( $params{ 'restore' } ) {
1764 my $fh = $q->upload('upfile');
1765 my $xml = read_file( $fh );
1766 my $tpp = XML::TreePP->new;
1767 my $tree = $tpp->parse( $xml );
1768 my @rows = @{ $tree->{database}->{select}->{row} };
1771 # INSERT INTO timeline ( ... ) VALUES ( aa, bb, cc ), ( kk, ll, mm ), ( xx, yy, zz )
1772 my @keys = qw/type chtxt title btime etime deltatime deltaday opt counter/;
1773 my $keys = join ', ', @keys;
1776 foreach my $row ( @rows ) {
1777 my $values = join ', ', map { "'".$row->{'-'.$_}."'" } @keys;
1778 utf8::decode( $values );
1779 push @values, "( $values )";
1781 my $sql = "INSERT INTO timeline ( $keys ) VALUES " . join ', ', @values;
1782 $dbh->do( "TRUNCATE TABLE timeline" );
1787 my @ary = $dbh->selectrow_array(
1788 "SELECT auto_jbk, auto_bayes, auto_del_tmp, auto_opt
1789 FROM in_settings " );
1791 @ary = map( $_ ? 'checked' : '', @ary );
1793 $HTML .= qq {内部オプションの変更\n<br>};
1794 $HTML .= qq {<form method="get" action="rectool.pl">\n};
1795 $HTML .= qq {<div>\n};
1796 $HTML .= qq {<input type="hidden" name="mode" value="change">\n};
1797 $HTML .= qq {<input type="hidden" name="mode_sub" value="setting">\n};
1798 $HTML .= qq {<input type="checkbox" name="jbk" value="1" $ary[0]>自動地引\n};
1799 $HTML .= qq {<input type="checkbox" name="bayes" value="1" $ary[1]>自動ベイズ\n};
1800 $HTML .= qq {<input type="checkbox" name="del_tmp" value="1" $ary[2]>自動一時ファイル削除\n};
1801 $HTML .= qq {自動オプション:<input type="text" name="opt" value="$opt">\n};
1802 $HTML .= qq {<input type="submit" value="保存">\n</div>\n</form>\n};
1805 $HTML .= qq {<hr>\n番組表のカテゴリ一覧と内蔵のカテゴリ一覧の合致を確認中...\n};
1806 $ary_ref = $dbh->selectcol_arrayref(
1807 "SELECT DISTINCT category FROM epg_timeline"
1809 my @category = map {$_->{name}} sort values %category;
1810 if ( List::Compare->new( $ary_ref, \@category )->get_symdiff ) {
1811 $HTML .= qq {一致しません<br>\n};
1812 $HTML .= qq {番組表:@{$ary_ref}<br>\n内蔵:@category<br>\n};
1815 $HTML .= qq {一致しました<br>\n};
1819 @ary = $dbh->selectrow_array( "SELECT terec, bscsrec, b252ts, ts2avi FROM in_status" );
1820 $HTML .= qq {<hr>\n地上波録画数:$ary[0]\n衛星波録画数:$ary[1]\n解読数:$ary[2]\n縁故数:$ary[3]\n<br>\n};
1821 $HTML .= qq {<form method="get" action="rectool.pl">\n};
1822 $HTML .= qq {<div>\n};
1823 $HTML .= qq {<input type="hidden" name="mode" value="change">\n};
1824 $HTML .= qq {<input type="hidden" name="mode_sub" value="fixstatus">\n};
1825 $HTML .= qq {<input type="submit" name="terec" value="地上波録画数をリセット">\n};
1826 $HTML .= qq {<input type="submit" name="bscsrec" value="衛星波録画数をリセット">\n};
1827 $HTML .= qq {<input type="submit" name="b252ts" value="解読数をリセット">\n};
1828 $HTML .= qq {<input type="submit" name="ts2avi" value="縁故数をリセット">\n</div>\n</form>\n};
1831 $HTML .= qq {<hr>\nRec10 バージョン:$rec10_version\nrectool バージョン:$rectool_version\n<br>\n};
1835 $HTML .= qq {<hr>\n番組表の欠落<br>\n};
1836 $ary_ref = $dbh->selectall_arrayref( "SELECT chname, chtxt FROM epg_ch" );
1837 foreach my $line ( @{$ary_ref} ) {
1838 my $ary_ref = $dbh->selectall_arrayref(
1839 "SELECT start, stop, title FROM epg_timeline WHERE channel = '$line->[1]' ORDER BY start"
1842 my @program_old = ( '', $ary_ref->[0]->[0] );
1843 my $program_old = \@program_old;
1845 foreach my $program_new ( @{$ary_ref} ) {
1846 if ( $program_old->[1] ne $program_new->[0] &&
1847 $program_old->[2] !~ /クロ?ジング|クロージング|エンディング|休止|ミッドナイト|ending/ &&
1848 $program_new->[2] !~ /オープニング|ウィークリー・インフォメーション|モーニング|opening/ &&
1849 ( str2datetime( $program_new->[0] ) - str2datetime( $program_old->[1] ) )->delta_minutes > 30 ) {
1850 $program_old->[1] =~ s/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/$1-$2-$3 $4:$5:$6/;
1851 $program_new->[0] =~ s/(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/$1-$2-$3 $4:$5:$6/;
1852 $error .= qq{ $program_old->[2] $program_old->[1]\n -> $program_new->[2] $program_new->[0]\n};
1854 $program_old = $program_new;
1856 $HTML .= qq {<pre>\n$line->[0]\n$error</pre>\n} if ( $error );
1861 $HTML .= qq {<hr>\n予約の保存・復元<br>\n};
1862 $HTML .= qq {<form action="rectool.pl" method="post" enctype="multipart/form-data">\n};
1863 $HTML .= qq {<div>\n};
1864 $HTML .= qq {<input type="hidden" name="mode" value="expert">\n};
1865 $HTML .= qq {<input type="submit" name="dump" value="保存">\n};
1866 $HTML .= qq {<input type="file" name="upfile">\n};
1867 $HTML .= qq {<input type="submit" name="restore" value="復元">\n};
1868 $HTML .= qq {</div>\n};
1869 $HTML .= qq {</form>\n};
1872 $ary_ref = $dbh->selectall_arrayref(
1873 "SELECT chname, chtxt, bctype, ch, csch, tsid, updatetime, status, visible
1876 $HTML .= qq {<hr>\n番組表の更新状況<br>\n};
1877 $HTML .= qq {<table summary="channeltable" border=1 cellspacing=0>\n<tr>\n};
1878 $HTML .= qq {<th>チャンネル名</th>\n};
1879 $HTML .= qq {<th>chtxt</th>\n};
1880 $HTML .= qq {<th>bctype</th>\n};
1881 $HTML .= qq {<th>ch</th>\n};
1882 $HTML .= qq {<th>csch</th>\n};
1883 $HTML .= qq {<th>tsid</th>\n};
1884 $HTML .= qq {<th>最終更新時刻</th>\n};
1885 $HTML .= qq {<th>状態</th>\n};
1886 $HTML .= qq {<th>表示</th>\n};
1887 $HTML .= qq {</tr>\n};
1888 foreach my $status ( @{$ary_ref} ) {
1889 $HTML .= qq {<tr>\n};
1890 $HTML .= qq {<td>$status->[0]</td>\n<td>$status->[1]</td>\n<td>$status->[2]</td>\n<td>$status->[3]</td>\n};
1891 $HTML .= qq {<td>$status->[4]</td>\n<td>$status->[5]</td>\n<td>$status->[6]</td>\n<td>$status->[7]</td>\n};
1892 $HTML .= qq {<td>$status->[8]</td>\n};
1893 $HTML .= qq {</tr>\n};
1895 $HTML .= qq {</table>\n};
1897 $HTML .= qq {<form method="get" action="rectool.pl">\n};
1898 $HTML .= qq {<div>\n};
1899 $HTML .= qq {番組表を再取得する\n};
1900 $HTML .= qq {<input type="hidden" name="mode" value="expert">\n};
1901 $HTML .= qq {<input type="hidden" name="mode_sub" value="reget">\n};
1902 $HTML .= qq {<select name="bctype">\n};
1903 $ary_ref = $dbh->selectall_arrayref(
1904 "SELECT chname, bctype
1905 FROM epg_ch WHERE bctype NOT LIKE '_s%' "
1907 foreach my $line ( @{$ary_ref} ) {
1908 $HTML .= qq {<option value="$line->[1]">$line->[1]</option>\n};
1910 $HTML .= qq {<option value="bs">BS</option>\n};
1911 $HTML .= qq {<option value="cs1">CS1</option>\n};
1912 $HTML .= qq {<option value="cs2">CS2</option>\n};
1913 $HTML .= qq {</select>\n};
1914 $HTML .= qq {<input type="submit" value="実行">\n</div>\n</form>\n};
1918 $ary_ref = $dbh->selectall_arrayref(
1919 "SELECT id, type, chtxt, title, btime, etime, opt, deltaday, deltatime
1922 $HTML .= qq {<hr>\n予約表<br>\n};
1923 $HTML .= qq {<table summary="rectimetable" border=1 cellspacing=0>\n<tr>\n};
1924 $HTML .= qq {<th>ID</th>\n};
1925 $HTML .= qq {<th>type</th>\n};
1926 $HTML .= qq {<th>chtxt</th>\n};
1927 $HTML .= qq {<th>title</th>\n};
1928 $HTML .= qq {<th>btime</th>\n};
1929 $HTML .= qq {<th>etime</th>\n};
1930 $HTML .= qq {<th>opt</th>\n};
1931 $HTML .= qq {<th>deltaday</th>\n};
1932 $HTML .= qq {<th>deltatime</th>\n};
1933 $HTML .= qq {</tr>\n};
1934 foreach my $status ( @{$ary_ref} ) {
1935 $HTML .= qq {<tr>\n};
1936 $HTML .= qq {<td>$status->[0]</td>\n<td>$status->[1]</td>\n<td>$status->[2]</td>\n<td>$status->[3]</td>\n};
1937 $HTML .= qq {<td>$status->[4]</td>\n<td>$status->[5]</td>\n<td>$status->[6]</td>\n<td>$status->[7]</td>\n};
1938 $HTML .= qq {<td>$status->[8]</td>\n};
1939 $HTML .= qq {</tr>\n};
1941 $HTML .= qq {</table>\n};
1944 ################ mode=log ################
1946 if ( $mode eq 'log' ) {
1947 $HTML =~ s/%HTML_TITLE_OPT%/ - Log/;
1949 $HTML .= qq {<div>\n};
1950 $HTML .= qq {<table summary="reclogtable" border=1 cellspacing=0>\n<tr>\n};
1951 $HTML .= qq {<th>ID</th>\n};
1952 $HTML .= qq {<th>chtxt</th>\n};
1953 $HTML .= qq {<th>title</th>\n};
1954 $HTML .= qq {<th>btime</th>\n};
1955 $HTML .= qq {<th>etime</th>\n};
1956 $HTML .= qq {<th>opt</th>\n};
1957 $HTML .= qq {<th>exp</th>\n};
1958 $HTML .= qq {<th>longexp</th>\n};
1959 $HTML .= qq {<th>category</th>\n};
1960 $HTML .= qq {</tr>\n};
1961 $ary_ref = $dbh->selectall_arrayref(
1962 "SELECT id, chtxt, title, btime, etime, opt, exp, longexp, category
1963 FROM in_timeline_log "
1965 foreach my $line ( @{$ary_ref} ) {
1966 $HTML .= qq {<tr>\n};
1967 $HTML .= qq {<td>$line->[0]</td>\n<td>$line->[1]</td>\n<td>$line->[2]</td>\n<td>$line->[3]</td>\n};
1968 $HTML .= qq {<td>$line->[4]</td>\n<td>$line->[5]</td>\n<td>$line->[6]</td>\n<td>$line->[7]</td>\n};
1969 $HTML .= qq {<td>$line->[8]</td>\n};
1970 $HTML .= qq {</tr>\n};
1972 $HTML .= qq {</table>\n};
1975 ################ mode=help ################
1977 if ( $mode eq 'help' ) {
1978 $HTML =~ s/%HTML_TITLE_OPT%/ - Help/;
1979 $HTML =~ s|%REFRESH%|<meta http-equiv="refresh" content="300">|;
1980 $HTML .= qq {<div>\n};
1981 $HTML .= qq {ヘルプ\n};
1984 ################ mode=test ################
1986 if ( $mode eq 'test' ) {
1987 $HTML =~ s/%HTML_TITLE_OPT%/ - Test/;
1988 $HTML =~ s|%REFRESH%|<meta http-equiv="refresh" content="300">|;
1989 $HTML .= qq {<div>\n};
1991 $tmp = read_file( '/etc/rec10.conf' );
1992 $tmp =~ s/\n/<br>\n/gs;
1995 # $HTML .= Dumper( $ary_ref );
1998 ################ mode nasi ################
2002 $HTML =~ s/%HTML_TITLE_OPT%/ - Top/;
2003 $HTML .= qq {Welcome to Rec10!<br>\n};
2009 #<div style="float: right">
2016 #<div align="center">
2017 #$HTML_ADV = $HTML_ADV_IMG . $HTML_ADV_TEXT if ( !$HTML_ADV );
2019 $HTML_HEADER = qq {<div style="text-align: center">\n$HTML_ADV\n</div>\n};
2022 $HTML =~ s/%HTML_TITLE_OPT%//;
2023 $HTML =~ s/%REFRESH%//;
2024 $HTML =~ s/%SCRIPT%//;
2026 $HTML =~ s/%HTML_HEADER%/$HTML_HEADER/;
2028 utf8::encode( $HTML );
2034 $hires = Time::HiRes::time() - $hires;
2035 $last_modified = localtime((stat 'rectool.pl')[9]);
2037 $HTML_HEADER .= qq {<div>\n};
2038 $HTML_HEADER .= qq {<span style="float: right; font-size: 8px">Last-Modified: $last_modified<br>Time-Elapsed: $hires 秒</span>\n};
2039 $HTML_HEADER .= qq {<span style="float: left">\n};
2040 $HTML_HEADER .= qq {<a href="rectool.pl">トップ(検索)</a>\n};
2041 $HTML_HEADER .= qq {<a href="rectool.pl?mode=schedule">予約確認</a>\n};
2042 $HTML_HEADER .= qq {<a href="rectool.pl?mode=graph">予約状況(画像版)</a>\n};
2043 $HTML_HEADER .= qq {<a href="rectool.pl?mode=list">録画一覧</a>\n};
2044 $HTML_HEADER .= qq {<a href="rectool.pl?mode=bravia">おまかせ</a>\n};
2045 $HTML_HEADER .= qq {<a href="rectool.pl?mode=expert">玄人仕様</a>\n};
2046 $HTML_HEADER .= qq {<a href="rectool.pl?mode=proc">復旧支援</a>\n};
2047 $HTML_HEADER .= qq {<a href="rectool.pl?mode=jbk">地引</a>\n};
2048 $HTML_HEADER .= qq {<a href="rectool.pl?mode=log">録画履歴</a>\n};
2049 $HTML_HEADER .= qq {<a href="rectool.pl?mode=recognize">文字認識</a>\n};
2050 $HTML_HEADER .= qq {<a href="rectool.pl?mode=edit">新規予約</a>\n};
2051 # $HTML_HEADER .= qq {<a href="../rec10web/rec10web.py">新規予約</a>\n};
2052 $HTML_HEADER .= qq {</span>\n};
2053 $HTML_HEADER .= qq {<hr style="clear: both; background-color: grey; height: 4px">\n};
2054 $HTML_HEADER .= qq {</div>\n};
2058 $chname = $params{ 'chname' };
2059 $chtxt = $params{ 'chtxt' };
2060 $key = $params{ 'key' };
2061 utf8::decode( $key );
2063 $chtxt = $dbh->selectrow_array("SELECT chtxt FROM epg_ch WHERE chname = '$chname' ");
2066 $HTML .= qq {<div style="float: left">\n};
2067 $HTML .= qq {<form method="get" action="rectool.pl">\n};
2068 $HTML .= qq {<div>\n};
2069 $HTML .= qq {<input type="hidden" name="mode" value="program">\n};
2072 &draw_form_channel();
2075 $HTML .= qq {<select name="date">\n<option value="" selected>無指定</option>\n};
2076 $ary_ref = $dbh->selectcol_arrayref(
2077 "SELECT DISTINCT SUBSTRING(start, 1, 8) FROM epg_timeline ORDER BY start"
2079 $date_sel = $params{ 'date' };
2080 foreach my $date ( @{ $ary_ref } ) {
2081 my @date = $date =~ /(.{4})(.{2})(.{2})/;
2082 $date_prt = "$date[1]/$date[2]";
2084 if ( $date eq $date_sel ) {
2085 $HTML .= qq {<option value="$date" selected>$date_prt</option>\n};
2088 $HTML .= qq {<option value="$date">$date_prt</option>\n};
2091 $HTML .= qq {</select>\n};
2094 $HTML .= qq {<select name="category">\n<option value="" selected>無指定</option>\n};
2095 $category_sel = $params{ 'category' };
2096 foreach my $category ( keys %category ) {
2097 if ( $category eq $category_sel ) {
2098 $HTML .= qq {<option value="$category" selected>$category{$category}->{name}</option>\n};
2101 $HTML .= qq {<option value="$category">$category{$category}->{name}</option>\n};
2104 $HTML .= qq {</select>\n};
2107 $HTML .= qq {<input name="key" type="text" value="$key" style="width:200px" accesskey="s">\n};
2110 $HTML .= qq {<input type="submit" value="更新" accesskey="r">\n</div>\n</form>\n};
2113 sub draw_form_channel {
2114 $HTML .= qq {<select name="chtxt">\n};
2115 $HTML .= qq {<option value="" selected>無指定</option>\n} if ( shift ne 'nonone' );
2117 foreach my $key ( keys %chtxt_0_chname ) {
2118 my $value = $chtxt_0_chname{$key};
2119 if ( ($chtxt && $key eq $chtxt ) || ( $chname && $value eq $chname ) ) {
2120 $HTML .= qq {<option value="$key" selected>$value</option>\n};
2123 $HTML .= qq {<option value="$key">$value</option>\n};
2126 $HTML .= qq {</select>\n};
2131 my ( %selected, %checked );
2133 if ( $chtxt =~ /BS_103/ ) {
2134 $selected{F} = 'selected';
2136 elsif ( $chtxt =~ /CS_239|CS_240|CS_335/ ) {
2137 $selected{H} = 'selected';
2139 elsif ( $chtxt =~ /BS_101|BS_102/ || $bctype =~ /cs/ ) {
2140 $selected{W} = 'selected';
2142 elsif ( $bctype =~ /bs|te/ ) {
2143 $selected{H} = 'selected';
2145 $selected{g} = 'selected';
2146 $selected{s} = 'selected';
2147 $checked{a} = $chtxt =~ /CS_331|CS_332|CS_333|CS_334|CS_335/ || $category =~ /アニメ/ ? 'checked' : '';
2149 $checked{d} = $title =~ /\Q[二]\E|[二]|\Q(二)\E|(二)/ ? 'checked' : '';
2150 $checked{5} = $title =~ /5\.1|5.1/ ? 'checked' : '';
2151 $checked{2} = 'checked';
2156 my @opt = split //, $opt;
2157 foreach my $opt ( @opt ) {
2158 $selected{$opt} = 'selected' if ( $opt =~ /S|L|G|H|F/ );
2159 $checked {$opt} = 'checked' if ( $opt =~ /a|h|l|d|2|5/ );
2161 $checked{d} = $title =~ /\Q[二]\E|[二]|\Q(二)\E|(二)/ ? 'checked' : '';
2162 $checked{5} = $title =~ /5\.1|5.1/ ? 'checked' : '';
2164 # 画質/圧縮率ともに指定されていない場合、真ん中をselectedにする
2165 $selected{g} = 'selected' unless ( $selected{u} || $selected{i} || $selected{o} || $selected{p} );
2166 $selected{s} = 'selected' unless ( $selected{q} || $selected{w} || $selected{e} || $selected{r} );
2168 $HTML .= qq {<select name="opt">\n};
2169 #$HTML .= qq {<option value="S" $selected{S}>S 720x480</option>\n};
2170 $HTML .= qq {<option value="W" $selected{W}>W 854x480</option>\n};
2171 $HTML .= qq {<option value="H" $selected{H}>H 1280x720</option>\n};
2172 $HTML .= qq {<option value="F" $selected{F}>F 1920x1080</option>\n};
2173 $HTML .= qq {<option value="I" $selected{I}>I インタレ保持</option>\n};
2174 $HTML .= qq {</select>\n};
2176 $HTML .= qq {<select name="opt">\n};
2177 $HTML .= qq {<option value="u" $selected{u}>最低</option>\n};
2178 $HTML .= qq {<option value="i" $selected{i}>低</option>\n};
2179 $HTML .= qq {<option value="" $selected{g}>画質</option>\n};
2180 $HTML .= qq {<option value="o" $selected{o}>高</option>\n};
2181 $HTML .= qq {<option value="p" $selected{p}>最高</option>\n};
2182 $HTML .= qq {</select>\n};
2184 $HTML .= qq {<select name="opt">\n};
2185 $HTML .= qq {<option value="q" $selected{q}>最低</option>\n};
2186 $HTML .= qq {<option value="w" $selected{w}>低</option>\n};
2187 $HTML .= qq {<option value="" $selected{s}>圧縮率</option>\n};
2188 $HTML .= qq {<option value="e" $selected{e}>高</option>\n};
2189 $HTML .= qq {<option value="r" $selected{r}>最高</option>\n};
2190 $HTML .= qq {</select>\n};
2192 $HTML .= qq {<select name="opt">\n};
2193 $HTML .= qq {<option value="" $selected{s}>コンテナ</option>\n};
2194 $HTML .= qq {<option value="m" $selected{e}>MKV</option>\n};
2195 $HTML .= qq {<option value="4" $selected{r}>MP4</option>\n};
2196 $HTML .= qq {</select>\n};
2198 $HTML .= qq {<select name="opt">\n};
2199 $HTML .= qq {<option value="" $selected{s}>モバイル向け</option>\n};
2200 $HTML .= qq {<option value="1" $selected{e}>QVGA</option>\n};
2201 $HTML .= qq {<option value="2" $selected{r}>WVGA</option>\n};
2202 $HTML .= qq {<option value="B" $selected{B}>Blu-ray向け</option>\n};
2203 $HTML .= qq {</select>\n};
2205 $HTML .= qq {<input type="checkbox" name="opt" value="a" $checked{a}>24fps(主にアニメ)\n};
2206 $HTML .= qq {<input type="checkbox" name="opt" value="d" $checked{d}>二ヶ国語放送\n};
2207 #$HTML .= qq {<input type="checkbox" name="opt" value="2" $checked{2}>2passモード\n};
2208 $HTML .= qq {<input type="checkbox" name="opt" value="5" $checked{5}>5.1ch放送\n};
2209 $HTML .= qq {<br>\n};
2210 $HTML .= qq {<select name="opt">\n};
2211 $HTML .= qq {<option value="">移動なし</option>\n};
2212 $HTML .= qq {<option value="R">録画後移動</option>\n};
2213 $HTML .= qq {<option value="D">解読後移動</option>\n};
2214 $HTML .= qq {<option value="E">縁故後移動</option>\n};
2215 $HTML .= qq {</select>\n};
2216 $HTML .= qq {<input type="checkbox" name="opt" value="N">ファイル名日時追加\n} if ( $shift eq 'reserve' );
2217 $HTML .= qq {<input type="checkbox" name="every" value="1">隔週録画\n} if ( $shift eq 'reserve' );
2221 $chname = $params{ 'chname' };
2222 $chtxt = $params{ 'chtxt' };
2223 $start = $params{ 'start' };
2224 $stop = $params{ 'stop' };
2225 $bayesid = $params{ 'bayesid' };
2226 $id = $params{ 'id' };
2228 # chtxt と chname を相互に補完
2230 $chtxt = $dbh->selectrow_array("SELECT chtxt FROM epg_ch WHERE chname = '$chname'");
2232 elsif ( $chtxt && $chtxt_0_chname{$chtxt} ) {
2233 $chname = $chtxt_0_chname{$chtxt};
2234 ( $chtxt_sql = $chtxt ) =~ s/_0/_%/;
2235 $bctype = $dbh->selectrow_array("SELECT bctype FROM epg_ch WHERE chtxt LIKE '$chtxt_sql'");
2238 $chname = $dbh->selectrow_array("SELECT chname FROM epg_ch WHERE chtxt = '$chtxt'")
2242 ( $title, $desc, $longdesc, $category ) = $dbh->selectrow_array(
2243 "SELECT title, exp, longexp, category
2245 WHERE channel = '$chtxt' AND start = '$start' AND stop = '$stop' ");
2247 $bctype = $dbh->selectrow_array("SELECT bctype FROM epg_ch WHERE chtxt = '$chtxt'");
2251 ( $chtxt, $title, $begin, $end ) = $dbh->selectrow_array(
2252 "SELECT chtxt, title, btime, etime FROM auto_timeline_bayes WHERE id = '$bayesid' "
2254 ( $chname, $bctype ) = $dbh->selectrow_array(
2255 "SELECT chname, bctype FROM epg_ch WHERE chtxt = '$chtxt' "
2257 $start = str2datetime( $begin )->strftime( '%Y%m%d%H%M%S' );
2258 $stop = str2datetime( $end )->strftime( '%Y%m%d%H%M%S' );
2259 ( $desc, $longdesc, $category ) = $dbh->selectrow_array(
2260 "SELECT exp, longexp, category FROM epg_timeline WHERE channel = '$chtxt' AND start = '$start' AND stop = '$stop' "
2264 ( $type, $chtxt, $title, $begin, $end, $deltaday, $deltatime, $opt, $counter ) = $dbh->selectrow_array(
2265 "SELECT type, chtxt, title, btime, etime, deltaday, deltatime, opt, counter
2266 FROM timeline WHERE id = '$id' "
2269 ( $chname, $bctype ) = $dbh->selectrow_array(
2270 "SELECT chname, bctype FROM epg_ch WHERE chtxt LIKE '$chtxt_sql' "
2272 $start = str2datetime( $begin )->strftime( '%Y%m%d%H%M%S' );
2273 $stop = str2datetime( $end )->strftime( '%Y%m%d%H%M%S' );
2274 ( $desc, $longdesc, $category ) = $dbh->selectrow_array(
2275 "SELECT exp, longexp, category FROM epg_timeline WHERE channel = '$chtxt' AND start = '$start' AND stop = '$stop' "
2278 # set $chtxt_0, $chtxt_sql, $bctype_sql
2280 #( $chtxt_no0 ) = $chtxt =~ /(\d+)_/;
2281 @start = $start =~ /(.{4})(.{2})(.{2})(.{2})(.{2})/;
2282 @stop = $stop =~ /(.{4})(.{2})(.{2})(.{2})(.{2})/;
2283 $begin = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', @start, '00' );
2284 $end = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', @stop , '00' );
2286 if ( $params{ 'title' } ) {
2287 $title = $params{ 'title' };
2288 utf8::decode( $title );
2290 $HTML .= qq {<!-- chtxt=$chtxt chtxt_0=$chtxt_0 chtxt_sql=$chtxt_sql bctype=$bctype -->\n};
2295 my $is_same = $dbh->selectrow_array(
2296 "SELECT COUNT(*) FROM timeline WHERE chtxt = '$chtxt' AND btime = '$begin' AND etime = '$end'"
2298 my @overlap = &get_overlap();
2301 $HTML .= "同一の番組が既に存在します。<br>\n";
2304 elsif ( $overlap[0] >= 2 ) {
2305 $HTML .= "時間が被る番組が既に2個存在します。<br>\n";
2306 $HTML .= $overlap[1];
2316 my $ary_ref = $dbh->selectall_arrayref(
2317 "SELECT btime, etime, title
2319 INNER JOIN epg_ch ON timeline.chtxt = epg_ch.chtxt
2320 WHERE bctype LIKE '$bctype_sql' AND type IN $type_user_made
2322 AND etime > '$begin'
2327 my $overlap = $max = 0;
2329 foreach my $prg ( @{ $ary_ref } ) {
2330 $str .= "$prg->[0] ? $prg->[1] : $prg->[2]<br>\n";
2331 $overlap{$prg->[0]} += 1;
2332 $overlap{$prg->[1]} -= 1;
2334 foreach my $key ( sort keys %overlap ) {
2335 $overlap += $overlap{$key};
2336 $max = List::Util::max( $max, $overlap );
2339 return ( $max, $str );
2346 sub get_file_list_wrapper {
2347 local $base_dir = shift;
2350 &get_file_list( $base_dir );
2356 opendir ( DIR, $dir );
2357 my @list = sort readdir( DIR );
2360 foreach my $file ( @list ) {
2361 next if ( $file =~ /^\.{1,2}$/ );
2362 if ( -d "$dir/$file" ){
2363 &get_file_list("$dir/$file");
2366 $abs = "$dir/$file";
2367 utf8::decode( $abs );
2368 ( $rel ) = $abs =~ /^$base_dir\/(.*)$/;
2369 $ptr->( $rel, $abs );
2377 return $str =~ /.{4}-.{2}-.{2} .{2}:.{2}:.{2}/ ? 0 : 1;
2384 if ( strisjoined( $str ) ) {
2385 @time = $str =~ /(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})/;
2388 @time = $str =~ /(.{4})-(.{2})-(.{2}) (.{2}):(.{2}):(.{2})/;
2390 return DateTime->new(
2391 year => $time[0], month => $time[1], day => $time[2],
2392 hour => $time[3], minute => $time[4], second => $time[5],
2393 locale => 'ja_JP' , time_zone => $tz
2399 our %day_name_cache;
2401 if ( !$day_name_cache{$str} ) {
2402 $day_name_cache{$str} = str2datetime( $str )->day_name;
2404 return $day_name_cache{$str};
2411 my $dt_begin = ref( $begin ) eq 'DateTime' ? $begin : &str2datetime( $begin );
2412 my $dt_end = ref( $end ) eq 'DateTime' ? $end : &str2datetime( $end );
2414 my $str_begin = $dt_begin->strftime( '%m/%d(%a) %H:%M' );
2415 my $str_end = $dt_end ->strftime( $dt_begin->day == $dt_end->day ? '%H:%M' : '翌 %H:%M' );
2416 # utf8::encode( $str_begin );
2418 my ( $sec, $min, $hour );
2419 $sec = $dt_end->epoch - $dt_begin->epoch;
2420 $min = int( $sec / 60 );
2421 $sec = $sec - $min * 60;
2422 $hour = int( $min / 60 );
2423 $min = $min - $hour * 60;
2425 $str_diff .= $hour . '時間' if ( $hour );
2426 $str_diff .= $min . '分' if ( $min );
2427 $str_diff .= $sec . '秒' if ( $sec );
2429 return ( $str_begin, $str_end, $str_diff );
2432 sub sqlgetsuggested {
2433 my ( $btime, $etime ) = @_;
2434 $deltatime = 3 if ( !$deltatime );
2436 $btime_bgn = $btime->clone->subtract( hours => $deltatime )->strftime( '%Y%m%d%H%M%S' );
2437 $btime_end = $btime->clone->add( hours => $deltatime )->strftime( '%Y%m%d%H%M%S' );
2438 $etime_bgn = $etime->clone->subtract( hours => $deltatime )->strftime( '%Y%m%d%H%M%S' );
2439 $etime_end = $etime->clone->add( hours => $deltatime )->strftime( '%Y%m%d%H%M%S' );
2441 $ary_ref = $dbh->selectall_arrayref(
2442 "SELECT start, stop, title, exp
2444 WHERE channel LIKE '$chtxt_sql'
2445 AND start BETWEEN '$btime_bgn' AND '$btime_end'
2446 AND stop BETWEEN '$etime_bgn' AND '$etime_end' "
2448 #die Dumper $ary_ref;
2451 my $hash_r = ngram_counts( $title, 2 ); # bi-gram
2452 foreach my $program ( @{$ary_ref} ) {
2454 my $hash_k = ngram_counts( $program->[2], 2 );
2456 map $point += $hash_k->{$_}, keys %{$hash_r};
2457 push @{$hash{$point}}, $program if ( $point );
2466 my $slen = length($str);
2469 for (my $i=0; $i < $slen-$klen+1; $i++){
2470 $href->{substr($str, $i, $klen)}++;
2476 ( $chtxt_0 = $chtxt ) =~ s/(\d+)_\d+/$1_0/;
2477 ( $chtxt_sql = $chtxt ) =~ s/(\d+)_\d+/$1_%/;
2478 if ( $bctype =~ /bs|cs/ ) {
2479 $bctype_sql = '_s%';
2481 elsif ( $bctype =~ /te/ ) {
2482 $bctype_sql = 'te%';