2 # -*- coding: ascii -*-
5 # Copyright (C) 2010 Toni Gundogdu <legatvs@gmail.com>.
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 binmode( STDOUT
, ":utf8" );
25 binmode( STDERR
, ":utf8" );
27 use Getopt
::ArgvFile
( home
=> 1, startupFilename
=> [qw(.umphrc)] );
28 use Getopt
::Long
qw(:config bundling);
30 my $VERSION = "0.1.1";
43 'version|v' => \
&print_version
,
44 'help|h' => \
&print_help
,
50 "umph $VERSION. Copyright (C) 2010 Toni Gundogdu. License: GNU GPL version 3
51 or later This is free software; see the source for copying conditions. There
52 is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
60 Pod
::Usage
::pod2usage
( -exitstatus
=> 0, -verbose
=> 1 );
65 print_help
if scalar @ARGV == 0;
67 my $req_body = "http://gdata.youtube.com/feeds/api/playlists/";
71 if ( $url =~ /^http:/i ) {
74 if ( $url =~ /view_play_list\?p=(.*?)$/i ) {
81 $url = "$req_body$url";
85 print STDERR
"Fetch $url ...\n";
89 my $p = new XML
::DOM
::Parser
;
90 my $doc = $p->parsefile($url);
91 my $root = $doc->getDocumentElement;
93 print STDERR
":: Parse playlist for video entries ...\n";
95 for my $entry ( $root->getElementsByTagName("entry") ) {
97 my $title = to_item
( $entry, "title" )->getFirstChild->getNodeValue;
100 = to_item
( $entry, "link" )->getAttributeNode("href")->getValue;
102 my %data = ( title
=> $title, url
=> $link, selected
=> 1 );
103 push @entries, \
%data;
108 print STDERR
"::: Found " . scalar @entries . " video entries\n";
110 prompt
() if $config{interactive
};
113 print "$_->{url}\n" if $_->{selected
} || !$config{interactive
};
118 my ( $entry, $name ) = @_;
119 return $entry->getElementsByTagName($name)->item(0);
130 'n' => \
&select_none
,
131 'r' => \
&revert_selection
,
133 print STDERR
"Enter prompt\nNote: all videos selected by default\n";
134 print STDERR
"Type \"help\" to get a list of commands\n";
140 if ( $ln =~ /(\d+)/ ) {
144 next if $ln !~ /(\w)/;
145 $cmds{$1}() if defined $cmds{$1};
152 if ( $i >= 0 && exists $entries[$i] ) {
153 $entries[$i]->{selected
} = !$entries[$i]->{selected
};
157 printf STDERR
"error: out of range\n";
165 list .. display playlist entries (numbered, *=selected)
166 all .. select all videos
168 revert .. revert selection
169 (number) .. toggle (select, unselect) video, see list output
171 dump .. dump selected video urls to stdout and exit
172 quit .. terminate program
174 Command name abbreviations are allowed, e.g. \"a\" instead of \"all\".
185 printf STDERR
"%2d: $_->{title}%s\n", ++$i, $_->{selected
} ?
"*" : "";
194 $_->{selected
} = 1 foreach @entries;
199 $_->{selected
} = 0 foreach @entries;
203 sub revert_selection
{
204 $_->{selected
} = !$_->{selected
} foreach @entries;
212 umph - Youtube video playlist parser for cclive and alike tools
216 umph [options] [URL|PLAYLIST_ID]
220 umph is a command line tool for parsing Youtube playlists. It prints
221 playlist video links, each separated with a newline, to the standard
222 output stream, while everything else gets printed to the standard
223 error stream. umph can be run with a simple interactive prompt to
224 select the printed video links.
228 -h, --help print help and exit
229 -v, --version print version and exit
230 -i, --interactive be interactive, default is no
232 =head1 OPTION DESCRIPTIONS
240 =item B<-v, --version>
242 Print version and exit.
244 =item B<-i, --interactive>
246 Be interactive, default is no. Implies the interactive prompt which
247 can be used select the printed video links.
255 =item umph "http://www.youtube.com/view_play_list?p=AAF3A1D0CA1E304F"
257 =item umph AAF3A1D0CA1E304F
259 Both fetch and parse the same playlist (identified as "AAF3A1D0CA1E304F").
261 =item umph AAF3A1D0CA1E304F | cclive -f mp4
263 Passes the parsed video links to cclive.
269 Exits 0 on success, otherwise 1.
275 =item $HOME/.umphrc, for example:
277 echo "--interactive" >> ~/.umphrc
283 umph depends on XML::DOM which uses LWP::UserAgent to retrieve
284 the playlist data. Note that LWP::UserAgent reads http_proxy
288 http://umph.googlecode.com/
290 Development repository:
291 git clone git://repo.or.cz/umph.git
295 C<cclive(1)> C<clive(1)>
299 Toni Gundogdu <legatvs@gmail.com>