line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: TvDotNu.pm,v 1.2 2004/03/31 20:28:08 claes Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package WWW::Search::Tv::Sweden::TvDotNu; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
25082
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
24
|
|
7
|
1
|
|
|
1
|
|
16
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
35
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
4635
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
95084
|
|
|
1
|
|
|
|
|
42
|
|
10
|
1
|
|
|
1
|
|
11
|
use HTTP::Request; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
27
|
|
11
|
1
|
|
|
1
|
|
3653
|
use HTML::Parser; |
|
1
|
|
|
|
|
28552
|
|
|
1
|
|
|
|
|
61
|
|
12
|
1
|
|
|
1
|
|
879
|
use WWW::Search::Tv::Sweden::TvDotNu::DB; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
33
|
|
13
|
1
|
|
|
1
|
|
686
|
use WWW::Search::Tv::Sweden::TvDotNu::Entry; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1145
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
require Exporter; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
20
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
21
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# This allows declaration use WWW::Search::Tv::Sweden::TvDotNu ':all'; |
24
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
25
|
|
|
|
|
|
|
# will save memory. |
26
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
) ] ); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our @EXPORT = qw( |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Always use this user agent |
39
|
|
|
|
|
|
|
my $UserAgent = LWP::UserAgent->new(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Month names |
42
|
|
|
|
|
|
|
my @Months = qw(jan feb mar apr may jun jul aug sep oct nov dec); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Preloaded methods go here. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
1
|
|
|
1
|
1
|
16
|
my ($class, %args) = @_; |
48
|
1
|
|
33
|
|
|
9
|
$class = ref($class) || $class; |
49
|
1
|
|
|
|
|
8
|
bless { |
50
|
|
|
|
|
|
|
cache => 1, |
51
|
|
|
|
|
|
|
%args |
52
|
|
|
|
|
|
|
}, $class; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub get_today { |
56
|
1
|
|
|
1
|
1
|
5
|
my ($self) = @_; |
57
|
1
|
|
|
|
|
6
|
return $self->get("http://www.tv.nu"); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub get_tomorrow { |
61
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
62
|
0
|
|
|
|
|
0
|
my ($day, $mon) = (localtime(time))[3,4]; |
63
|
0
|
|
|
|
|
0
|
my $url = "http://show.tv.nu/" . $Months[$mon] . "/" . ($day + 1) . "/"; |
64
|
0
|
|
|
|
|
0
|
return $self->get($url); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub get_full_entry { |
68
|
0
|
|
|
0
|
1
|
0
|
my ($self, $entry) = @_; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
0
|
my $request = HTTP::Request->new(GET => $entry->url); |
71
|
0
|
|
|
|
|
0
|
my $response = $UserAgent->request($request); |
72
|
|
|
|
|
|
|
|
73
|
0
|
0
|
|
|
|
0
|
if($response->is_success) { |
74
|
0
|
|
|
|
|
0
|
$self->_parse_entry($response->content(), $entry); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get { |
79
|
1
|
|
|
1
|
0
|
2
|
my ($self, $url) = @_; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
11
|
my $request = HTTP::Request->new(GET => $url); |
82
|
1
|
|
|
|
|
11917
|
my $response = $UserAgent->request($request); |
83
|
|
|
|
|
|
|
|
84
|
1
|
50
|
|
|
|
402588
|
if($response->is_success) { |
85
|
1
|
|
|
|
|
29
|
return $self->_parse_toc($response->content()); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _parse_toc { |
90
|
1
|
|
|
1
|
|
925
|
my ($self, $content) = @_; |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
18
|
my $db = WWW::Search::Tv::Sweden::TvDotNu::DB->new(); |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
5
|
my $start_h = $self->_toc_start_h($db); |
95
|
1
|
|
|
|
|
6
|
my $end_h = $self->_toc_end_h($db); |
96
|
1
|
|
|
|
|
5
|
my $text_h = $self->_toc_text_h($db); |
97
|
|
|
|
|
|
|
|
98
|
1
|
|
|
|
|
17
|
my $toc_parser = HTML::Parser->new(api_version => 3, |
99
|
|
|
|
|
|
|
start_h => [$start_h, "tagname, attr"], |
100
|
|
|
|
|
|
|
text_h => [$text_h, "dtext"], |
101
|
|
|
|
|
|
|
end_h => [$end_h, "tagname"], |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
103
|
$toc_parser->parse($content); |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
194
|
return $db; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub _parse_entry { |
110
|
0
|
|
|
0
|
|
0
|
my ($self, $content, $entry) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
my $start_h = $entry->_entry_start_h(); |
113
|
0
|
|
|
|
|
0
|
my $end_h = $entry->_entry_end_h(); |
114
|
0
|
|
|
|
|
0
|
my $text_h = $entry->_entry_text_h(); |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
my $entry_parser = HTML::Parser->new(api_version => 3, |
117
|
|
|
|
|
|
|
start_h => [$start_h, "tagname, attr"], |
118
|
|
|
|
|
|
|
text_h => [$text_h, "dtext"], |
119
|
|
|
|
|
|
|
end_h => [$end_h, "tagname"], |
120
|
|
|
|
|
|
|
); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
0
|
$entry_parser->unbroken_text(1); |
123
|
0
|
|
|
|
|
0
|
$entry_parser->parse($content); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _toc_start_h { |
127
|
1
|
|
|
1
|
|
4
|
my ($self, $db) = @_; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
return sub { |
130
|
3411
|
|
|
3411
|
|
4619
|
my ($tagname, $attr) = @_; |
131
|
|
|
|
|
|
|
|
132
|
3411
|
100
|
|
|
|
19347
|
if($tagname eq 'a') { |
133
|
1044
|
50
|
66
|
|
|
29256
|
if(exists $attr->{href} && $attr->{href} =~ /^javascript:p(.*)$/) { |
134
|
0
|
|
|
|
|
0
|
my ($url, $channel, |
135
|
|
|
|
|
|
|
$start_hour, $start_min, |
136
|
|
|
|
|
|
|
$end_hour, $end_min) = $1 =~ m{ |
137
|
|
|
|
|
|
|
^\(\' |
138
|
|
|
|
|
|
|
(.*)\/ |
139
|
|
|
|
|
|
|
(.*)\/ |
140
|
|
|
|
|
|
|
(\d\d)(\d\d)-(\d\d)(\d\d) |
141
|
|
|
|
|
|
|
\.html\'}x; |
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
0
|
|
|
0
|
next unless($url && $channel && "$start_hour$start_min" && "$end_hour$end_min"); |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
144
|
0
|
|
|
|
|
0
|
$url = join("", $url, "/", $channel, "/", $start_hour, $start_min, "-", $end_hour, $end_min, ".html"); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
0
|
my $entry = WWW::Search::Tv::Sweden::TvDotNu::Entry->new(url => $url, |
147
|
|
|
|
|
|
|
channel => $channel, |
148
|
|
|
|
|
|
|
start_time => [ |
149
|
|
|
|
|
|
|
$start_hour + 0, |
150
|
|
|
|
|
|
|
$start_min + 0 |
151
|
|
|
|
|
|
|
], |
152
|
|
|
|
|
|
|
end_time => [ |
153
|
|
|
|
|
|
|
$end_hour + 0, |
154
|
|
|
|
|
|
|
$end_min + 0 |
155
|
|
|
|
|
|
|
], |
156
|
|
|
|
|
|
|
title => "", |
157
|
|
|
|
|
|
|
); |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
0
|
$db->add($entry); |
160
|
0
|
|
|
|
|
0
|
$self->{open_a} = 1; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
1
|
|
|
|
|
12
|
}; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _toc_text_h { |
167
|
1
|
|
|
1
|
|
3
|
my ($self, $db) = @_; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
return sub { |
170
|
3568
|
|
|
3568
|
|
5308
|
my ($text) = @_; |
171
|
|
|
|
|
|
|
|
172
|
3568
|
50
|
|
|
|
22201
|
if($self->{open_a}) { |
173
|
0
|
|
|
|
|
0
|
$db->last->title($text); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
1
|
|
|
|
|
5
|
} |
177
|
|
|
|
|
|
|
sub _toc_end_h { |
178
|
1
|
|
|
1
|
|
3
|
my ($self) = @_; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
return sub { |
181
|
2603
|
|
|
2603
|
|
3564
|
my ($tagname) = @_; |
182
|
2603
|
100
|
|
|
|
9932
|
if($tagname eq 'a') { |
183
|
1044
|
|
|
|
|
3634
|
$self->{open_a} = 0; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
1
|
|
|
|
|
7
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |
191
|
|
|
|
|
|
|
__END__ |