#!/usr/bin/perl -w
use strict;
use warnings;
use TV::Anytime;

# Pull out all films on the BBC channels from the TV-Anywhere data and show
# them on the command line. Not perfect but a good start.
# Version: 0.1 (20050902)
# Author: Dean Wilson 

# this is the base of where you extracted the TV-Anytime data
my $tvdata = '/home/dwilson/sandbox/tvanytime/20050902';

my $tv = TV::Anytime->new($tvdata);

# grab all the tv data. No radio
my @tv_services = $tv->services_television;

foreach my $channel (@tv_services) {
  print $channel->name, "\n";

  foreach my $program ($channel->programs) {
  my @genres = $program->genres;

    # check to make sure it's a film
    foreach my $genre (@genres) {
      if ($genre->name  eq 'OriginationCS' &&
          $genre->value eq 'CINEMA INDUSTRY ORIGINATED') {
        # print out the name and details of when it's on
        print "  ", $program->title, "\n";
        foreach my $event ($program->events) {
          print "  "
          . $event->start->datetime . " -> "
          . $event->stop->datetime . " ("
          . $event->duration->minutes . " mins)\n";
        }
      }
    }
  }
}
