root/trunk/install/perl/epgimport.pl

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

・放送波からのEPG番組表取得に対応。
・foltia_epgテーブル構成変更
・folcast.phpがSQLiteでまったく動作していなかったのを修正

  • 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         &writelog("epgimport DEBUG Single station mode (ch:$channel / $ontvcode).");
92         }
93 }#endif $stationid > 0
94
95 #地デジ----------------------------------------
96 #受信局確認
97 if ($channel >= 13 && $channel <= 62){#局指定があるなら
98         $stations{$channel} = $ontvcode;
99         $uset = 1;
100 }elsif($channel >= 100){
101         $uset = 0; #地デジ範囲外の局
102 }else{
103         $sth = $dbh->prepare($stmt{'epgimport.3'});
104         $sth->execute();
105        
106         while (@data = $sth->fetchrow_array()) {
107                 $stations{$data[0]} = $data[1];
108         }#end while
109         $uset = 1;
110 }#end if
111
112 if ($uset == 1){
113 foreach $channel ( keys %stations ) {
114         $ontvcode = $stations{$channel};
115         #print "$ontvcode $digitalch\n";
116         &chkrecordingschedule;
117         #print "$recpt1path $channel $rectime $recfolderpath/__$channel.m2t\n";
118         $oserr = `$recpt1path $channel $rectime $recfolderpath/__$channel.m2t`;
119         #print "$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml\n";
120         $oserr = `$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`;
121         #print "cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
122         $oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
123         unlink "$recfolderpath/__$channel.m2t";
124         unlink "$xmloutpath/__$channel-epg.xml";
125 }#end foreach
126 }#endif
127
128 #BS----------------------------------------
129 #受信局確認
130 if ($channel >= 100 && $channel <= 222 ){#局指定があるなら
131         $usebs = 1;
132 }elsif($channel >= 13 && $channel <= 62){
133         $usebs = 0;     #地デジ局指定の場合、スキップ。
134 }elsif($channel >= 223){
135         $usebs = 0;     #CS局指定の場合もスキップ
136 }else{
137         $sth = $dbh->prepare($stmt{'epgimport.4'});
138         $sth->execute();
139         @data = $sth->fetchrow_array();
140         if ($data[0] > 0 ){
141                 $usebs = 1;
142         }
143 }#end if
144
145 if ($usebs == 1){
146         #$ontvcode = $stations{$channel};
147         $channel = 211;
148         #print "$ontvcode $digitalch\n";
149         &chkrecordingschedule;
150         #print "$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t\n";
151         $oserr = `$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t`;
152         #print "$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml\n";
153         $oserr = `$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`;
154         #print "cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
155         $oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
156         unlink "$recfolderpath/__$channel.m2t";
157         unlink "$xmloutpath/__$channel-epg.xml";
158 }else{
159         &writelog("epgimport DEBUG Skip BS.$channel:$usebs");
160 }
161
162
163
164 #CS----------------------------------------
165 #CSは取得に時間がかかるがどうしようか
166 #ひとまずlongモードのときだけ取得
167 if ( $ARGV[0] eq "long" ){
168 #受信局確認
169 if ($channel >= 223  ){#局指定があるなら
170         $usecs = 1;
171 }else{
172         $sth = $dbh->prepare($stmt{'epgimport.5'});
173         $sth->execute();
174         @data = $sth->fetchrow_array();
175         if ($data[0] > 0 ){
176                 $usecs = 1;
177         }
178 }#end if
179
180 if ($usecs == 1){
181 #一気に録画して
182         $channela = "CS8";
183         #print "$ontvcode $digitalch\n";
184         &chkrecordingschedule;
185         #print "$recpt1path $channela $bsrectime $recfolderpath/__$channela.m2t\n";
186         $oserr = `$recpt1path $channela $bsrectime $recfolderpath/__$channela.m2t`;
187
188         $channelb = "CS24";
189         &chkrecordingschedule;
190         #print "$recpt1path $channelb $bsrectime $recfolderpath/__$channelb.m2t\n";
191         $oserr = `$recpt1path $channelb $bsrectime $recfolderpath/__$channelb.m2t`;
192
193 #時間のかかるepgdumpまとめてあとまわし
194         #print "nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml\n";
195         $oserr = `nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml`;
196         #print "cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
197         $oserr = `cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
198         unlink "$recfolderpath/__$channela.m2t";
199         unlink "$xmloutpath/__$channela-epg.xml";
200
201         #print "nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml\n";
202         $oserr = `nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml`;
203         #print "cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl\n";
204         $oserr = `cat $xmloutpath/__$channelb-epg.xml | $toolpath/perl/xmltv2foltia.pl`;
205         unlink "$recfolderpath/__$channelb.m2t";
206         unlink "$xmloutpath/__$channelb-epg.xml";
207 }else{
208         &writelog("epgimport DEBUG Skip CS.");
209 }#endif use
210 }else{
211         if ($channel >= 223  ){#局指定があるなら
212                 &writelog("epgimport ERROR CS Station No. was ignored. CS EPG get long mode only.");
213         }
214 }#end if long
215
216
217 sub chkrecordingschedule{
218 #放送予定まで近くなったら、チューナー使いつづけないようにEPG取得中断
219 my $now = time() ;
220 my $fiveminitsafter = time() + 60 * 4;
221 my $rows = -2;
222 $now = &epoch2foldate($now);
223 $fiveminitsafter = &epoch2foldate($fiveminitsafter);
224
225 #録画予定取得
226 $sth = $dbh->prepare($stmt{'epgimport.6'});
227 $sth->execute($now,$fiveminitsafter,$now,$fiveminitsafter);
228
229 while (@data = $sth->fetchrow_array()) {
230 #
231 }#end while
232
233 $rows = $sth->rows;
234
235 if ($rows > 0 ){
236         &writelog("epgimport ABORT The recording schedule had approached.");
237         exit ;
238 }else{
239         &writelog("epgimport DEBUG Near rec program is $rows.:$now:$fiveminitsafter");
240 }#end if
241 }#endsub chkrecordingschedule
242
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。
track feed