1 package NonameTV
::Importer
::TravelChannel_v2
;
8 Import data for TravelChannel.
9 Version 2 - Mail - Working.
18 use Spreadsheet
::ParseExcel
;
21 use NonameTV qw
/MyGet 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 $self->{MinMonths
} = 1 unless defined $self->{MinMonths
};
37 $self->{MaxMonths
} = 2 unless defined $self->{MaxMonths
};
39 defined( $self->{UrlRoot
} ) or die "You must specify UrlRoot";
41 my $dsh = NonameTV
::DataStore
::Helper
->new( $self->{datastore
} );
42 $self->{datastorehelper
} = $dsh;
47 sub ImportContentFile
{
49 my( $file, $chd ) = @_;
51 $self->{fileerror
} = 0;
53 if( $file =~ /\.xls$/i ){
54 $self->ImportFlatXLS( $file, $chd );
56 error
( "TC: Unknown file format: $file" );
65 my( $file, $chd ) = @_;
67 my $dsh = $self->{datastorehelper
};
68 my $ds = $self->{datastore
};
74 progress
( "TC FlatXLS: $chd->{xmltvid}: Processing flat XLS $file" );
76 my $oBook = Spreadsheet
::ParseExcel
::Workbook
->Parse( $file );
78 my($iR, $oWkS, $oWkC);
80 my( $time, $episode );
81 my( $program_title , $program_description );
85 foreach my $oWkS (@
{$oBook->{Worksheet
}}) {
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 = 2 ; defined $oWkS->{MaxRow
} && $iR <= $oWkS->{MaxRow
} ; $iR++) {
96 $oWkC = $oWkS->{Cells
}[$iR][1];
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
("TC: Date is: $date");
124 #if($iR == 28) { next; }
128 $oWkC = $oWkS->{Cells
}[$iR][2];
130 my $time = ParseTime
( $oWkC->Value );
133 #use Data::Dumper; print Dumper($oWkS->{Cells}[28]);
143 # program_title (column 3)
144 $oWkC = $oWkS->{Cells
}[$iR][3];
146 # Here's where the magic happends.
147 # Love goes out to DrForr.
148 $title = $oWkC->Value;
151 # EPG is actually listing.
152 $oWkC = $oWkS->{Cells
}[$iR][8];
153 my $epg = $oWkC->Value;
155 $oWkC = $oWkS->{Cells
}[$iR][6];
156 my $subtitle = $oWkC->Value;
158 $oWkC = $oWkS->{Cells
}[$iR][4];
159 my $sea = $oWkC->Value;
161 $oWkC = $oWkS->{Cells
}[$iR][5];
162 my $epi = $oWkC->Value;
164 # Episode info in xmltv-format
165 if( ($epi > 0) and ($sea > 0) )
167 $episode = sprintf( "%d . %d .", $sea-1, $epi-1 );
171 $episode = sprintf( ". %d .", $epi-1 );
174 if( $time and $title ){
176 # empty last day array
179 progress
("$time $title");
182 channel_id
=> $chd->{id
},
183 title
=> norm
($title),
185 subtitle
=> norm
($subtitle),
190 ## Episodes and so on ( Doesn't seem to work, fix this later. )
194 $dsh->AddProgramme( $ce );
213 my( $year, $day, $month );
215 # format '2011-04-13'
216 # if( $text =~ /^(\d+)\/(\d+)\/(\d+)$/i ){
217 # ( $month, $day, $year ) = ( $text =~ /^(\d+)\/(\d+)\/(\d{2})$/i );
219 # format '2011-05-16'
220 # } elsif( $text =~ /^\d{4}-\d{2}-\d{2}$/i ){
221 # ( $year, $month, $day ) = ( $text =~ /^(\d{4})-(\d{2})-(\d{2})$/i );
224 #if( $text =~ /^(\d+)-(\w)-(\d+)$/ ){
225 # ( $day, $month, $year ) = ( $text =~ /^(\d+)-(\w)-(\d+)$/ );
227 if( $text =~ /^(\d+)-Jan-(\d+)$/ ){
228 ( $day, $year ) = ( $text =~ /^(\d+)-Jan-(\d+)$/ );
230 } elsif( $text =~ /^(\d+)-Feb-(\d+)$/ ){
231 ( $day, $year ) = ( $text =~ /^(\d+)-Feb-(\d+)$/ );
233 } elsif( $text =~ /^(\d+)-Mar-(\d+)$/ ){
234 ( $day, $year ) = ( $text =~ /^(\d+)-Mar-(\d+)$/ );
236 } elsif( $text =~ /^(\d+)-Apr-(\d+)$/ ){
237 ( $day, $year ) = ( $text =~ /^(\d+)-Apr-(\d+)$/ );
239 } elsif( $text =~ /^(\d+)-May-(\d+)$/ ){
240 ( $day, $year ) = ( $text =~ /^(\d+)-May-(\d+)$/ );
242 } elsif( $text =~ /^(\d+)-Jun-(\d+)$/ ){
243 ( $day, $year ) = ( $text =~ /^(\d+)-Jun-(\d+)$/ );
245 } elsif( $text =~ /^(\d+)-Jul-(\d+)$/ ){
246 ( $day, $year ) = ( $text =~ /^(\d+)-Jul-(\d+)$/ );
248 } elsif( $text =~ /^(\d+)-Aug-(\d+)$/ ){
249 ( $day, $year ) = ( $text =~ /^(\d+)-Aug-(\d+)$/ );
256 jan 1 feb 2 mar 3 apr 4 maj 5 jun 6
257 jul 7 aug 8 sep 9 okt 10 nov 11 dec 12
262 #$month = $mon2num{ lc substr($month, 0, 3) };
264 $year += 2000 if $year < 100;
266 my $dt = DateTime
->new(
270 time_zone
=> "Europe/Stockholm"
273 $dt->set_time_zone( "UTC" );
276 return $dt->ymd("-");
277 #return $year."-".$month."-".$day;
283 #print "ParseTime: >$text<\n";
287 if( $text =~ /^\d+:\d+$/ ){
288 ( $hour , $min ) = ( $text =~ /^(\d+):(\d+)$/ );
291 return sprintf( "%02d:%02d", $hour, $min );
296 ### Setup coding system