line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Folder.pm 57 2007-01-12 19:26:09Z boumenot $ |
2
|
|
|
|
|
|
|
# Author: Christopher Boumenot |
3
|
|
|
|
|
|
|
###################################################################### |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# Copyright 2006-2007 by Christopher Boumenot. This program is free |
6
|
|
|
|
|
|
|
# software; you can redistribute it and/or modify it under the same |
7
|
|
|
|
|
|
|
# terms as Perl itself. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
###################################################################### |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Net::TiVo::Folder; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
2603
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
14
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
2066
|
use Text::Wrap; |
|
1
|
|
|
|
|
3875
|
|
|
1
|
|
|
|
|
62
|
|
17
|
1
|
|
|
1
|
|
1664
|
use Log::Log4perl qw(:easy get_logger); |
|
1
|
|
|
|
|
65521
|
|
|
1
|
|
|
|
|
9
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Should be read as a poor man's XPath |
20
|
|
|
|
|
|
|
our %DEFAULT_ATTRIBUTES_XPATH = ( |
21
|
|
|
|
|
|
|
content_type => [qw(Details ContentType)], |
22
|
|
|
|
|
|
|
format => [qw(Details SourceFormat)], |
23
|
|
|
|
|
|
|
change_date => [qw(Details LastChangeDate)], |
24
|
|
|
|
|
|
|
name => [qw(Details Title)], |
25
|
|
|
|
|
|
|
total_items => [qw(Details TotalItems)], |
26
|
|
|
|
|
|
|
# Is this the same thing as total_items()? |
27
|
|
|
|
|
|
|
item_count => [qw(ItemCount)], |
28
|
|
|
|
|
|
|
# What value is this? |
29
|
|
|
|
|
|
|
item_start => [qw(ItemStart)], |
30
|
|
|
|
|
|
|
global_sort => [qw(GlobalSort)], |
31
|
|
|
|
|
|
|
sort_order => [qw(SortOrder)], |
32
|
|
|
|
|
|
|
# Due to the way folders are created it is difficult |
33
|
|
|
|
|
|
|
# to get the url of the folder. I could add it easily |
34
|
|
|
|
|
|
|
# enough, but it would be a hack, and I'm not sure |
35
|
|
|
|
|
|
|
# that you really need the url of the folder. I need |
36
|
|
|
|
|
|
|
# to fix the code. |
37
|
|
|
|
|
|
|
#url |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
__PACKAGE__->make_accessor($_) for keys %DEFAULT_ATTRIBUTES_XPATH; |
41
|
|
|
|
|
|
|
__PACKAGE__->make_accessor($_) for qw(size); |
42
|
|
|
|
|
|
|
__PACKAGE__->make_array_accessor($_) for qw(shows); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
0
|
0
|
sub TIVO_MIME_TYPES { qw(video/x-tivo-mpeg video/x-tivo-raw-pes video/x-tivo-raw-tts) } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new { |
47
|
0
|
|
|
0
|
0
|
0
|
my ($class, %options) = @_; |
48
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
0
|
unless ($options{xmlref}) { |
50
|
0
|
|
|
|
|
0
|
die __PACKAGE__ . ": Mandatory param xmlref missing\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
0
|
my $self = { |
54
|
|
|
|
|
|
|
%options, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
bless $self, $class; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
for my $attr (keys %DEFAULT_ATTRIBUTES_XPATH) { |
60
|
0
|
|
|
|
|
0
|
my $value = __PACKAGE__->walk_hash_ref($options{xmlref}, $DEFAULT_ATTRIBUTES_XPATH{$attr}); |
61
|
0
|
|
|
|
|
0
|
$self->$attr($value); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
$self->change_date(hex($self->change_date())); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# DEBUG(sub { Data::Dumper::Dumper($options{xmlref}) }); |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
0
|
my ($size, @shows); |
69
|
0
|
|
|
|
|
0
|
for my $show (@{$options{xmlref}->{Item}}) { |
|
0
|
|
|
|
|
0
|
|
70
|
0
|
0
|
|
|
|
0
|
if (grep {$show->{Links}->{Content}->{ContentType} eq $_} TIVO_MIME_TYPES) { |
|
0
|
|
|
|
|
0
|
|
71
|
0
|
|
|
|
|
0
|
push @shows, Net::TiVo::Show->new(xmlref => $show); |
72
|
0
|
|
|
|
|
0
|
INFO("added the show " . $shows[-1]->name()); |
73
|
0
|
|
|
|
|
0
|
$size += $shows[-1]->size(); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
$self->size($size); |
78
|
0
|
|
|
|
|
0
|
$self->shows(\@shows); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _commify { |
84
|
0
|
|
|
0
|
|
0
|
my ($self, $num) = @_; |
85
|
0
|
|
|
|
|
0
|
$num = reverse $num; |
86
|
0
|
|
|
|
|
0
|
$num =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g; |
87
|
0
|
|
|
|
|
0
|
$num = reverse $num; |
88
|
0
|
|
|
|
|
0
|
return $num; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub as_string { |
92
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
$Text::Wrap::columns = 72; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
my @a; |
97
|
0
|
|
|
|
|
0
|
push @a, $self->name(); |
98
|
0
|
0
|
|
|
|
0
|
push @a, sprintf("%d %s", $self->total_items(), (($self->total_items() > 1) ? "episodes" : "episode")); |
99
|
0
|
|
|
|
|
0
|
push @a, sprintf("%s bytes", $self->_commify($self->size())); |
100
|
0
|
|
|
|
|
0
|
my $s = wrap("", " ", join(", ", @a)); |
101
|
0
|
|
|
|
|
0
|
return $s; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# cmb - taken from the excellent Net::Amazon! |
105
|
|
|
|
|
|
|
sub make_accessor { |
106
|
27
|
|
|
27
|
0
|
45
|
my($package, $name) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
1
|
|
1732
|
no strict qw(refs); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
165
|
|
109
|
|
|
|
|
|
|
|
110
|
27
|
|
|
|
|
83
|
my $code = <
|
111
|
|
|
|
|
|
|
*{"$package\\::$name"} = sub { |
112
|
|
|
|
|
|
|
my(\$self, \$value) = \@_; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if(defined \$value) { |
115
|
|
|
|
|
|
|
\$self->{$name} = \$value; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
if(exists \$self->{$name}) { |
118
|
|
|
|
|
|
|
return (\$self->{$name}); |
119
|
|
|
|
|
|
|
} else { |
120
|
|
|
|
|
|
|
return ""; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
EOT |
124
|
27
|
50
|
|
|
|
30
|
if(! defined *{"$package\::$name"}) { |
|
27
|
|
|
|
|
159
|
|
125
|
27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
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# cmb - taken from the excellent Net::Amazon! |
130
|
|
|
|
|
|
|
sub make_array_accessor { |
131
|
1
|
|
|
1
|
0
|
3
|
my($package, $name) = @_; |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
1
|
|
7
|
no strict qw(refs); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
264
|
|
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
6
|
my $code = <
|
136
|
|
|
|
|
|
|
*{"$package\\::$name"} = sub { |
137
|
|
|
|
|
|
|
my(\$self, \$nameref) = \@_; |
138
|
|
|
|
|
|
|
if(defined \$nameref) { |
139
|
|
|
|
|
|
|
if(ref \$nameref eq "ARRAY") { |
140
|
|
|
|
|
|
|
\$self->{$name} = \$nameref; |
141
|
|
|
|
|
|
|
} else { |
142
|
|
|
|
|
|
|
\$self->{$name} = [\$nameref]; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
# Return a list |
146
|
|
|
|
|
|
|
if(exists \$self->{$name} and |
147
|
|
|
|
|
|
|
ref \$self->{$name} eq "ARRAY") { |
148
|
|
|
|
|
|
|
return \@{\$self->{$name}}; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
return undef; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
EOT |
154
|
|
|
|
|
|
|
|
155
|
1
|
50
|
|
|
|
2
|
if(! defined *{"$package\::$name"}) { |
|
1
|
|
|
|
|
8
|
|
156
|
1
|
50
|
0
|
0
|
|
171
|
eval $code or die "$@"; |
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub walk_hash_ref { |
161
|
0
|
|
|
0
|
0
|
|
my ($package, $href, $aref) = @_; |
162
|
|
|
|
|
|
|
|
163
|
0
|
0
|
|
|
|
|
return $href if scalar(@$aref) == 0; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
my @a; |
166
|
0
|
|
|
|
|
|
push @a, $_ for @$aref; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my $tail = pop @a; |
169
|
0
|
|
|
|
|
|
my $ref = $href; |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
for my $part (@a) { |
172
|
0
|
|
|
|
|
|
$ref = $ref->{$part}; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
return $ref->{$tail}; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
__END__ |