This file is indexed.

/usr/share/perl5/WebService/YouTube/Util.pm is in libwebservice-youtube-perl 1.0.3-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#
# $Id: Util.pm 11 2007-04-09 04:34:01Z hironori.yoshida $
#
package WebService::YouTube::Util;
use strict;
use warnings;
use version; our $VERSION = qv('1.0.3');

use Carp;
use LWP::UserAgent;
use URI::Escape qw(uri_escape uri_escape_utf8);
use Encode ();

sub rss_uri {
    my ( $class, $type, $arg ) = @_;

    if ( $type ne 'global' && $type ne 'tag' && $type ne 'user' ) {
        croak "type of $type is not supported";
    }

    if ( Encode::is_utf8($arg) ) {
        $arg = uri_escape_utf8($arg);
    }
    else {
        $arg = uri_escape($arg);
    }

    if ( $type eq 'user' ) {
        $arg = lc $arg . '/videos';
    }
    return "http://www.youtube.com/rss/$type/$arg.rss";
}

sub rest_uri {
    my ( $class, $dev_id, $method, $fields ) = @_;

    my $query = q{};
    if ($fields) {
        foreach my $key ( keys %{$fields} ) {
            my $value = $fields->{$key};
            if ( Encode::is_utf8($value) ) {
                $value = uri_escape_utf8($value);
            }
            else {
                $value = uri_escape($value);
            }
            $query .= sprintf '&%s=%s', $key, $value;
        }
    }
    return
      "http://www.youtube.com/api2_rest?dev_id=$dev_id&method=$method$query";
}

sub get_video_uri {
    my ( $class, $video, $args ) = @_;

    if ( !$video ) {
        return;
    }

    $args->{ua} ||= LWP::UserAgent->new;

    my ( $video_id, $video_uri );
    if ( ref $video ) {
        $video_id  = $video->id;
        $video_uri = $video->url;
    }
    else {
        $video_id = $video;
    }
    $video_uri ||= "http://youtube.com/?v=$video_id";

    my $res = $args->{ua}->get($video_uri);
    if ( !$res->is_success ) {
        carp $res->status_line;
        return;
    }

    my $content = $res->content;
    if ( $content =~ m{"/player2\.swf\?([^"]+)",\s*"movie_player"}msx ) {
        return "http://youtube.com/get_video.php?$1";
    }
    if ( $content =~ m{\bt\b[^:]*:\s*(['"])(.+?)\1}msx ) {
        return "http://youtube.com/get_video.php?video_id=$video_id&t=$2";
    }
    if ( $content =~ m{class="errorBox"[^>]*>\s*([^<]+?)\s*<}msx ) {
        carp "$video_id: $1";
        return;
    }
    carp "$video_id: got a page but it is invalid page\n$content";
    return;
}

sub get_video {
    my ( $class, $video, $args ) = @_;

    if ( !$video ) {
        return;
    }

    $args->{ua} ||= LWP::UserAgent->new;

    my $video_uri = $class->get_video_uri( $video, $args );
    if ( !$video_uri ) {
        return;
    }
    my $res = $args->{ua}->get($video_uri);
    if ( !$res->is_success ) {
        carp $res->status_line;
        return;
    }
    return $res->content;
}

1;

__END__

=head1 NAME

WebService::YouTube::Util - Utility for WebService::YouTube

=head1 VERSION

This document describes WebService::YouTube::Util version 1.0.3

=head1 SYNOPSIS

    use WebService::YouTube::Util;
    
    # Get an URI of RSS
    my $uri = WebService::YouTube::Util->rss_uri( 'global', 'recently_added' );
    
    # Get an URI of REST API
    my $uri = WebService::YouTube::Util->rest_uri( $dev_id,
                                                   'youtube.videos.list_by_tag',
                                                   { tag => 'monkey' }
                                                 );
    
    # Get a downloadable URI
    my $uri = WebService::YouTube::Util->get_video_uri('rdwz7QiG0lk');
    
    # Get a video which type is .flv
    my $content = WebService::YouTube::Util->get_video('rdwz7QiG0lk');

=head1 DESCRIPTION

This is an utility for L<WebService::YouTube>.

=head1 SUBROUTINES/METHODS

=head2 rss_uri( $type, $arg )

Returns a URI of RSS.
$type should be 'global' or 'tag' or 'user'.
$arg is required when $type is 'tag' or 'user'.

=head2 rest_uri( $dev_id, $method, \%fields )

Returns a URI of REST API.
$dev_id is your developer ID of YouTube.
$method is a method name like a 'youtube.*.*'.
%fields can contain optional parameter.

=head2 get_video_uri( $video, \%args )

Returns a downloadable URI of $video.
$video should be a video ID or a L<WebService::YouTube::Video> object.
%args can contain some optional arguments.

=over

=item ua

L<LWP::UserAgent> object

=back

=head2 get_video( $video, \%args )

Returns a downloaded content of $video.
$video should be a video ID or a L<WebService::YouTube::Video> object.
%args can contain some optional arguments.

=over

=item ua

L<LWP::UserAgent> object

=back

=head1 DIAGNOSTICS

=over

=item type of ... is not supported

No such RSS. The type should be 'global' or 'tag' or 'user'.

=item got a page but it is invalid page

Maybe, YouTube is being maintained. :-)

=back

=head1 CONFIGURATION AND ENVIRONMENT

WebService::YouTube::Util requires no configuration files or environment variables.

=head1 DEPENDENCIES

L<WebService::YouTube>, L<LWP::UserAgent>, L<URI::Escape>

=head1 INCOMPATIBILITIES

None reported.

=head1 BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to
C<bug-webservice-youtube@rt.cpan.org>, or through the web interface at
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WebService-YouTube>.
I will be notified, and then you'll automatically be notified of progress on
your bug as I make changes.

=head1 AUTHOR

Hironori Yoshida <yoshida@cpan.org>

=head1 LICENSE AND COPYRIGHT

This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself. See L<perlartistic>.

=cut