-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrns
106 lines (85 loc) · 2.46 KB
/
rns
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/perl -w
use Switch;
use LWP::UserAgent;
my $my_serial = "RTV4080K1AA5000149";
my $my_zipcode = "97206";
my $my_country = "US";
my $my_headend = "OR36575";
my $rns_base = "http://rns.replaytv.net/cgi-bin/2.0";
sub url_login {
my ($action, @args) = @_;
my ($attempts, $total);
switch ($action) {
case "nightly" { $attempts = shift @args || 1;
$total = shift @args || 1;
return "login.pl?action=$action&attempts=$attempts&total=$total";
}
else { die "Invalid or unsupported login action" }
}
}
sub url_getmrauth {
my ($serial) = shift @_ || $my_serial;
# If-None-Match: "1-1"
return "getmrauth.pl?serial=$serial";
}
sub url_getzipcode2 {
my ($zipcode) = shift @_ || $my_zipcode;
my ($country) = shift @_ || $my_country;
return "getzipcode2.pl?zipcode=$zipcode&country=$country";
}
sub url_getheadend {
my ($headend) = shift @_ || $my_headend;
my ($country) = shift @_ || $my_country;
return "getheadend.pl?headend=$headend&country=$country";
}
sub url_getcg2 {
my $date = shift @_ || die "getcg2 needs a date";
my $tmsid = shift @_ || die "getcg2 needs at least one channel";
my $timestamp = shift @_ || "0";
my $url = "getcg2.pl?A${date}C${tmsid}Z$timestamp";
while (defined($tmsid = shift @_)) {
$timestamp = shift @_;
if (defined($timestamp)) {
$timestamp =~ s/^\+/P/;
$timestamp =~ s/^\-/M/;
if ($timestamp !~ m/^[MPZ]/) {
$timestamp = "Z$timestamp";
}
}
else {
$timestamp = "P0";
}
$url .= "_$tmsid$timestamp";
}
return $url;
}
sub main {
my ($command, @args) = @_;
my ($ua, $req, $res);
my %commands = (
login => \&url_login,
getmrauth => \&url_getmrauth,
getzipcode2 => \&url_getzipcode2,
getheadend => \&url_getheadend,
getcg2 => \&url_getcg2,
);
if (!defined($commands{$command})) {
print STDERR "Usage: \n";
foreach (sort keys %commands) {
print "\t$_\n";
}
exit -1;
}
$url = $commands{$command}->(@args);
$req = new HTTP::Request GET => "$rns_base/$url";
$req->authorization_basic("RNSBasic", "A7x*8-Qt");
$ua = new LWP::UserAgent;
$res = $ua->request($req);
if ($res->is_success) {
print $res->content;
} else {
die "Failed, sorry";
}
# wget --server-response --http-user="RNSBasic" --http-passwd="A7x*8-Qt" 'http://rns.replaytv.net/cgi-bin/2.0/getsw.pl?version=520410600&serial=RTV4080K1AA5000149'
}
main(@ARGV);