#!perl use warnings; use strict; use 5.10.0; use open qw(:utf8); binmode STDOUT, ':encoding(cp850)'; use File::Spec::Functions qw(catdir tmpdir); use Encode qw(decode_utf8); use URI; use URI::Escape qw(uri_unescape); use WWW::YouTube::Download; use LWP::UserAgent::Cached; my $video_id = 'W9cUVCY3mSo'; my $lwp_cache_dir = catdir tmpdir, 'lwp-cache'; mkdir $lwp_cache_dir or die $! if ! -d $lwp_cache_dir; my %ua_opt = ( show_progress => 1, cache_dir => $lwp_cache_dir, nocache_if => sub { my $response = shift; return 1 if $response->code != 200; }, ); my $client = WWW::YouTube::Download->new(); $client->ua( LWP::UserAgent::Cached->new( %ua_opt ) ); my $info_url = URI->new( 'http://www.youtube.com/get_video_info' ); $info_url->query_form( 'video_id' => $video_id ); my $res = $client->ua->get( $info_url->as_string ); die "$res->status_line: $info_url" if ! $res->is_success; my %hash; for my $item ( split /&/, $res->decoded_content ) { my ( $key, $value ) = split /=/, $item; say( $value ) if $key eq 'title'; say( uri_unescape( $value ) ) if $key eq 'title'; if ( defined $value && $key =~ /^(?:title|keywords|reason|status)\z/ ) { $hash{$key} = decode_utf8( uri_unescape( $value ) ); $hash{$key} =~ s/\+/ /g; } say( $hash{$key} ) if $key eq 'title'; }