test augmenter with current date, silence some output
[nonametv.git] / test / augment.pl
blob613d3bdf80b4e159bf206affb4e9f776d5c74241
1 #!/usr/bin/perl -w
3 use strict;
4 use utf8;
6 use FindBin;
7 use lib "$FindBin::Bin/../lib";
9 use DateTime;
10 use Data::Dumper;
11 use Encode;
12 #use NonameTV::Augmenter::Tvdb;
13 use NonameTV::Factory qw/CreateAugmenter CreateDataStore CreateDataStoreDummy /;
15 my $ds = CreateDataStore( );
17 my $dt = DateTime->now( time_zone => 'UTC' );
18 $dt->add( days => 7 );
20 my $batchid = 'neo.zdf.de_' . $dt->week_year() . '-' . $dt->week();
21 printf( "augmenting %s...\n", $batchid );
23 my $augmenter = CreateAugmenter( 'Tvdb', $ds );
25 # program metadata from augmenter
26 my $newprogram;
27 # result code from augmenter
28 my $result;
30 # stripped down rule for testing
31 my %simplerule = ( matchby => 'episodetitle' );
33 my ( $res, $sth ) = $ds->sa->Sql( "
34 SELECT p.* from programs p, batches b
35 WHERE (p.batch_id = b.id)
36 AND (b.name LIKE ?)
37 ORDER BY start_time asc, end_time desc",
38 # name of batch to use for testing
39 [$batchid] );
41 my $found=0;
42 my $notfound=0;
43 my $ce = $sth->fetchrow_hashref();
44 while( defined( $ce ) ) {
45 if( ( $ce->{program_type} eq 'series' )and( defined( $ce->{subtitle} ) ) ) {
46 $ce->{subtitle} =~ s|,\sTeil (\d+)$| ($1)|;
47 $ce->{subtitle} =~ s|\s-\sTeil (\d+)$| ($1)|;
48 $ce->{subtitle} =~ s|\s\(Teil (\d+)\)$| ($1)|;
49 ( $newprogram, $result ) = $augmenter->AugmentProgram( $ce, \%simplerule );
50 if( defined( $newprogram) ) {
51 $found++;
52 } else {
53 $notfound++;
57 $ce = $sth->fetchrow_hashref();
60 printf( "found %d/%d episodes at tvdb by name\n", $found, $found+$notfound );