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.
221 It was written to be used with cclive but other tools may
226 -h, --help print help and exit
227 -v, --version print version and exit
228 -i, --interactive be interactive, default is no
230 =head1 OPTIONS DESCRIPTIONS
238 =item B<-v, --version>
240 Print version and exit.
242 =item B<-i, --interactive>
244 Be interactive, default is no. Implies prompting, or selecting videos.
252 =item umph "http://www.youtube.com/view_play_list?p=AAF3A1D0CA1E304F"
254 =item umph "http://gdata.youtube.com/feeds/api/playlists/AAF3A1D0CA1E304F?v=2"
256 =item umph AAF3A1D0CA1E304F
258 All of the three above do the same.
260 =item umph AAF3A1D0CA1E304F | cclive -f mp4
262 Passes the parsed video links to cclive.
268 Exits 0 on success, otherwise 1.
274 =item $HOME/.umphrc, for example:
276 echo "--interactive" >> ~/.umphrc
282 umph depends on XML::DOM which uses LWP::UserAgent to retrieve
283 the playlist data. Note that LWP::UserAgent reads http_proxy
287 http://umph.googlecode.com/
289 Development repository:
290 git clone git://repo.or.cz/umph.git
294 C<cclive(1)> C<clive(1)>
298 Toni Gundogdu <legatvs@gmail.com>