| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
use DBI; |
|---|
| 21 |
use DBD::Pg; |
|---|
| 22 |
use DBD::SQLite; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 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"; |
|---|
| 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 |
|
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 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){ |
|---|
| 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 |
} |
|---|
| 97 |
} |
|---|
| 98 |
} |
|---|
| 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 |
} |
|---|
| 114 |
$uset = 1; |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
if ($uset == 1){ |
|---|
| 118 |
foreach $channel ( keys %stations ) { |
|---|
| 119 |
$ontvcode = $stations{$channel}; |
|---|
| 120 |
|
|---|
| 121 |
&chkrecordingschedule; |
|---|
| 122 |
|
|---|
| 123 |
$oserr = `$recpt1path $channel $rectime $recfolderpath/__$channel.m2t`; |
|---|
| 124 |
|
|---|
| 125 |
$oserr = `$epgdumppath/epgdump $ontvcode $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`; |
|---|
| 126 |
|
|---|
| 127 |
$oserr = `cat $xmloutpath/__$channel-epg.xml | $toolpath/perl/xmltv2foltia.pl`; |
|---|
| 128 |
unlink "$recfolderpath/__$channel.m2t"; |
|---|
| 129 |
unlink "$xmloutpath/__$channel-epg.xml"; |
|---|
| 130 |
} |
|---|
| 131 |
} |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 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; |
|---|
| 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 |
} |
|---|
| 149 |
|
|---|
| 150 |
if ($usebs == 1){ |
|---|
| 151 |
|
|---|
| 152 |
$channel = 211; |
|---|
| 153 |
|
|---|
| 154 |
&chkrecordingschedule; |
|---|
| 155 |
|
|---|
| 156 |
$oserr = `$recpt1path $channel $bsrectime $recfolderpath/__$channel.m2t`; |
|---|
| 157 |
|
|---|
| 158 |
$oserr = `$epgdumppath/epgdump /BS $recfolderpath/__$channel.m2t $xmloutpath/__$channel-epg.xml`; |
|---|
| 159 |
|
|---|
| 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 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 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 |
} |
|---|
| 184 |
|
|---|
| 185 |
if ($usecs == 1){ |
|---|
| 186 |
|
|---|
| 187 |
$channela = "CS8"; |
|---|
| 188 |
|
|---|
| 189 |
&chkrecordingschedule; |
|---|
| 190 |
|
|---|
| 191 |
$oserr = `$recpt1path $channela $bsrectime $recfolderpath/__$channela.m2t`; |
|---|
| 192 |
|
|---|
| 193 |
$channelb = "CS24"; |
|---|
| 194 |
&chkrecordingschedule; |
|---|
| 195 |
|
|---|
| 196 |
$oserr = `$recpt1path $channelb $bsrectime $recfolderpath/__$channelb.m2t`; |
|---|
| 197 |
|
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
$oserr = `nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channela.m2t $xmloutpath/__$channela-epg.xml`; |
|---|
| 201 |
|
|---|
| 202 |
$oserr = `cat $xmloutpath/__$channela-epg.xml | $toolpath/perl/xmltv2foltia.pl`; |
|---|
| 203 |
unlink "$recfolderpath/__$channela.m2t"; |
|---|
| 204 |
unlink "$xmloutpath/__$channela-epg.xml"; |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
$oserr = `nice -n 19 $epgdumppath/epgdump /CS $recfolderpath/__$channelb.m2t $xmloutpath/__$channelb-epg.xml`; |
|---|
| 208 |
|
|---|
| 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 |
} |
|---|
| 215 |
}else{ |
|---|
| 216 |
if ($channel >= 223 ){ |
|---|
| 217 |
&writelog("epgimport ERROR CS Station No. was ignored. CS EPG get long mode only."); |
|---|
| 218 |
} |
|---|
| 219 |
} |
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
sub chkrecordingschedule{ |
|---|
| 223 |
|
|---|
| 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 |
} |
|---|
| 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 |
} |
|---|
| 246 |
} |
|---|
| 247 |
|
|---|