diff options
Diffstat (limited to 'angel.pl')
-rwxr-xr-x | angel.pl | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/angel.pl b/angel.pl new file mode 100755 index 0000000..6ab24ac --- /dev/null +++ b/angel.pl @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use JSON; + +my $ENDPOINT = "https://www.googleapis.com/youtube/v3"; +my $YT_API_KEY = $ENV{'YT_API_KEY'} or die "YT_API_KEY not defined"; + +sub decode_json_utf8 { + my $json = join "", @_; + utf8::encode($json); + return decode_json($json); +} + +sub api_search { + return (decode_json_utf8 `curl -s '$ENDPOINT/search?channelId=UCGUc7rf0fbEzrGb7kkmu6zw&part=snippet&q=Informativo&maxResults=1&key=$YT_API_KEY'`)->{items}; +} + +my $today = `date '+%Y-%m-%dT'`; +chomp $today; + +my ($video) = @{api_search()}; + +if ($video->{snippet}{publishTime} =~ /^$today/) { + print "$video->{snippet}{title}\nhttps://www.youtube.com/watch?v=$video->{id}{videoId}\n"; +} |