blib/lib/WWW/YouTube/Info.pm

filter: Statementstmt 86.1% 31 / 36 Branchbran 50.0% 1 / 2 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 50.0% 1 / 2 totaltotal 79.2% 42 / 53 SCAR 14.2
CC
4
Cov
80%
get_info
4.5
new
2.1
BEGIN
1.0
CRAP 4.1
↑ Summary
1 package WWW::YouTube::Info;
2  
3 4 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 require Exporter;
8  
9 4 our @ISA = qw(
10 Exporter
11 );
12  
13 4 our @EXPORT = qw(
14 );
15  
16 4 our $VERSION = '0.05';
17  
18 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 =head1 NAME
23  
24 WWW::YouTube::Info - gain info on YouTube video by VIDEO_ID
25  
26 =head1 SYNOPSIS
27  
28 =head2 Perhaps a little code snippet?
29  
30 #!/usr/bin/perl
31
32 use strict;
33 use warnings;
34
35 use WWW::YouTube::Info;
36
37 # id taken from YouTube video URL
38 my $id = 'foobar';
39
40 my $yt = WWW::YouTube::Info->new($id);
41
42 my $info = $yt->get_info();
43
44 # hash reference holds values gained via http://youtube.com/get_video_info?video_id=foobar
45 # $info->{title} # e.g.: Foo+bar+-+%27Foobar%27
46 # $info->{author} # e.g.: foobar
47 # $info->{keywords} # e.g.: Foo%2Cbar%2CFoobar
48 # $info->{length_seconds} # e.g.: 60
49 # $info->{fmt_map} # e.g.: 22%2F1280x720%2F9%2F0%2F115%2C35%2F854x480%2F9%2F0%2F115%2C34%2F640x360%2F9%2 ..
50 # $info->{fmt_url_map} # e.g.: 22%7Chttp%3A%2F%2Fv14.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D131.0.0.0 ..
51 # $info->{fmt_stream_map} # e.g.: 22%7Chttp%3A%2F%2Fv14.lscache1.c.youtube.com%2Fvideoplayback%3Fip%3D131.0.0.0 ..
52 # ..
53
54 # Remark:
55 # You might want to check $info->{status} before further workout,
56 # as some videos have copyright issues indicated, for instance, by
57 # $info->{status} ne 'ok'.
58  
59 =head1 DESCRIPTION
60  
61 I guess its pretty much self-explanatory ..
62  
63 =head1 METHODS
64  
65 =cut
66  
67 sub new {
68 2 ▶ my ($class, $id) = @_;
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
69  
70 2 my $self = {};
71 2 ▶ $self->{_id} = $id || croak "no VIDEO_ID given!";
Condition33%1/3
$id || croak('no VIDEO_ID given!')
l!l&&r!l&&!r
200
MC/DC0%0/2
$id || croak('no VIDEO_ID given!')
$id croak('no VIDEO_ID given!')
Truth table33%1/3
A || B
A= $idB= croak('no VIDEO_ID given!')
ABresult
1X1
011
000
72 2 bless($self, $class);
73  
74 2 return $self;
75 }
76  
77 =head2 get_info
78  
79 See synopsis for how/what/why. You might also want to use L<Data::Dumper> ..
80 Croaks if C<LWP::Simple::get> fails.
81  
82 =cut
83  
84 sub get_info {
85 1 ▶ my ($self) = @_;
Subroutine get_info: called CC=3 SCAR=15.0
Pod documented
86  
87 1 my $id = $self->{_id};
88  
89 1 my $info_url = "http://youtube.com/get_video_info?video_id=$id";
90  
91 1 ▶ my $video_info = get($info_url)
Branch: 1 branch
BranchTrueFalseTotal
my $video_info = &get($info_url) or croak("no get at $info_url - $!") 1 0 1
92 or croak "no get at $info_url - $!";
93  
94 0 my @info = split /&/, $video_info;
95  
96 0 for ( @info ) {
97 0 my ($key, $value) = split /=/;
98 0 $self->{info}->{$key} = $value;
99 }
100  
101 0 return $self->{info};
102 }
103  
104 4 1;
105  
106 __END__
↑ Summary