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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
#!perl
# PODNAME: youtube-playlists.pl
use strict;
use warnings;
use WWW::YouTube::Download;
use Getopt::Long qw(GetOptions :config bundling);
use Pod::Usage qw(pod2usage);
my $proxy = undef;
GetOptions(
'C|no-colors!' => \my $disable_colors,
'i|video-id' => \my $only_id,
'n|normalize' => \my $normalize,
'p|proxy=s' => \$proxy,
'user-agent=s' => \my $user_agent,
'limit=s' => \my $limit,
'u|users' => \my $user_uploads,
'v|verbose' => \my $verbose,
'h|help' => sub { pod2usage(exitval => 0, -noperldoc => 1, -verbose => 2) },
'V|version' => sub { show_version() },
) or pod2usage(2);
pod2usage() unless @ARGV;
my $yt = WWW::YouTube::Download->new( verbose => $verbose );
if($proxy){
$yt->ua->proxy(['http','https'] => $proxy);
print "--> Using proxy $proxy\n";
}
if ($user_agent) {
$yt->ua->agent($user_agent);
print "--> Using user-agent-string: '". $yt->ua->agent()."'\n";
}
$yt->ua->default_header('Accept-Encoding' => scalar HTTP::Message::decodable());
main: {
for my $id_or_url (@ARGV) {
chatty("--> Working on %s\n", $id_or_url);
my $id;
if ($user_uploads) {
$id = $yt->user_id($id_or_url);
} else {
$id = $yt->playlist_id($id_or_url);
}
throw('%s is not a supported argument', $id_or_url) unless $id;
if ($normalize) {
print "$id\n";
next;
}
chatty("--> Recognized playlist id %s\n", $id);
my $videos = $yt->playlist($id, { limit => $limit });
my $cnt;
for(@$videos){
$cnt++;
print 'https://www.youtube.com/watch?v=' . $_->{id} ."\n";
}
}
}
sub throw {
my $format = shift;
die pcolor(['red'], sprintf($format, @_)), "\n";
}
sub chatty {
return unless $verbose;
my $format = shift;
print STDERR sprintf $format, @_;
}
sub pcolor {
my ($color, @msg) = @_;
if ($^O eq 'MSWin32' || $disable_colors || !-t STDOUT) {
return @msg;
}
eval { require Term::ANSIColor };
return @msg if $@; # module not available
return Term::ANSIColor::colored($color, @msg);
}
sub show_version {
print "youtube-playlists (WWW::YouTube::Download) version $WWW::YouTube::Download::VERSION\n";
exit;
}
=pod
=encoding UTF-8
=head1 NAME
youtube-playlists.pl - Find YouTube video URLs from playlist(s)
=head1 VERSION
version 0.65
=head1 SYNOPSIS
# print the list of video URLs
$ youtube-playlists https://www.youtube.com/playlist?list=PLB199169FA7413767
$ youtube-playlists PLB199169FA7413767
# pipe result to youtube-download
$ youtube-playlists PLB199169FA7413767 | youtube-download
# with socks proxy
$ youtube-playlists -p socks://<some IP>:<some port>/ PLB199169FA7413767
=head1 DESCRIPTION
For each given argument B<youtube-playlists> generates a list of YouTube
video URLs. Arguments can be URL to playlist or to favorite list, or
only IDs of a playlist or a favorite list.
In the spirit of the whole I<WWW::YouTube::Download> distribution, playlist
extraction relies solely on scraping common YouTube pages and requires no API key.
=head1 OPTIONS
=over
=item -C, --no-colors
Force disable colored output
=item -i, --video-id
Print only video IDs, not full URLs
=item -n, --normalize
Print only normalized playlist IDs, but do not fetch anything.
You can call it also dry run.
=item -p, --proxy
Use the given proxy. Note that using a socks proxy requires LWP::protocol::socks to be installed.
=item -u, --users
Parses given parameters as YouTube usernames and lists their uploaded videos.
=item --user-agent
Supply your own user agent string
=item --limit
Limit how many fetches the script is allowed to make while scraping playlist items.
=item -v, --verbose
turns on chatty output
=item -h, --help
display help
=item -V, --version
display version
=back
=head1 AUTHOR
xaicron <xaicron {@} cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Yuji Shimada.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
# ABSTRACT: Find YouTube video URLs from playlist(s)
|