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
#!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'; }
Quote%C3%9Cberraschungsei+R%C3%B6ntgen
"\x{009c}" does not map to cp850 at C:\perl.pl line 41.
Ã\x{009c}berraschungsei+Röntgen
Überraschungsei Röntgen
Quote%C3%9Cberraschungsei+R%C3%B6ntgen
"\x{009c}" does not map to cp850 at YoutubeDownload.pm line ...
Ç\x{009c}berraschungsei+RÇôntgen
sberraschungsei R"ntgen