1 |
pcg |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
# dumps "interesting" data about tv channels |
4 |
|
|
|
5 |
|
|
use Getopt::Long; |
6 |
|
|
|
7 |
|
|
use Video::Frequencies; |
8 |
|
|
use Video::Capture::V4l; |
9 |
|
|
use Video::Capture::VBI qw/:DEFAULT %VPS_CNI %VT_NI/; |
10 |
|
|
use Video::XawTV; |
11 |
|
|
|
12 |
|
|
GetOptions "+verbose|v" => \$verbose |
13 |
|
|
or exit 1; |
14 |
|
|
|
15 |
|
|
$rc = new Video::XawTV; |
16 |
|
|
eval { $rc->load("$ENV{HOME}/.xawtv") }; |
17 |
|
|
|
18 |
|
|
$ftab = $rc->opt('freqtab') || "pal-europe"; |
19 |
|
|
$freq = $CHANLIST{$ftab} or die "no such frequency table: $ftab"; |
20 |
|
|
|
21 |
|
|
$v4l = new Video::Capture::V4l; |
22 |
|
|
$tuner = $v4l->tuner(0); |
23 |
|
|
$channel = $v4l->channel(0); |
24 |
|
|
|
25 |
|
|
$tuner->mode(MODE_PAL); $tuner->set; |
26 |
|
|
$channel->norm(MODE_PAL); $channel->set; |
27 |
|
|
|
28 |
|
|
$vbi = new Video::Capture::V4l::VBI or die; |
29 |
|
|
$vbi_fd = $vbi->fileno; |
30 |
|
|
|
31 |
|
|
$|=1; |
32 |
|
|
|
33 |
|
|
my @channels; |
34 |
|
|
|
35 |
|
|
for $chan (sort keys %$freq) { |
36 |
|
|
my $f = $freq->{$chan}; |
37 |
|
|
print "tuning to $chan ($f)..."; |
38 |
|
|
$v4l->freq($f); |
39 |
|
|
select undef,undef,undef,0.2; # shit! |
40 |
|
|
$vbi->backlog (10); |
41 |
|
|
%fea = (); |
42 |
|
|
scan_vbi (50); |
43 |
|
|
$vbi->backlog (0); |
44 |
|
|
if ($tuner->signal > 30000) { |
45 |
|
|
my $cni = $VPS_CNI{$fea{CNI} & 0xfff}; |
46 |
|
|
my $ni = $VT_NI{$fea{NI}}; |
47 |
|
|
my $name; |
48 |
|
|
if (defined $ni) { |
49 |
|
|
$name = "$ni->[0] ($ni->[1])"; |
50 |
|
|
} elsif (defined $cni) { |
51 |
|
|
$name = $cni; |
52 |
|
|
} elsif ($fea{NAME}) { |
53 |
|
|
$name = $fea{NAME}; |
54 |
|
|
} elsif (length $fea{VT} > 1) { |
55 |
|
|
$name = $fea{VT}; |
56 |
|
|
} else { |
57 |
|
|
$name = "channel $chan"; |
58 |
|
|
} |
59 |
|
|
$name =~ s/\s*"\s*/ /g; |
60 |
|
|
$name =~ s/\s*\(.*?\)\s*/ /g; |
61 |
|
|
$name =~ s/^\s+//; |
62 |
|
|
$name =~ s/\s+$//; |
63 |
|
|
print " $name"; |
64 |
|
|
print " ["; |
65 |
|
|
while(my($k,$v)=each %fea) { |
66 |
|
|
print " $k","[$v]"; |
67 |
|
|
} |
68 |
|
|
print " ]"; |
69 |
|
|
my $c = { name => $name, channel => $chan, capture => 'on' }; |
70 |
|
|
if (1||$verbose) { |
71 |
|
|
$c->{features} = join(":", %fea); |
72 |
|
|
} |
73 |
|
|
my $key = find_key ($name); |
74 |
|
|
$c->{key} = $key if $key; |
75 |
|
|
push @channels, $c; |
76 |
|
|
} else { |
77 |
|
|
print " no signal"; |
78 |
|
|
} |
79 |
|
|
print "\n"; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
$rc->channels(@channels); |
83 |
|
|
$rc->save("xawtvrc"); |
84 |
|
|
|
85 |
|
|
print "\nnew xawtvrc saved as ./xawtvrc\n"; |
86 |
|
|
|
87 |
|
|
sub scan_vbi { |
88 |
|
|
my $frames = shift; |
89 |
|
|
|
90 |
|
|
my($name_,$name,$name2); |
91 |
|
|
|
92 |
|
|
while ($frames) { |
93 |
|
|
my $vbi_alloc; |
94 |
|
|
$tuner->get; return if $tuner->signal < 30000; |
95 |
|
|
$frames--; |
96 |
|
|
|
97 |
|
|
return if (defined $VT_NI{$fea{NI}} || defined $VPS_CNI{$fea{CNI}}) && !$verbose; |
98 |
|
|
|
99 |
|
|
for (decode_field $vbi->field, VBI_VT|VBI_VPS|VBI_OTHER|VBI_EMPTY) { |
100 |
|
|
if ($_->[0] == VBI_VPS) { |
101 |
|
|
$fea{CNI}=$_->[3]; |
102 |
|
|
if (ord($_->[1]) > 127 or length $name_ >= 12) { |
103 |
|
|
if ($name eq $name_) { |
104 |
|
|
$fea{NAME}=$name; |
105 |
|
|
} |
106 |
|
|
$name = $name_; |
107 |
|
|
} |
108 |
|
|
$name_ .= $_->[1] & "\x7f"; |
109 |
|
|
$fea{VPS}=sprintf "%04x", $_->[3]; |
110 |
|
|
$vbi_alloc .= "V"; |
111 |
|
|
} elsif ($_->[0] == VBI_VT) { |
112 |
|
|
if ($_->[2] == 0) { |
113 |
|
|
if ($_->[4] == 0x1df) { |
114 |
|
|
$fea{EPG}=""; |
115 |
|
|
} else { |
116 |
|
|
$fea{VT}=vt_2_name($_->[3]); |
117 |
|
|
} |
118 |
|
|
} elsif ($_->[2] == 30) { |
119 |
|
|
if (($_->[3]>>1) == 0) { |
120 |
|
|
$fea{NI} = $_->[6]; |
121 |
|
|
$fea{'NI30/1'}=sprintf "%04x", $_->[6]; |
122 |
|
|
} elsif (($_->[3]>>1) == 8) { |
123 |
|
|
$fea{PDC}=""; |
124 |
|
|
} else { |
125 |
|
|
$fea{"30"}="$_->[3]"; |
126 |
|
|
} |
127 |
|
|
} elsif ($_->[2] == 31) { |
128 |
|
|
if ($_->[4] == 0x500) { |
129 |
|
|
$fea{"$_->[1]/IC"}=""; |
130 |
|
|
} else { |
131 |
|
|
$fea{sprintf "$_->[1]/31[%x]",$_->[4]}++; |
132 |
|
|
} |
133 |
|
|
} |
134 |
|
|
$vt++; |
135 |
|
|
$vbi_alloc .= "T"; |
136 |
|
|
} elsif ($_->[0] == VBI_OTHER) { |
137 |
|
|
$vbi_alloc .= $_->[1] == 1 ? "c" : "O"; |
138 |
|
|
} elsif ($_->[0] == VBI_EMPTY) { |
139 |
|
|
$vbi_alloc .= "."; |
140 |
|
|
} else { |
141 |
|
|
$others++; |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
$fea{ALLOC}=$vbi_alloc; |
145 |
|
|
select undef,undef,undef,0.1 unless $vbi->queued; |
146 |
|
|
} |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
# try to guess sender name from videotext |
150 |
|
|
sub vt_2_name { |
151 |
|
|
local $_ = substr (shift, 8, 20) & ("\x7f") x 20; |
152 |
|
|
s/^\d+//; |
153 |
|
|
s/^[\x00-\x1f ]+//; |
154 |
|
|
s/\s*[\x00-\x1f].*//; |
155 |
|
|
s/\W?text.*//i; |
156 |
|
|
$_; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
sub find_key { |
160 |
|
|
local $_ = shift; |
161 |
|
|
return '.' if /3sat/; |
162 |
|
|
return '1' if /ARD/; |
163 |
|
|
return '2' if /ZDF/; |
164 |
|
|
return '3' if /SW 3/; |
165 |
|
|
return '7' if /PRO 7/; |
166 |
|
|
return 'r' if /RTL Plus/; |
167 |
|
|
return 't' if /RTL 2/; |
168 |
|
|
return 'i' if /VIVA 2/; |
169 |
|
|
return 'v' if /VIVA/; |
170 |
|
|
return 'm' if /MTV/; |
171 |
|
|
return 's' if /SAT 1/; |
172 |
|
|
return 'k' if /Kabel 1/; |
173 |
|
|
return 'e' if /EuroNews/; |
174 |
|
|
return 'a' if /Arte/; |
175 |
|
|
return 'x' if /VOX/; |
176 |
|
|
(); |
177 |
|
|
} |