Commit e8b5012c by Joakim Nylén

Remove unused importers

parent 3c27e8ff
package NonameTV::Importer::Hallmark;
use strict;
use warnings;
=pod
Import data from Excel files delivered via e-mail.
Features:
=cut
use utf8;
use DateTime;
use Spreadsheet::ParseExcel;
use File::Temp qw/tempfile/;
use NonameTV qw/norm AddCategory MonthNumber/;
use NonameTV::Log qw/progress error/;
use NonameTV::Importer::BaseFile;
use base 'NonameTV::Importer::BaseFile';
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class->SUPER::new( @_ );
bless ($self, $class);
return $self;
}
sub ImportContentFile {
my $self = shift;
my( $file, $chd ) = @_;
$self->{fileerror} = 0;
my $xmltvid = $chd->{xmltvid};
my $channel_id = $chd->{id};
my $ds = $self->{datastore};
# Only process .xls files.
return if( $file !~ /\.xls$/i );
progress( "Hallmark: $xmltvid: Processing $file" );
my %columns = ();
my $date;
my $currdate = "x";
my $batch_id = $xmltvid . "_" . $file;
$ds->StartBatch( $batch_id , $channel_id );
my $oBook = Spreadsheet::ParseExcel::Workbook->Parse( $file );
# main loop
for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) {
my $oWkS = $oBook->{Worksheet}[$iSheet];
progress( "Hallmark: $chd->{xmltvid}: Processing worksheet: $oWkS->{Name}" );
# browse through rows
for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) {
# get the names of the columns from the 1st row
if( not %columns ){
for(my $iC = $oWkS->{MinCol} ; defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ; $iC++) {
$columns{norm($oWkS->{Cells}[$iR][$iC]->Value)} = $iC;
# columns alternate names
$columns{'Title CRO'} = $iC if( $oWkS->{Cells}[$iR][$iC]->Value =~ /Cro Title/i );
$columns{'Title CRO'} = $iC if( $oWkS->{Cells}[$iR][$iC]->Value =~ /^Title$/i );
}
next;
}
#foreach my $col (%columns) {
#print "$col\n";
#}
# date - column 0 ('Date')
my $oWkC = $oWkS->{Cells}[$iR][$columns{'Date'}];
next if( ! $oWkC );
$date = ParseDate( $oWkC->Value );
next if( ! $date );
# starttime - column ('Start')
$oWkC = $oWkS->{Cells}[$iR][$columns{'Start'}];
next if( ! $oWkC );
my $starttime = create_dt( $date , $oWkC->Value ) if( $oWkC->Value );
# endtime - column ('End')
$oWkC = $oWkS->{Cells}[$iR][$columns{'End'}];
next if( ! $oWkC );
my $endtime = create_dt( $date , $oWkC->Value ) if( $oWkC->Value );
# title - column ('Title')
$oWkC = $oWkS->{Cells}[$iR][$columns{'Title'}];
next if( ! $oWkC );
my $title = $oWkC->Value if( $oWkC->Value );
# CRO title - column ('Title CRO')
my $titlecro = $oWkS->{Cells}[$iR][$columns{'Title CRO'}]->Value if $oWkS->{Cells}[$iR][$columns{'Title CRO'}];
my $type = $oWkS->{Cells}[$iR][$columns{'Type'}]->Value if $oWkS->{Cells}[$iR][$columns{'Type'}];
my $prodno = $oWkS->{Cells}[$iR][$columns{'Prod No.'}]->Value if $oWkS->{Cells}[$iR][$columns{'Prod No.'}];
my $episodetitle = $oWkS->{Cells}[$iR][$columns{'Episode Title'}]->Value if $oWkS->{Cells}[$iR][$columns{'Episode Title'}];
my $slotlen = $oWkS->{Cells}[$iR][$columns{'Slot Len'}]->Value if $oWkS->{Cells}[$iR][$columns{'Slot Len'}];
my $epino = $oWkS->{Cells}[$iR][$columns{'Epi No.'}]->Value if $oWkS->{Cells}[$iR][$columns{'Epi No.'}];
my $cert = $oWkS->{Cells}[$iR][$columns{'Cert'}]->Value if $oWkS->{Cells}[$iR][$columns{'Cert'}];
my $genre = $oWkS->{Cells}[$iR][$columns{'Genre'}]->Value if $oWkS->{Cells}[$iR][$columns{'Genre'}];
my $year = $oWkS->{Cells}[$iR][$columns{'Year'}]->Value if $oWkS->{Cells}[$iR][$columns{'Year'}];
my $director = $oWkS->{Cells}[$iR][$columns{'Director'}]->Value if $oWkS->{Cells}[$iR][$columns{'Director'}];
my $actor = $oWkS->{Cells}[$iR][$columns{'Actor'}]->Value if $oWkS->{Cells}[$iR][$columns{'Actor'}];
my $episodesynopsis = $oWkS->{Cells}[$iR][$columns{'Episode Synopsis'}]->Value if $oWkS->{Cells}[$iR][$columns{'Episode Synopsis'}];
my $minisynopsis = $oWkS->{Cells}[$iR][$columns{'Mini Synopsis'}]->Value if $oWkS->{Cells}[$iR][$columns{'Mini Synopsis'}];
my $synopsis = $oWkS->{Cells}[$iR][$columns{'Synopsis'}]->Value if $oWkS->{Cells}[$iR][$columns{'Synopsis'}];
progress("Hallmark: $xmltvid: $starttime - $title");
my $ce = {
channel_id => $channel_id,
start_time => $starttime->ymd("-") . " " . $starttime->hms(":"),
end_time => $endtime->ymd("-") . " " . $endtime->hms(":"),
title => $titlecro || $title,
};
# subtitle
if( $episodetitle ){
$ce->{subtitle} = $episodetitle;
} elsif( $titlecro ){
$ce->{subtitle} = $title;
}
$ce->{description} = $synopsis if $synopsis;
$ce->{program_type} = $type if $type;
$ce->{production_date} = "$year-01-01" if $year;
$ce->{directors} = $director if $director;
$ce->{actors} = $actor if $actor;
# episode
if( $epino ){
$ce->{episode} = sprintf( ". %d .", $epino-1 );
$ce->{program_type} = 'series';
}
# genre
if( $genre ){
my($program_type, $category ) = $ds->LookupCat( "Hallmark", $genre );
AddCategory( $ce, $program_type, $category );
}
$ds->AddProgramme( $ce );
}
%columns = ();
}
$ds->EndBatch( 1 );
return;
}
sub ParseDate
{
my ( $dinfo ) = @_;
my( $day, $monthname, $year );
#print ">$dinfo<\n";
# format '033 03 Jul 2008'
if( $dinfo =~ /^\d+\s+\d+\s+\S+\s+\d+$/ ){
( $day, $monthname, $year ) = ( $dinfo =~ /^\d+\s+(\d+)\s+(\S+)\s+(\d+)$/ );
# format '05-sep-08'
} elsif( $dinfo =~ /^\d+-(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)-\d+$/i ){
( $day, $monthname, $year ) = ( $dinfo =~ /^(\d+)-(\S+)-(\d+)$/ );
# format 'Fri 30 Apr 2010'
} elsif( $dinfo =~ /^\S+\s*\d+\s*(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\s*\d+$/i ){
( $day, $monthname, $year ) = ( $dinfo =~ /^\S+\s*(\d+)\s*(\S+)\s*(\d+)$/ );
}
else {
return undef;
}
#print "DAY: $day\n";
#print "MON: $monthname\n";
#print "YEA: $year\n";
return undef if( ! $year);
$year+= 2000 if $year< 100;
my $mon = MonthNumber( $monthname, "en" );
#print "DAY: $day\n";
#print "MON: $mon\n";
my $dt = DateTime->new( year => $year,
month => $mon,
day => $day,
hour => 0,
minute => 0,
second => 0,
time_zone => 'Europe/Zagreb',
);
$dt->set_time_zone( "UTC" );
return $dt;
}
sub create_dt
{
my( $date, $time ) = @_;
my( $hour, $min, $sec ) = ( $time =~ /(\d{2}):(\d{2}):(\d{2})/ );
my $dt = $date->clone()->add( hours => $hour , minutes => $min , seconds => $sec );
return $dt;
}
1;
### Setup coding system
## Local Variables:
## coding: utf-8
## End:
package NonameTV::Importer::HighTV_3D;
use strict;
use warnings;
=pod
Importer for HighTV 3D (http://hightv.tv)
The excel files is sent via mail
Every day is runned as a seperate batch.
=cut
use utf8;
use POSIX;
use DateTime;
use XML::LibXML;
use Spreadsheet::ParseExcel;
use NonameTV qw/norm/;
use NonameTV::DataStore::Helper;
use NonameTV::Log qw/progress error/;
use NonameTV::Config qw/ReadConfig/;
use NonameTV::Importer::BaseFile;
use base 'NonameTV::Importer::BaseFile';
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = $class->SUPER::new( @_ );
bless ($self, $class);
my $conf = ReadConfig();
$self->{FileStore} = $conf->{FileStore};
my $dsh = NonameTV::DataStore::Helper->new( $self->{datastore} );
$self->{datastorehelper} = $dsh;
return $self;
}
sub ImportContentFile {
my $self = shift;
my( $file, $chd ) = @_;
$self->{fileerror} = 0;
if( $file =~ /\.xls$/i ){
$self->ImportXLS( $file, $chd );
} else {
error( "High: Unknown file format: $file" );
}
return;
}
sub ImportXLS
{
my $self = shift;
my( $file, $chd ) = @_;
my $dsh = $self->{datastorehelper};
my $ds = $self->{datastore};
my %columns = ();
my $date;
my $currdate = "x";
my @ces;
progress( "High: Processing flat XLS $file" );
my $oBook = Spreadsheet::ParseExcel::Workbook->Parse( $file );
# main loop
foreach my $oWkS (@{$oBook->{Worksheet}}) {
my $foundcolumns = 0;
# browse through rows
for(my $iR = 1 ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) {
# date - column 0 ('Date')
my $oWkC = $oWkS->{Cells}[$iR][0];
next if( ! $oWkC );
next if( ! $oWkC->Value );
$date = ParseDate( $oWkC->Value );
next if( ! $date );
# Startdate
if( $date ne $currdate ) {
if( $currdate ne "x" ) {
$dsh->EndBatch( 1 );
}
my $batchid = $chd->{xmltvid} . "_" . $date;
$dsh->StartBatch( $batchid , $chd->{id} );
progress("High: Date is $date");
$dsh->StartDate( $date , "00:00" );
$currdate = $date;
}
# time
$oWkC = $oWkS->{Cells}[$iR][1];
next if( ! $oWkC );
my $time = ParseTime($oWkC->Value) if( $oWkC->Value );
# title
$oWkC = $oWkS->{Cells}[$iR][2];
next if( ! $oWkC );
my $title = $oWkC->Value if( $oWkC->Value );
$title =~ s/- In 3D//g;
$title =~ s/In 3D//g;
# season, episode, episode title
my($ep, $season, $episode);
( $season, $ep ) = ($title =~ /\bSeason\s+(\d+)\s+EP\s+(\d+)/ );
if(defined($season)) {
$episode = sprintf( "%d . %d . ", $season-1, $ep-1 );
$title =~ s/- Season (.*) EP (.*)\)//g;
$title =~ s/Season (.*) EP (.*)\)//g;
}
( $season, $ep ) = ($title =~ /\bS(\d+)\s+E(\d+)/ );
if(defined($season)) {
$episode = sprintf( "%d . %d . ", $season-1, $ep-1 );
$title =~ s/- S(.*) E(.*)\)//g;
$title =~ s/S(.*) E(.*)\)//g;
}
( $ep ) = ($title =~ /\bEP\s+(\d+)/ );
if(defined($ep) && !defined($episode)) {
$episode = sprintf( " . %d .", $ep-1 );
$title =~ s/- EP (.*)\)//g;
$title =~ s/EP (.*)\)//g;
}
( $ep ) = ($title =~ /\bPART\s+(\d+)/ );
if(defined($ep) && !defined($episode)) {
$episode = sprintf( " . %d .", $ep-1 );
$title =~ s/- PART (.*)\)//g;
$title =~ s/PART (.*)\)//g;
}
my ($new_title, $episode_title) = split(/-/, $title);
if(defined($new_title) and $new_title ne "") {
$title = $new_title;
}
# empty last day array
undef @ces;
my $ce = {
channel_id => $chd->{channel_id},
title => norm( $title ),
start_time => $time,
};
if(defined($episode) && $episode ne "") {
$ce->{episode} = $episode;
}
if(defined($episode_title) && $episode_title ne "") {
$ce->{subtitle} = norm($episode_title);
}
progress("High: $time - $title");
$dsh->AddProgramme( $ce );
push( @ces , $ce );
} # next row
} # next worksheet
$dsh->EndBatch( 1 );
return 1;
}
sub ParseDate {
my ( $text ) = @_;
my( $year, $day, $month );
# format '2011-04-13'
if( $text =~ /^\d{4}\-\d{2}\-\d{2}$/i ){
( $year, $month, $day ) = ( $text =~ /^(\d{4})\-(\d{2})\-(\d{2})$/i );
# format '2011/05/16'
} elsif( $text =~ /^\d{4}\/\d{2}\/\d{2}$/i ){
( $year, $month, $day ) = ( $text =~ /^(\d{4})\/(\d{2})\/(\d{2})$/i );
# format '1/14/2012'
} elsif( $text =~ /^\d+\/\d+\/\d{4}$/i ){
( $month, $day, $year ) = ( $text =~ /^(\d+)\/(\d+)\/(\d+)$/i );
}
$year += 2000 if $year < 100;
return sprintf( '%d-%02d-%02d', $year, $month, $day );
}
sub ParseTime {
my( $text ) = @_;
my( $hour , $min );
if( $text =~ /^\d+:\d+$/ ){
( $hour , $min ) = ( $text =~ /^(\d+):(\d+)$/ );
}
return sprintf( "%02d:%02d", $hour, $min );
}
1;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment