App-WatchLater
view release on metacpan or search on metacpan
bin/yt-desc-links view on Meta::CPAN
#!/usr/bin/env perl
package App::YtDescLinks;
use 5.016;
use strict;
use warnings;
use Carp;
use Getopt::Long qw(:config auto_help gnu_getopt);
use List::Util qw(any);
use Pod::Usage;
use Try::Tiny;
use URI::Find;
use App::WatchLater::YouTube;
my %opts;
GetOptions(
\%opts,
'filter|f!',
'version|v',
) or pod2usage(2);
if ($opts{version}) {
say 'yt-desc-links ' . App::WatchLater::YouTube->VERSION;
exit;
}
my $api = App::WatchLater::YouTube->new(
api_key => $ENV{YT_API_KEY},
access_token => $ENV{YT_ACCESS_TOKEN},
);
while (<>) {
try {
my $video_id = find_video_id($_);
my $snippet = $api->get_video($video_id);
say $video_id;
say biggest_thumbnail($snippet->{thumbnails});
say_uris($snippet->{description});
} catch {
print STDERR $_;
};
}
use constant FILTERS => (
qr/pixiv/,
qr/deviantart/,
qr/imgur/,
qr/zerochan/,
qr/anime-pictures/,
);
sub should_print {
return 1 unless $opts{filter};
my ($uri) = @_;
any { $uri =~ $_ } FILTERS;
}
sub say_uris {
my ($text) = @_;
my $finder = URI::Find->new(sub { say $_[1] if should_print $_[1] });
$finder->find(\$text);
}
sub biggest_thumbnail {
my ($href) = @_;
my $maxw = 0;
my $url;
for my $thumb (values %$href) {
( run in 4.814 seconds using v1.01-cache-2.11-cpan-2398b32b56e )