http://www.perlmonks.org?node_id=1008244


in reply to Re^2: explore a complexe hash structure return by Webservices::GData::YouTube
in thread explore a complexe hash structure return by Webservices::GData::YouTube

So you're using http://search.cpan.org/perldoc/WebService::GData::YouTube#search_video which returns a WebService::GData::YouTube::Feed::Video which says in SYNOPSIS to use
foreach my $video (@$videos) { say $video->video_id; say $video->title; say $video->content; say $video->view_count; say $video->favorite_count; say $video->duration; }
You're after thumbnails and there is a http://search.cpan.org/perldoc/WebService::GData::YouTube::Feed::Video#thumbnails

A grep thumbnails returns

lib/WebService/GData/YouTube/Doc/GeneralOverview.pod 254: my $thumbs =$video->thumbnails; lib/WebService/GData/YouTube/Feed/Video.pm 158:sub thumbnails { 633:=head3 thumbnails t/56-WebService-GData-YouTube-Feed-Video-instance.t 91:ok( @{ $entry->thumbnails } == 5, 'number of thumbnails is right.' +); 93:ok($entry->thumbnails->[0]->url eq 'http://i.ytimg.com/vi/qWAY3YvHq +LE/default.jpg','thumbnail is properly set.');

So thumbnails returns a list, and there is an example of usage in WebService::GData::YouTube::Doc::GeneralOverview , a sub display_video which contains

my $thumbs =$video->thumbnails; foreach my $thumb (@$thumbs) { say $thumb->url; say $thumb->time; say $thumb->width; say $thumb->height; }

So there you go

#!/usr/bin/perl -- use strict; use warnings; use feature qw/ say /; use Carp::Always; use WebService::GData::YouTube; use WebService::GData::Error; ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" Main( @ARGV ); exit( 0 ); sub Main { my $query = shift or die qq{\nUsage: $0 "Robert Palmer"\n\n}; my $yt = WebService::GData::YouTube->new(); $yt->query()->q( $query )->limit( 10, 2 ); $yt->query()->maxresults( 20 ); my $videos = $yt->search_video(); display_videos( $videos ); } sub display_videos { my $videos = shift; foreach my $video ( @$videos ) { display_video( $video, 'justthumbs' ); } } sub display_video { my $video = shift; my $justthumbs = shift; say 'Video Id:', $video->video_id; say 'Title:', $video->title; if( not $justthumbs ) { say 'Description:', $video->description; say 'Updated:', $video->updated; say 'Published:', $video->published; say 'Uploaded:', $video->uploaded; say 'Favorite Count:', $video->favorite_count; say 'View Count:', $video->view_count; say 'Duration:', $video->duration; say 'Keywords:', $video->keywords; say 'Author Name:', $video->author->[0]->name; say 'Author Uri:', $video->author->[0]->uri; say 'Geo Location:', $video->location; say 'Denied Countries:', $video->denied_countries; say 'Media Player URL:', $video->media_player; say 'Is Private:', $video->is_private; #content say $video->content->type( 'flash' )->[0] ->url; #retrieve the flash application url say $video->content->format( 1 )->[0]->url; #3gpp rtsp #loop over it: my $contents = $video->content; foreach my $content ( @$contents ) { say $content->url; say $content->type; say $content->duration; say $content->format; } say $video->rating->num_dislikes; say $video->rating->num_likes; } ## end if( not $justthumbs ) my $thumbs = $video->thumbnails; foreach my $thumb ( @$thumbs ) { for my $att( qw/ url time width height /){ my $val = $thumb->$att; $val = '' if not defined $val; say "$att: $val"; } #~ say $thumb->url; #~ say $thumb->time; #~ say $thumb->width; #~ say $thumb->height; } } ## end sub display_video