Permalink
Browse files

Added support for the 'audio' format;

Improved the 'itag finder' system for a given resolution;
YoutubeViewer.pm accepts URLs which doesn't contain the signature (sig);
  • Loading branch information...
1 parent ebae448 commit 2c57ea013a8f9a1bd68e0fd71b56cf13038fdecb @trizen committed Nov 7, 2013
@@ -10,7 +10,7 @@ lib/WWW/YoutubeViewer/ParseXML.pm
lib/WWW/YoutubeViewer/RegularExpressions.pm
lib/WWW/YoutubeViewer/Utils.pm
Makefile.PL
-MANIFEST
+MANIFEST This list of files
META.json
META.yml
README
@@ -4,7 +4,7 @@
"Șuteu \"Trizen\" Daniel <trizenx@gmail.com>"
],
"dynamic_config" : 1,
- "generated_by" : "Module::Build version 0.4005, CPAN::Meta::Converter version 2.131560",
+ "generated_by" : "Module::Build version 0.4008, CPAN::Meta::Converter version 2.132830",
"license" : [
"perl_5"
],
@@ -7,7 +7,7 @@ build_requires:
configure_requires:
Module::Build: 0
dynamic_config: 1
-generated_by: 'Module::Build version 0.4005, CPAN::Meta::Converter version 2.131560'
+generated_by: 'Module::Build version 0.4008, CPAN::Meta::Converter version 2.132830'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
@@ -1,4 +1,4 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.4005
+# Note: this file was auto-generated by Module::Build::Compat version 0.4008
require 5.016;
use ExtUtils::MakeMaker;
WriteMakefile
@@ -18,7 +18,7 @@
#-------------------------------------------------------
# Appname: youtube-viewer
# Created on: 02 June 2010
-# Latest edit on: 06 September 2013
+# Latest edit on: 07 November 2013
# Websites: http://trizen.googlecode.com
# https://github.com/trizen/youtube-viewer
#-------------------------------------------------------
@@ -463,9 +463,9 @@ YouTube options:
--hd : search only for videos available in at least 720p
--page=i : get results starting with a specific page
--results=[1-50] : how many results to display per page
- -2 -3 -4 -7 -1 : resolutions: 240p, 360p, 480p, 720p or 1080p
- --resolution=RES : resolutions: original, 1080, 720, 480, 360, 340,
- 240, 180, 144
+ -2 -3 -4 -7 -1 : resolutions: 240p, 360p, 480p, 720p and 1080p
+ --resolution=RES : available resolutions: original, 1080p, 720p,
+ 480p, 360p, 240p, 180p, 144p, audio
-F --favorites:s : show the latest favorited videos *
-R --recommended : show the recommended videos for you *
-S --subscriptions:s : show the new subscription videos *
@@ -480,6 +480,7 @@ MPlayer options:
-f --fullscreen! : set the fullscreen mode for mplayer (-fs)
-n --novideo! : play the music only without a video in the foreground
-l --use-lc : use a lower cache for MPlayer (for slow connections)
+ --nocache : use no cache while streaming videos (for fast connections)
--cache=i : set the cache for MPlayer (set: $opt{cache})
--cache-min=i : set the cache-min for MPlayer (set: $opt{cache_min})
--lcache=i : set the lower-cache for MPlayer (set: $opt{lower_cache})
@@ -516,7 +517,7 @@ Other options:
--get-captions! : download the closed captions (with gcap)
--captions-dir=s : the directory where to download the .srt files
--gdata-url=s : print video results from a valid GData URL
- --get-term-width : adjust the text for your terminal width
+ --get-term-width! : adjust the text for your terminal width
--login : will prompt you for login
--logout : will delete the authentication key
--http_proxy=s : HTTP proxy to use, format 'http://domain.tld:port/'.
@@ -602,17 +603,7 @@ NOTE: Categories and region IDs are case sensitive!
example, but the mplayer arguments doesn't work for vlc.
The full command should be: $execname -mplayer=vlc -mplayer-arg=-q
-2. Available resolutions: original, 1080, 720, 480, 360, 340, 240, 180, 144
- 1080 = mp4
- 720 = mp4 (unless webm is prefered)
- 480 = flv (unless webm is prefered)
- 360 = flv (unless webm is prefered)
- 340 = mp4 (actually is 360p)
- 240 = flv
- 180 = 3gpp (mp4v, mp4a)
- 144 = 3gpp (mp4v, mp4a)
-
-3. lower_cache and lower_cache_min values are used when -l (--use-lower-cache)
+2. lower_cache and lower_cache_min values are used when -l (--use-lower-cache)
is specified as argument, or if the resolution of a video is lower than 720p.
** Arguments
@@ -1120,6 +1111,7 @@ sub parse_arguments {
# MPlayer
'mplayer=s' => \$opt{mplayer},
+ 'nocache!' => \$opt{nocache},
'cache=i' => \$opt{cache},
'cache-min|cache_min=i' => \$opt{cache_min},
'lcache|lower-cache|lower_cache=i' => \$opt{lower_cache},
@@ -1141,7 +1133,7 @@ sub parse_arguments {
'rp|rem-played|remove_played_file!' => \$opt{remove_played_file},
'clobber!' => \$opt{clobber},
'info|i|show-info=s' => \$opt{show_video_info},
- 'get-term-width' => \$opt{adj_for_term_width},
+ 'get-term-width!' => \$opt{adj_for_term_width},
'page=i' => \$opt{page},
'novideo|n!' => \$opt{novideo},
'results=i' => \$opt{results},
@@ -2467,10 +2459,10 @@ sub update_mplayer_arguments {
if ($opt{use_lower_cache}
or not $resolution ~~ [qw(original 1080 720)]) {
- set_mplayer_arguments($opt{lower_cache}, $opt{lower_cache_min});
+ set_mplayer_arguments($opt{nocache} ? (32, 0) : ($opt{lower_cache}, $opt{lower_cache_min}));
}
else {
- set_mplayer_arguments($opt{cache}, $opt{cache_min});
+ set_mplayer_arguments($opt{nocache} ? (32, 0) : ($opt{cache}, $opt{cache_min}));
}
}
@@ -8,7 +8,6 @@ use strict;
use autouse 'XML::Fast' => qw{ xml2hash($;%) };
use autouse 'URI::Escape' => qw{ uri_escape uri_escape_utf8 uri_unescape };
-
=head1 NAME
WWW::YoutubeViewer - A very easy interface to YouTube.
@@ -1122,10 +1121,12 @@ sub _get_pairs_from_info_data {
}
foreach my $hash_ref (@array) {
- if (exists $hash_ref->{url} and exists $hash_ref->{sig}) {
+ if (exists $hash_ref->{url}) {
# Add signature
- $hash_ref->{url} .= "&signature=$hash_ref->{sig}";
+ if (exists $hash_ref->{sig}) {
+ $hash_ref->{url} .= "&signature=$hash_ref->{sig}";
+ }
# Add proxy (if defined http_proxy)
if (defined(my $proxy_url = $self->get_http_proxy)) {
@@ -46,18 +46,17 @@ Get a HASH ref with the YouTube itags. {resolution => {type => itag}}.
=cut
sub get_itags {
- return
- scalar {
- 'original' => {normal => 38},
- '1080' => {normal => 37, webm => 46},
- '720' => {normal => 22, webm => 45},
- '480' => {normal => 35, webm => 44},
- '360' => {normal => 34, webm => 43},
- '340' => {normal => 18},
- '240' => {normal => 5},
- '180' => {normal => 36},
- '144' => {normal => 17},
- };
+ return scalar {
+ 'original' => [38],
+ '1080' => [37, 46], # 137 -- no audio
+ '720' => [22, 45], # 136 -- no audio
+ '480' => [35, 44], # 135 -- no audio
+ '360' => [34, 18, 43], # 134 -- no audio
+ '240' => [5], # 133 -- no audio
+ '180' => [36],
+ '144' => [17], # 160 -- no audio
+ 'audio' => [139, 140, 141, 171, 172],
+ };
}
=head2 get_resolutions()
@@ -68,11 +67,12 @@ Get a HASH ref with the itags as keys and resolutions as values.
sub get_resolutions {
my ($self) = @_;
+
state $itags = $self->get_itags();
return scalar {
map {
my $res = $_;
- map { $itags->{$res}{$_} => $res } keys %{$itags->{$_}}
+ map { $itags->{$res}[$_] => $res } 0 .. $#{$itags->{$_}}
} keys %{$itags}
};
}
@@ -87,8 +87,11 @@ sub find_streaming_url {
my ($self, $urls_ref, $prefer_webm, $resolution) = @_;
state $itags = $self->get_itags();
- state $resolutions = $self->get_resolutions();
- state $webm_itags = [map { $_->{webm} } grep { exists $_->{webm} } values %{$itags}];
+ state $resolutions = $self->get_resolutions($itags);
+
+ if (defined($resolution) and $resolution =~ /^([0-9]+)/) {
+ $resolution = $1;
+ }
my $wanted_itag = defined $resolution ? $itags->{$resolution} : undef;
@@ -97,21 +100,10 @@ sub find_streaming_url {
if (exists $url_ref->{itag} && exists $url_ref->{url}) {
if (defined $wanted_itag) {
- (
- (
- $url_ref->{itag} == (
- $prefer_webm && exists $wanted_itag->{webm}
- ? $wanted_itag->{webm}
- : $wanted_itag->{normal}
- )
- )
- || ($url_ref->{itag} == $wanted_itag->{normal})
- )
- || next;
- }
-
- if (not $prefer_webm) {
- if ($url_ref->{itag} ~~ $webm_itags) {
+ if (($prefer_webm and $url_ref->{itag} == $wanted_itag->[-1]) or ($url_ref->{itag} ~~ $wanted_itag)) {
+ ## ok
+ }
+ else {
next;
}
}
@@ -122,7 +114,24 @@ sub find_streaming_url {
}
}
- return unless defined $streaming;
+ if (not defined $streaming) {
+
+ foreach my $res (qw(original 1080 720 480 360 240 180 144)) {
+
+ foreach my $url (@{$urls_ref}) {
+ if (exists $url->{itag} and exists $url->{url}) {
+
+ if ($url->{itag} ~~ $itags->{$res}) {
+ $streaming = $url;
+ last;
+ }
+
+ }
+ }
+ last if defined($streaming);
+ }
+ }
+
return wantarray ? ($streaming, $resolutions->{$streaming->{itag}}) : $streaming;
}

0 comments on commit 2c57ea0

Please sign in to comment.