#!/usr/bin/perl use warnings; use strict; use Data::Dump qw| dump |; my $lib = $0; $lib =~ s#^(.*)/[^/]*$#$1/../lib#; use File::Spec; require File::Spec->catfile($lib, "YTYT.pm");; # Setup YouTube object my $youtube = YTYT::new(); $youtube->db_connect(); # Get Channel list and Setup Hash Ref for Videos my $channels = $youtube->{dbh}->selectall_arrayref("SELECT channelId FROM channels;"); my @channels; foreach my $channel_ref (@$channels) { push @channels, @$channel_ref[0]; } # Get list of Videos from all subscriptions foreach my $channelId (@channels) { my @videos = $youtube->latest_videos( channelId => $channelId ); unless (scalar @videos) { print(" no videos found for $channelId\n"); next; } foreach my $video_ref (@videos) { my %video = %$video_ref; $video{channelId} = $channelId; $video{seen} = 0; if (scalar $youtube->{dbh}->selectrow_array("SELECT videoId FROM videos WHERE videoId = '$video{videoId}';")) { $youtube->db_update( table => 'videos', %video ); } else { $youtube->db_insert( table => 'videos', %video ); } } } $youtube->db_disconnect(); print "Completed without error\n";