1 package NonameTV
::Importer
::ExtremeSports_v2
;
8 Import data for Extreme Sports.
9 Version 2 - Mail - Working.
18 use Spreadsheet
::ParseExcel
;
21 use NonameTV qw
/norm AddCategory MonthNumber/;
22 use NonameTV
::DataStore
::Helper
;
23 use NonameTV
::Log qw
/progress error/;
24 use NonameTV
::Config qw
/ReadConfig/;
26 use NonameTV
::Importer
::BaseFile
;
28 use base
'NonameTV::Importer::BaseFile';
32 my $class = ref($proto) || $proto;
33 my $self = $class->SUPER::new
( @_ );
34 bless ($self, $class);
36 my $dsh = NonameTV
::DataStore
::Helper
->new( $self->{datastore
} );
37 $self->{datastorehelper
} = $dsh;
42 sub ImportContentFile
{
44 my( $file, $chd ) = @_;
46 $self->{fileerror
} = 0;
48 if( $file =~ /\.xls$/i ){
49 $self->ImportFlatXLS( $file, $chd );
51 error
( "ExtremeSports: Unknown file format: $file" );
60 my( $file, $chd ) = @_;
62 my $dsh = $self->{datastorehelper
};
63 my $ds = $self->{datastore
};
69 progress
( "ExtremeSports FlatXLS: $chd->{xmltvid}: Processing flat XLS $file" );
71 my $oBook = Spreadsheet
::ParseExcel
::Workbook
->Parse( $file );
73 my($iR, $oWkS, $oWkC);
75 my( $time, $episode );
76 my( $program_title , $program_description );
80 foreach my $oWkS (@
{$oBook->{Worksheet
}}) {
82 if( $oWkS->{Name
} !~ /Eng/ ){
83 progress
( "ExtremeSports: $chd->{xmltvid}: Skipping other language: $oWkS->{Name}" );
87 progress
("--------- SHEET: $oWkS->{Name}");
90 # the first row looks like one cell saying like "EPG DECEMBER 2007 (Yamal - HotBird)"
91 # the 2nd row contains column names Date, Time (local), Progran, Description
92 #for(my $iR = $oWkS->{MinRow} ; defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) {
93 for(my $iR = 1 ; defined $oWkS->{MaxRow
} && $iR <= $oWkS->{MaxRow
} ; $iR++) {
96 $oWkC = $oWkS->{Cells
}[$iR][0];
98 $date = ParseDate
( $oWkC->Value );
99 #$date = $oWkC->Value;
103 progress
("SKIPPING :D");
107 if($date ne $currdate ) {
108 if( $currdate ne "x" ) {
109 # save last day if we have it in memory
110 # FlushDayData( $channel_xmltvid, $dsh , @ces );
116 my $batchid = $chd->{xmltvid
} . "_" . $date;
117 $dsh->StartBatch( $batchid , $chd->{id
} );
118 $dsh->StartDate( $date , "06:00" );
121 progress
("ExtremeSports: Date is: $date");
124 #if($iR == 28) { next; }
128 $oWkC = $oWkS->{Cells
}[$iR][1];
130 my $time = ParseTime
( $oWkC->Value );
133 #use Data::Dumper; print Dumper($oWkS->{Cells}[28]);
142 # program_title (column 3)
143 $oWkC = $oWkS->{Cells
}[$iR][3];
145 # Here's where the magic happends.
146 # Love goes out to DrForr.
147 $test = $oWkC->Value;
149 $title = norm
($test) if $test ne "";
150 # If no series title, get it from episode name.
153 $oWkC = $oWkS->{Cells
}[$iR][5];
154 my $desc = $oWkC->Value;
156 if( $time and $title ){
158 # empty last day array
161 progress
("$time $title");
164 channel_id
=> $chd->{id
},
165 title
=> norm
($title),
167 description
=> norm
($desc),
171 $oWkC = $oWkS->{Cells
}[$iR][29];
172 my $episode = $oWkC->Value;
174 $ce->{episode
} = ". " . ($episode-1) . " ." if $episode ne "";
178 $dsh->AddProgramme( $ce );
197 my( $year, $day, $month );
199 # format '2011-04-13'
200 if( $text =~ /^(\d+)\/(\d
+)\
/(\d+)$/i ){
201 ( $month, $day, $year ) = ( $text =~ /^(\d+)\/(\d
+)\
/(\d{2})$/i );
203 # format '2011-05-16'
204 } elsif( $text =~ /^\d{4}-\d{2}-\d{2}$/i ){
205 ( $year, $month, $day ) = ( $text =~ /^(\d{4})-(\d{2})-(\d{2})$/i );
208 $year += 2000 if $year < 100;
210 my $dt = DateTime
->new(
214 time_zone
=> "Europe/Stockholm"
217 $dt->set_time_zone( "UTC" );
220 return $dt->ymd("-");
221 #return $year."-".$month."-".$day;
227 #print "ParseTime: >$text<\n";
231 if( $text =~ /^\d+:\d+$/ ){
232 ( $hour , $min ) = ( $text =~ /^(\d+):(\d+)$/ );
235 return sprintf( "%02d:%02d", $hour, $min );
240 ### Setup coding system