Permalink
Browse files

Added two new options: '--max-seconds=i' and '--min-seconds=i' which …

…will play only the videos with a length greater or smaller than a given number of seconds.
  • Loading branch information...
1 parent 86a197e commit 7dcda9e8d60cf6c957185347b2d9e0222108d7ab @trizen committed Dec 19, 2013
Showing with 15 additions and 1 deletion.
  1. +15 −1 WWW-YoutubeViewer/bin/youtube-viewer
@@ -18,7 +18,7 @@
#-------------------------------------------------------
# Appname: youtube-viewer
# Created on: 02 June 2010
-# Latest edit on: 11 December 2013
+# Latest edit on: 19 December 2013
# Websites: http://trizen.googlecode.com
# https://github.com/trizen/youtube-viewer
#-------------------------------------------------------
@@ -554,6 +554,8 @@ Other options:
--comments=ID/URL : show comments for a YouTube video
--get-title=ID/URL : get and print the title for a video
--get-desc=ID/URL : get and print the description for a video
+ --max-seconds=i : don't play videos longer than i seconds
+ --min-seconds=i : don't play videos shorter than i seconds
--gcap=s : set the full path to the gcap script
--get-captions! : download the closed captions (with gcap)
--captions-dir=s : the directory where to download the .srt files
@@ -1123,6 +1125,9 @@ sub parse_arguments {
'duration=s' => \$opt{duration},
'time=s' => \$opt{time},
+ 'max-seconds=i' => \$opt{max_seconds},
+ 'min-seconds=i' => \$opt{min_seconds},
+
'like=s' => \$opt{like_video},
'dislike=s' => \$opt{dislike_video},
'author=s' => \$opt{author},
@@ -2573,6 +2578,15 @@ sub play_videos {
my ($videos) = @_;
foreach my $video (@{$videos}) {
+
+ if (defined($opt{max_seconds})) {
+ next if $video->{duration} > $opt{max_seconds};
+ }
+
+ if (defined($opt{min_seconds})) {
+ next if $video->{duration} < $opt{min_seconds};
+ }
+
my $streaming = get_streaming_url($video->{videoID});
if (defined $streaming->{info}{status} and not $streaming->{info}{status} =~ /^(?:ok|success)/i) {

0 comments on commit 7dcda9e

Please sign in to comment.