Linux-DVB-DVBT-Apps-QuartzPVR
view release on metacpan or search on metacpan
scripts/dvbt-qpvr-scan view on Meta::CPAN
) or pod2usage(2) ;
pod2usage(1) if $help;
pod2usage(-verbose => 2) if $man;
## Just show country list?
if ($list_countries)
{
my @countries = Linux::DVB::DVBT::Freq::country_list() ;
print "Supported countries:\n" ;
foreach my $aref (@countries)
{
my ($code, $country) = @$aref ;
print "$code : $country\n" ;
}
exit 0 ;
}
## Show status
if ($status)
{
show_status() ;
exit 0 ;
}
##==========================================================================
## RUN SCAN
## Check for a running scan
my ($pid, $status_aref) = read_status() ;
if ($pid < 0)
{
# clear out status file
write_log({}, 0) ;
}
## Run scan
$DEBUG_PERL = $DEBUG if ($DEBUG_PERL < $DEBUG) ;
$DEBUG_DVB = $DEBUG if ($DEBUG_DVB < $DEBUG) ;
Linux::DVB::DVBT->debug($DEBUG_PERL) ;
Linux::DVB::DVBT->dvb_debug($DEBUG_DVB) ;
Linux::DVB::DVBT->verbose($VERBOSE) ;
## Create dvb
## NOTE: With default object settings, the application will
## die on *any* error, so there is no error checking in this script
##
my $dvb = Linux::DVB::DVBT->new(
'adapter' => $adap,
'scan_cb_start' => \&scan_cb,
'scan_cb_end' => \&scan_cb,
'scan_cb_loop_start' => \&scan_cb,
'scan_cb_loop_end' => \&scan_cb,
) ;
## see if frontend is currently busy
my $frontend_busy = $dvb->is_busy() ;
if ($frontend_busy)
{
print "Fontend busy!\n" ;
## Finish off
my %info = (
'complete' => 1,
'estimated_percent' => 0,
'busy' => 1,
) ;
write_log(\%info, 0) ;
exit 1 ;
}
# set options
$dvb->config_path($config) if $config ;
if ($clean)
{
$dvb->merge(0) ;
}
# check for any previous scan
my $last_tuning_href = $dvb->get_tuning_info() ;
my $got_previous = 0 ;
if (exists($last_tuning_href->{'freqfile'}) && keys %{$last_tuning_href->{'freqfile'}})
{
$got_previous = 1 ;
}
Linux::DVB::DVBT::prt_data("Existing tuning info=", $last_tuning_href) if $DEBUG>=10 ;
# check args
if ((@ARGV == 0) && !$got_previous)
{
print "$0: No frequency file given, and no previous scans completed.\n" ;
pod2usage(-verbose => 2) ;
}
## check how we'll be scanning
my $scan_type = "" ;
my $freqfile ;
my $country ;
if (@ARGV > 0)
{
if (length $ARGV[0] == 2)
{
$country = uc $ARGV[0] ;
$scan_type = "country" ;
}
else
{
$freqfile = $ARGV[0] ;
$scan_type = "file" ;
}
}
if ($use_config && $got_previous)
{
$scan_type = "previous" ;
}
# check args
if (!$scan_type)
{
print "$0: No frequency file given, and no previous scans completed.\n" ;
pod2usage(-verbose => 2) ;
}
scripts/dvbt-qpvr-scan view on Meta::CPAN
{
## show status
show_status() ;
exit 0 ;
}
# if ($country)
# {
# print STDERR "Scanning frequencies for $country. Please wait, this will take some time...\n" ;
# $dvb->scan_from_country($country) ;
# }
# else
# {
# ## Check for a running scan
# if ($pid < 0)
# {
# ## Run scan
# if (@ARGV > 0)
# {
# $freqfile = $ARGV[0] ;
# $dvb->scan_from_file($freqfile) ;
# }
# else
# {
# # use previous scan frequencies
# print STDERR "Using previous scan results to set frequency list...\n" ;
# $dvb->scan_from_previous() ;
# }
# }
# else
# {
# ## show status
# show_status() ;
# exit 0 ;
# }
#
# }
## Finish off
my %info = (
'complete' => 1,
'estimated_percent' => 100,
'scan_info' => $dvb->tuning(),
) ;
write_log(\%info, 0) ;
exit 0 ;
#=================================================================================
#---------------------------------------------------------------------------------
sub write_log
{
my ($info_href, $append) = @_ ;
$info_href ||= {} ;
my $curr_freq = 0 ;
my $percent = 0 ;
my $busy = 0 ;
if (exists($info_href->{'estimated_percent'}))
{
$percent = $info_href->{'estimated_percent'} ;
}
if (exists($info_href->{'current_freq'}) && $info_href->{'current_freq'})
{
$curr_freq = $info_href->{'current_freq'} ;
}
if (exists($info_href->{'busy'}))
{
$busy = $info_href->{'busy'} ;
}
# Write out record - build in memory then write once
my @record = ($START_RECORD) ;
push @record, "PID = $$" ;
push @record, "BUSY = $busy" ;
push @record, "PERCENT = $percent" ;
push @record, "FREQ = $curr_freq" ;
if (exists($info_href->{'scan_info'}))
{
## Channels
if (exists($info_href->{'scan_info'}{'pr'}))
{
push @record, "CHANNELS:" ;
my $progs_href = $info_href->{'scan_info'}{'pr'} ;
foreach my $prog (sort { $progs_href->{$a}{'lcn'} <=> $progs_href->{$b}{'lcn'} } keys %$progs_href)
{
push @record, sprintf(":%d:$prog:%d:%s:%s:",
$progs_href->{$prog}{'lcn'},
$progs_href->{$prog}{'tsid'},
$progs_href->{$prog}{'net'},
($progs_href->{$prog}{'type'} == 1 ? "tv" : "radio"),
) ;
}
}
## Frequencies
if (exists($info_href->{'scan_info'}{'freqs'}))
{
push @record, "FREQS:" ;
my $freqs_href = $info_href->{'scan_info'}{'freqs'} ;
foreach my $freq (sort { $a <=> $b } keys %$freqs_href)
{
push @record, sprintf(":$freq:%d:%d:%d:",
$freqs_href->{$freq}{'seen'},
$freqs_href->{$freq}{'tuned'},
($freq==$curr_freq ? 1 : 0),
) ;
}
}
elsif (exists($info_href->{'scan_info'}{'freq_file'}))
{
push @record, "FREQS:" ;
my $freqs_href = $info_href->{'scan_info'}{'freq_file'} ;
foreach my $freq (sort { $a <=> $b } keys %$freqs_href)
{
push @record, sprintf(":$freq:%d:%d:%d:",
0,
0,
($freq==$curr_freq ? 1 : 0),
) ;
}
}
elsif (exists($info_href->{'tuning_list'}))
{
push @record, "FREQS:" ;
my $freqs_aref = $info_href->{'tuning_list'} ;
if ($curr_freq)
{
my %freqs = map { $_->{'frequency'} => 1 } @$freqs_aref ;
if (!exists($freqs{$curr_freq}))
{
push @$freqs_aref, {
'frequency' => $curr_freq,
( run in 1.130 second using v1.01-cache-2.11-cpan-39bf76dae61 )