root/trunk/install/perl/epgimport.pl

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

・ラジオ局録音の場合はepgimport実行しないように修正

  • 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 = "";
47
48 #引き数がアルか?
49 if ( $ARGV[0] eq "long" ){
50         #長期番組表取得
51         $rectime = 60;
52         $bsrectime = 120;
53 }elsif( $ARGV[0] > 0 ){
54         $stationid = $ARGV[0];
55         $rectime = 3;
56         $bsrectime = 36;
57 }else{
58         #短期番組表取得
59         $rectime = 3;
60         $bsrectime = 36;
61 }
62 #データ量比較
63 #3秒   16350 Aug 10 16:21 __27-epg-short.xml
64 #12秒  56374 Aug 10 16:21 __27-epg-long.xml
65 #60秒 127735 Aug 10 16:23 __27-epg-velylong.xml
66
67 #重複起動確認
68 $processes =  &processfind("epgimport.pl");
69 if ($processes > 1 ){
70 &writelog("epgimport processes exist. exit:");
71 exit;
72 }
73
74
75 $dbh = DBI->connect($DSN,$DBUser,$DBPass) ||die $DBI::error;;
76
77 #局指定があるなら、単一放送局指定モード
78 if ($stationid > 0){
79         $sth = $dbh->prepare($stmt{'epgimport.1'});
80         $sth->execute($stationid);
81         @data = $sth->fetchrow_array();
82         unless($data[0] == 1){#局の数が1でなければ異常終了
83                 &writelog("epgimport ERROR Invalid station id ($stationid).");
84                 exit 1;
85         }else{
86         $sth = $dbh->prepare($stmt{'epgimport.2'});
87         $sth->execute($stationid);
88         @data = $sth->fetchrow_array();
89         $channel = $data[0];
90         $ontvcode = $data[1];
91         if ($channel > 0){
92                 &writelog("epgimport DEBUG Single station mode (ch:$channel / $ontvcode).");
93         }else{#ラジオ局などの場合
94                 &writelog("epgimport ABORT SID $stationid is not Digital TV ch.");
95                 exit;
96         }#endif ラジオ局かどうか
97         }#end unless($data[0] == 1
98 }#endif $stationid > 0
99
100 #地デジ----------------------------------------
101 #受信局確認
102 if ($channel >= 13 && $channel <= 62){#局指定があるなら
103         $stations{$channel} = $ontvcode;
104         $uset = 1;
105 }elsif($channel >= 100){
106         $uset = 0; #地デジ範囲外の局
107 }else{
108         $sth = $dbh->prepare($stmt{'epgimport.3'});
109         $sth->execute();
110        
111         while (@data = $sth->fetchrow_array()) {
112                 $stations{$data[0]} = $data[1];
113         }#end while
114         $uset = 1;
115 }#end if
116
117 if ($uset == 1){
118 foreach $channel ( keys %stations ) {
119         $ontvcode = $stations{$channel};
120         #print "$ontvcode $digitalch\n";
121         &chkrecordingschedule;
122         #print "$recpt1path $channel $rectime $recfolderpath/__$channel.m2t\n";
123         $oserr = `$recpt1path $channel $rectime $recfolderpath/__$channel.m2t`;
124         #print "$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml\n";
125         $oserr = `$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`;
126         #print "cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
127         $oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
128         unlink "$recfolderpath/__$channel.m2t";
129         unlink "$xmloutpath/__$channel-epg.xml";
130 }#end foreach
131 }#endif
132
133 #BS----------------------------------------
134 #受信局確認
135 if ($channel >= 100 && $channel <= 222 ){#局指定があるなら
136         $usebs = 1;
137 }elsif($channel >= 13 && $channel <= 62){
138         $usebs = 0;     #地デジ局指定の場合、スキップ。
139 }elsif($channel >= 223){
140         $usebs = 0;     #CS局指定の場合もスキップ
141 }else{
142         $sth = $dbh->prepare($stmt{'epgimport.4'});
143         $sth->execute();
144         @data = $sth->fetchrow_array();
145         if ($data[0] > 0 ){
146                 $usebs = 1;
147         }
148 }#end if
149
150 if ($usebs == 1){
151         #$ontvcode = $stations{$channel};
152         $channel = 211;
153         #print "$ontvcode $digitalch\n";
154         &chkrecordingschedule;
155         #print "$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t\n";
156         $oserr = `$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t`;
157         #print "$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml\n";
158         $oserr = `$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`;
159         #print "cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
160         $oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
161         unlink "$recfolderpath/__$channel.m2t";
162         unlink "$xmloutpath/__$channel-epg.xml";
163 }else{
164         &writelog("epgimport DEBUG Skip BS.$channel:$usebs");
165 }
166
167
168
169 #CS----------------------------------------
170 #CSは取得に時間がかかるがどうしようか
171 #ひとまずlongモードのときだけ取得
172 if ( $ARGV[0] eq "long" ){
173 #受信局確認
174 if ($channel >= 223  ){#局指定があるなら
175         $usecs = 1;
176 }else{
177         $sth = $dbh->prepare($stmt{'epgimport.5'});
178         $sth->execute();
179         @data = $sth->fetchrow_array();
180         if ($data[0] > 0 ){
181                 $usecs = 1;
182         }
183 }#end if
184
185 if ($usecs == 1){
186 #一気に録画して
187         $channela = "CS8";
188         #print "$ontvcode $digitalch\n";
189         &chkrecordingschedule;
190         #print "$recpt1path $channela $bsrectime $recfolderpath/__$channela.m2t\n";
191         $oserr = `$recpt1path $channela $bsrectime $recfolderpath/__$channela.m2t`;
192
193         $channelb = "CS24";
194         &chkrecordingschedule;
195         #print "$recpt1path $channelb $bsrectime $recfolderpath/__$channelb.m2t\n";
196         $oserr = `$recpt1path $channelb $bsrectime $recfolderpath/__$channelb.m2t`;
197
198 #時間のかかるepgdumpまとめてあとまわし
199         #print "nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml\n";
200         $oserr = `nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml`;
201         #print "cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
202         $oserr = `cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
203         unlink "$recfolderpath/__$channela.m2t";
204         unlink "$xmloutpath/__$channela-epg.xml";
205
206         #print "nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml\n";
207         $oserr = `nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml`;
208         #print "cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
209         $oserr = `cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
210         unlink "$recfolderpath/__$channelb.m2t";
211         unlink "$xmloutpath/__$channelb-epg.xml";
212 }else{
213         &writelog("epgimport DEBUG Skip CS.");
214 }#endif use
215 }else{
216         if ($channel >= 223  ){#局指定があるなら
217                 &writelog("epgimport ERROR CS Station No. was ignored. CS EPG get long mode only.");
218         }
219 }#end if long
220
221
222 sub chkrecordingschedule{
223 #放送予定まで近くなったら、チューナー使いつづけないようにEPG取得中断
224 my $now = time() ;
225 my $fiveminitsafter = time() + 60 * 4;
226 my $rows = -2;
227 $now = &epoch2foldate($now);
228 $fiveminitsafter = &epoch2foldate($fiveminitsafter);
229
230 #録画予定取得
231 $sth = $dbh->prepare($stmt{'epgimport.6'});
232 $sth->execute($now,$fiveminitsafter,$now,$fiveminitsafter);
233
234 while (@data = $sth->fetchrow_array()) {
235 #
236 }#end while
237
238 $rows = $sth->rows;
239
240 if ($rows > 0 ){
241         &writelog("epgimport ABORT The recording schedule had approached.");
242         exit ;
243 }else{
244         &writelog("epgimport DEBUG Near rec program is $rows.:$now:$fiveminitsafter");
245 }#end if
246 }#endsub chkrecordingschedule
247
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed