xmltv/grab/sd_json tv_grab_sd_json,1.19,1.20
Kevin Groeneveld <[email protected]> Fri, 15 Jul 2016 01:25:45 +0000
| Newsgroups | gmane.comp.tv.xmltv.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/xmltv/xmltv/grab/sd_json
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv21167
Modified Files:
tv_grab_sd_json
Log Message:
tv_grab_sd_json: More performance improvements.
Profiling showed that date/time handling was still the top item for
execution time. By writing our own code to parse airDateTime to a unix time
instead of using DateTime epoch function the date/time handling is now
relatively insignificant.
Setting UNSAFE for XML::Writer also makes a somewhat significant
improvement.
The top usage of execution time is now XMLTV.pm and XML/Writer.pm.
Index: tv_grab_sd_json
===================================================================
RCS file: /cvsroot/xmltv/xmltv/grab/sd_json/tv_grab_sd_json,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** tv_grab_sd_json 9 Jul 2016 18:03:41 -0000 1.19
--- tv_grab_sd_json 15 Jul 2016 01:25:43 -0000 1.20
***************
*** 83,86 ****
--- 83,87 ----
'encoding' => 'utf-8',
'ENCODING' => 'utf-8',
+ 'UNSAFE' => 1,
);
***************
*** 196,216 ****
}
! my $dt_zone_utc = DateTime::TimeZone->new(name => 'UTC');
! my $dt_zone_local = DateTime::TimeZone->new(name => 'local');
! sub parse_airdate {
! my @date = ($_[0] =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/);
! local $Params::Validate::NO_VALIDATION = 1;
! return DateTime->new(
! year => $date[0],
! month => $date[1],
! day => $date[2],
! hour => $date[3],
! minute => $date[4],
! second => $date[5],
! time_zone => $dt_zone_utc,
! );
}
# SD-JSON only specifies a date for originalAirDate. Older versions of
# mythtv need full date and time even though xmltv only requires date.
--- 197,234 ----
}
! # days to add to day of month to get days since Jan 1st
! my @days_norm = ( -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333 );
! my @days_leap = ( -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 );
! sub is_leap_year {
! return (!($_[0] % 4) && (($_[0] % 100) || !($_[0] % 400)));
}
+ sub parse_airtime {
+ use integer;
+ my ($year, $month, $day, $hour, $min, $sec) = ($_[0] =~ /(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)Z/);
+
+ # determine number of days since Jan 1st of requested year
+ $month -= 1;
+ $day += is_leap_year($year) ? $days_leap[$month] : $days_norm[$month];
+
+ # add number of days (minus leap days) for years since 1970
+ $day += ($year - 1970) * 365;
+
+ # add leap days from previous years since year 0 (we already included leap
+ # day for this year), subtract number of leap days between 0 and 1970 (477)
+ $year -= 1;
+ $day += $year / 4 - $year / 100 + $year / 400 - 477;
+
+ return ($day * 86400 + $hour * 3600 + $min * 60 + $sec);
+ }
+
+ sub format_airtime {
+ my ($sec, $min, $hour, $day, $month, $year) = gmtime($_[0]);
+ return sprintf('%04d%02d%02d%02d%02d%02d +0000', $year + 1900, $month + 1, $day, $hour, $min, $sec);
+ }
+
+ my $dt_zone_local = DateTime::TimeZone->new(name => 'local');
+
# SD-JSON only specifies a date for originalAirDate. Older versions of
# mythtv need full date and time even though xmltv only requires date.
***************
*** 218,227 ****
# minimize the chance of an error causing the day to be off by one.
sub parse_original_airdate {
! my @date = ($_[0] =~ /(\d+)-(\d+)-(\d+)/);
local $Params::Validate::NO_VALIDATION = 1;
return DateTime->new(
! year => $date[0],
! month => $date[1],
! day => $date[2],
hour => 12,
time_zone => $dt_zone_local,
--- 236,245 ----
# minimize the chance of an error causing the day to be off by one.
sub parse_original_airdate {
! my ($year, $month, $day) = ($_[0] =~ /(\d+)-(\d+)-(\d+)/);
local $Params::Validate::NO_VALIDATION = 1;
return DateTime->new(
! year => $year,
! month => $month,
! day => $day,
hour => 12,
time_zone => $dt_zone_local,
***************
*** 827,832 ****
for my $schedule (values %{$cache_schedules->{$channel}}) {
for my $program (@{$schedule->{'programs'}}) {
! my $dt = parse_airdate($program->{'airDateTime'});
! my $airtime = $dt->epoch();
my $dur = int($program->{'duration'});
--- 845,849 ----
for my $schedule (values %{$cache_schedules->{$channel}}) {
for my $program (@{$schedule->{'programs'}}) {
! my $airtime = parse_airtime($program->{'airDateTime'});
my $dur = int($program->{'duration'});
***************
*** 1416,1427 ****
my ($w, $channel, $program, $details) = @_;
! my $dt = parse_airdate($program->{'airDateTime'});
! my $airtime = $dt->epoch();
my $dur = int($program->{'duration'});
if(($airtime + $dur) > $time_start && $airtime < $time_stop) {
! my $start = $dt->strftime('%Y%m%d%H%M%S %z');
! $dt->add(seconds => $dur);
! my $stop = $dt->strftime('%Y%m%d%H%M%S %z');
$w->write_programme({
--- 1433,1442 ----
my ($w, $channel, $program, $details) = @_;
! my $airtime = parse_airtime($program->{'airDateTime'});
my $dur = int($program->{'duration'});
if(($airtime + $dur) > $time_start && $airtime < $time_stop) {
! my $start = format_airtime($airtime);
! my $stop = format_airtime($airtime + $dur);
$w->write_programme({
------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev