root/trunk/install/perl/epgimport.pl

リビジョン 129, 7.3 kB (コミッタ: sorshi, コミット時期: 14 年 前)

TSファイル取得時間を見直して、110度CSの取得が異常に重い問題に対処しました。

  • svn:executable 属性の設定値: *
Line 
1 #!/usr/bin/perl
2 #
3 #
4 # Anime recording system foltia
5 # http://www.dcc-jpl.com/soft/foltia/
6 #
7 # epgimport.pl
8 #
9 # EPG番組表取得
10 # tsを取得してepgdump経由でepgテーブルにインポートします。
11 # 内部でxmltv2foltia.plを呼んで実際の追加処理を行います。
12 #
13 # usage
14 # epgimport.pl [long]  #longがつくと一週間分
15 # epgimport.pl [stationid]  #放送局ID指定でそのチャンネルだけ短時間で取得
16 #
17 # DCC-JPL Japan/foltia project
18 #
19
20 use DBI;
21 use DBD::Pg;
22 use DBD::SQLite;
23 #use Schedule::At;
24 #use Time::Local;
25 use Jcode;
26
27 $path = $0;
28 $path =~ s/epgimport.pl$//i;
29 if ($path ne "./"){
30 push( @INC, "$path");
31 }
32
33 require "foltialib.pl";
34
35 my $ontvcode = "";
36 my $channel = "";
37 my @date = ();
38 my $recpt1path = $toolpath . "/perl/tool/recpt1"; #ほかのキャプチャデバイス作ってる人はココを変更
39 my $epgdumppath = $toolpath ."/perl/tool"; #epgdumpのあるディレクトリ
40 my $xmloutpath = "/tmp";
41 my %stations;
42 my $uset = "";
43 my $usebs = "";
44 my $usecs = "";
45 my $stationid = "" ;
46 my $rectime = 0;
47 my $bsrectime = 0;
48 my $cs1rectime = 0;
49 my $cs2rectime = 0;
50
51
52 #引き数がアルか?
53 if ( $ARGV[0] eq "long" ){
54         #長期番組表取得
55         $rectime = 60;
56         $bsrectime = 120;
57         $cs1rectime = 60;
58         $cs2rectime = 60;
59 }elsif( $ARGV[0] > 0 ){
60         $stationid = $ARGV[0];
61         $rectime = 3;
62         $bsrectime = 36;
63         $cs1rectime = 15;
64         $cs2rectime = 5;
65 }else{
66         #短期番組表取得
67         $rectime = 3;
68         $bsrectime = 36;
69         $cs1rectime = 15;
70         $cs2rectime = 5;
71 }
72 #データ量比較
73 #3秒   16350 Aug 10 16:21 __27-epg-short.xml
74 #12秒  56374 Aug 10 16:21 __27-epg-long.xml
75 #60秒 127735 Aug 10 16:23 __27-epg-velylong.xml
76
77 #重複起動確認
78 $processes =  &processfind("epgimport.pl");
79 if ($processes > 1 ){
80 &writelog("epgimport processes exist. exit:");
81 exit;
82 }
83
84
85 $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
86
87 #局指定があるなら、単一放送局指定モード
88 if ($stationid > 0){
89         $sth = $dbh->prepare($stmt{'epgimport.1'});
90         $sth->execute($stationid);
91         @data = $sth->fetchrow_array();
92         unless($data[0] == 1){#局の数が1でなければ異常終了
93                 &writelog("epgimport ERROR Invalid station id ($stationid).");
94                 exit 1;
95         }else{
96         $sth = $dbh->prepare($stmt{'epgimport.2'});
97         $sth->execute($stationid);
98         @data = $sth->fetchrow_array();
99         $channel = $data[0];
100         $ontvcode = $data[1];
101         if ($channel > 0){
102                 &writelog("epgimport DEBUG Single station mode (ch:$channel / $ontvcode).");
103         }else{#ラジオ局などの場合
104                 &writelog("epgimport ABORT SID $stationid is not Digital TV ch.");
105                 exit;
106         }#endif ラジオ局かどうか
107         }#end unless($data[0] == 1
108 }#endif $stationid > 0
109
110 #地デジ----------------------------------------
111 #受信局確認
112 if ($channel >= 13 && $channel <= 62){#局指定があるなら
113         $stations{$channel} = $ontvcode;
114         $uset = 1;
115 }elsif($channel >= 100){
116         $uset = 0; #地デジ範囲外の局
117 }else{
118         $sth = $dbh->prepare($stmt{'epgimport.3'});
119         $sth->execute();
120        
121         while (@data = $sth->fetchrow_array()) {
122                 $stations{$data[0]} = $data[1];
123         }#end while
124         $uset = 1;
125 }#end if
126
127 if ($uset == 1){
128 foreach $channel ( keys %stations ) {
129         $ontvcode = $stations{$channel};
130         #print "$ontvcode $digitalch\n";
131         &chkrecordingschedule;
132         #print "$recpt1path $channel $rectime $recfolderpath/__$channel.m2t\n";
133         $oserr = `$recpt1path $channel $rectime $recfolderpath/__$channel.m2t`;
134         #print "$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml\n";
135         $oserr = `$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`;
136         #print "cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
137         $oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
138         unlink "$recfolderpath/__$channel.m2t";
139         unlink "$xmloutpath/__$channel-epg.xml";
140 }#end foreach
141 }#endif
142
143 #BS----------------------------------------
144 #受信局確認
145 if ($channel >= 100 && $channel <= 222 ){#局指定があるなら
146         $usebs = 1;
147 }elsif($channel >= 13 && $channel <= 62){
148         $usebs = 0;     #地デジ局指定の場合、スキップ。
149 }elsif($channel >= 223){
150         $usebs = 0;     #CS局指定の場合もスキップ
151 }else{
152         $sth = $dbh->prepare($stmt{'epgimport.4'});
153         $sth->execute();
154         @data = $sth->fetchrow_array();
155         if ($data[0] > 0 ){
156                 $usebs = 1;
157         }
158 }#end if
159
160 if ($usebs == 1){
161         #$ontvcode = $stations{$channel};
162         $channel = 211;
163         #print "$ontvcode $digitalch\n";
164         &chkrecordingschedule;
165         #print "$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t\n";
166         $oserr = `$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t`;
167         #print "$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml\n";
168         $oserr = `$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`;
169         #print "cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
170         $oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
171         unlink "$recfolderpath/__$channel.m2t";
172         unlink "$xmloutpath/__$channel-epg.xml";
173 }else{
174         &writelog("epgimport DEBUG Skip BS.$channel:$usebs");
175 }
176
177
178
179 #CS----------------------------------------
180 #if ( $ARGV[0] eq "long" ){ #短時間録画なら異常に重くはならないことを発見した
181 #受信局確認
182 if ($channel >= 223  ){#局指定があるなら
183         $usecs = 1;
184 }else{
185         $sth = $dbh->prepare($stmt{'epgimport.5'});
186         $sth->execute();
187         @data = $sth->fetchrow_array();
188         if ($data[0] > 0 ){
189                 $usecs = 1;
190         }
191 }#end if
192
193 if ($usecs == 1){
194 #一気に録画して
195         $channela = "CS8";
196         #print "$ontvcode $digitalch\n";
197         &chkrecordingschedule;
198         #print "$recpt1path $channela $bsrectime $recfolderpath/__$channela.m2t\n";
199         $oserr = `$recpt1path $channela $cs1rectime $recfolderpath/__$channela.m2t`;
200
201         $channelb = "CS24";
202         &chkrecordingschedule;
203         #print "$recpt1path $channelb $bsrectime $recfolderpath/__$channelb.m2t\n";
204         $oserr = `$recpt1path $channelb $cs2rectime $recfolderpath/__$channelb.m2t`;
205
206 #時間のかかるepgdumpまとめてあとまわし
207         #print "nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml\n";
208         $oserr = `$epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml`;
209         #print "cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
210         $oserr = `cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
211         unlink "$recfolderpath/__$channela.m2t";
212         unlink "$xmloutpath/__$channela-epg.xml";
213
214         #print "nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml\n";
215         $oserr = `$epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml`;
216         #print "cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
217         $oserr = `cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
218         unlink "$recfolderpath/__$channelb.m2t";
219         unlink "$xmloutpath/__$channelb-epg.xml";
220 }else{
221         &writelog("epgimport DEBUG Skip CS.");
222 }#endif use
223 #}else{
224 #       if ($channel >= 223  ){#局指定があるなら
225 #               &writelog("epgimport ERROR CS Station No. was ignored. CS EPG get long mode only.");
226 #       }
227 #}#end if long
228
229
230 sub chkrecordingschedule{
231 #放送予定まで近くなったら、チューナー使いつづけないようにEPG取得中断
232 my $now = time() ;
233 my $fiveminitsafter = time() + 60 * 4;
234 my $rows = -2;
235 $now = &epoch2foldate($now);
236 $fiveminitsafter = &epoch2foldate($fiveminitsafter);
237
238 #録画予定取得
239 $sth = $dbh->prepare($stmt{'epgimport.6'});
240 $sth->execute($now,$fiveminitsafter,$now,$fiveminitsafter);
241
242 while (@data = $sth->fetchrow_array()) {
243 #
244 }#end while
245
246 $rows = $sth->rows;
247
248 if ($rows > 0 ){
249         &writelog("epgimport ABORT The recording schedule had approached.");
250         exit ;
251 }else{
252         &writelog("epgimport DEBUG Near rec program is $rows.:$now:$fiveminitsafter");
253 }#end if
254 }#endsub chkrecordingschedule
255
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed