#!/usr/bin/env perl
use 5.010;
use strict;
use warnings;
use utf8;
#binmode STDOUT, ":utf8";
use URI;
use Web::Scraper;
use Excel::Writer::XLSX;
use LWP::UserAgent;
use Mojo::UserAgent;
use WWW::YouTube::Download;
use WebService::GData::YouTube;
my ($search, $limit) = (@ARGV);
$limit //= 10;
my $search_youtube = WebService::GData::YouTube->new;
$search_youtube->query()->q($search)->limit($limit, 0);
my $results = $search_youtube->search_video();
my $client = WWW::YouTube::Download->new;
foreach my $ret (@$results) {
say "Starting Download : " . $ret->title;
$client->download($ret->video_id);
}
IyEvdXNyL2Jpbi9lbnYgcGVybAp1c2UgNS4wMTA7CnVzZSBzdHJpY3Q7CnVzZSB3YXJuaW5nczsKdXNlIHV0Zjg7CiNiaW5tb2RlIFNURE9VVCwgIjp1dGY4IjsKCnVzZSBVUkk7CnVzZSBXZWI6OlNjcmFwZXI7CnVzZSBFeGNlbDo6V3JpdGVyOjpYTFNYOwp1c2UgTFdQOjpVc2VyQWdlbnQ7Cgp1c2UgTW9qbzo6VXNlckFnZW50Owp1c2UgV1dXOjpZb3VUdWJlOjpEb3dubG9hZDsKdXNlIFdlYlNlcnZpY2U6OkdEYXRhOjpZb3VUdWJlOwogCgpteSAoJHNlYXJjaCwgJGxpbWl0KSA9IChAQVJHVik7CiRsaW1pdCAvLz0gMTA7CiAKCm15ICRzZWFyY2hfeW91dHViZSA9IFdlYlNlcnZpY2U6OkdEYXRhOjpZb3VUdWJlLT5uZXc7CiAKCiRzZWFyY2hfeW91dHViZS0+cXVlcnkoKS0+cSgkc2VhcmNoKS0+bGltaXQoJGxpbWl0LCAwKTsKIAoKbXkgJHJlc3VsdHMgPSAkc2VhcmNoX3lvdXR1YmUtPnNlYXJjaF92aWRlbygpOwogCgpteSAkY2xpZW50ID0gV1dXOjpZb3VUdWJlOjpEb3dubG9hZC0+bmV3Owpmb3JlYWNoIG15ICRyZXQgKEAkcmVzdWx0cykgewoJc2F5ICJTdGFydGluZyBEb3dubG9hZCA6ICIgLiAkcmV0LT50aXRsZTsKCSRjbGllbnQtPmRvd25sb2FkKCRyZXQtPnZpZGVvX2lkKTsKfQo=