Changeset 355

Show
Ignore:
Timestamp:
12/12/06 15:03:32 (7 years ago)
Author:
lincoln
Message:

augment_timezone is alive

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • postprocessors/augment_timezone

    r349 r355  
    11#!/usr/bin/perl -w 
    22 
    3 # Augment XMLTV start/stop times with the local timezone 
     3# Augment XMLTV start/stop times with the local timezone if MythTV's 
     4# TimeOffset setting is anything other than "None" 
    45#  * to be used as a postprocessor for XMLTV data 
    56#  * can be used in conjunction with 'shepherd' XMLTV reconciler or standalone 
     
    1112#  start/stop times are in 'localtime'. 
    1213# 
    13 #  If MythTV's "TimeOffset" setting is set to 'All', this will cause all 
    14 #  programming information to be out, because MythTV's 'All' setting 
    15 #  means data with no timezone is in GMT. 
     14#  If MythTV's "TimeOffset" setting is set to anything other than 'None', 
     15#  this can cause programming information to be out: 
     16#   - if set to 'All', all programs will be out by the difference between 
     17#     GMT and locatime ('All' means MythTV is expecting all start/stop times 
     18#     in GMT) 
     19#   - if explicitly set to GMT +/- XX then this will cause programming to 
     20#     be out whenever there is a switchover to/from daylight savings 
    1621# 
    1722#  this postprocessor addresses this by explicitly putting a timezone 
    18 #  on every programme that doesn't already have one. 
     23#  on every programme that doesn't already have one, BUT ONLY IF 
     24#  MythTV is configured to anything other than 'None'. 
     25# 
    1926#  provided your unix system is configured into the correct timezone, 
    2027#  this will work just fine including boundaries crossing daylight savings. 
    2128# 
    2229#  it means that it doesn't matter if MythTV's "TimeOffset" is set to 
    23 #  'All' or 'None', the data will be right regardless. 
     30#  'All' or 'None', or something inbetween, the data will be right regardless. 
    2431 
    2532use strict; 
    2633my $progname = "adjust_timezone"; 
    27 my $version = "0.01"; 
     34my $version = "0.02"; 
    2835 
    2936use XMLTV; 
    3037use POSIX qw(strftime mktime); 
    3138use Getopt::Long; 
     39use DBI; 
     40 
    3241 
    3342$| = 1; 
     43my $dbh; 
    3444 
    3545my $opt = { }; 
    36 $opt->{output_file} =           "output.xmltv"; 
     46$opt->{output_file} =   "output.xmltv"; 
     47$opt->{mysql_file} =    "/usr/local/share/mythtv/mysql.txt". 
     48                        ":/usr/share/mythtv/mysql.txt". 
     49                        ":$ENV{HOME}/.mythtv/mysql.txt". 
     50                        ":/home/mythtv/.mythtv/mysql.txt". 
     51                        ":/root/.mythtv/mysql.txt". 
     52                        ":/etc/mythtv/mysql.txt"; 
     53 
    3754$opt->{debug} =                 0; 
    3855 
     
    4057GetOptions( 
    4158        'output=s'              => \$opt->{output_file}, 
     59        'mysql_file=s'          => \$opt->{mysql_file}, 
    4260 
    4361        'help'                  => \$opt->{help}, 
     
    6684Supported options include: 
    6785  --output={file}      send final XMLTV output to {file} (default: $opt->{output_file}) 
     86  --mysql_file={file}  file where we look for mythtv database user/pass/dbi (default: $opt->{mysql_file}) 
    6887  --debug              enable debugging 
    6988 
     
    7493} 
    7594 
    76 @ARGV = ('-') if not @ARGV; 
    77  
    78 # go go go! 
     95&get_database_settings; 
     96&get_timeoffset_setting; 
     97 
     98if ($opt->{timeoffset} eq "None") { 
     99        print " - MythTV's TimeOffset setting is set to \"None\". No need to do anything.\n"; 
     100} else { 
     101        print " - MythTV's TimeOffset setting is set to \"%s\". Adding timezones.\n",$$opt->{timeoffset}; 
     102} 
    79103 
    80104my %writer_args = ( encoding => 'ISO-8859-1' ); 
     
    87111        'generator-info-name' => "$progname $version"} ); 
    88112 
     113@ARGV = ('-') if not @ARGV; 
    89114foreach my $file (@ARGV) { 
    90         printf "Parsing: %s", ($file eq "-" ? "(from-stdin, hit control-D to finiah)" : $file); 
     115        printf " - parsing: %s\n", ($file eq "-" ? "(from-stdin, hit control-D to finiah)" : $file); 
    91116        XMLTV::parsefiles_callback(undef, undef, \&channel_cb,\&programme_cb, $file); 
    92117} 
     
    111136        my $prog=shift; 
    112137 
    113         # if there is no timezone present in start time, put one there 
    114         if (($prog->{start} !~ /\+/) && ($prog->{start} !~ /\-/)) { 
    115                 $prog->{start} = POSIX::strftime("%Y%m%d%H%M %z",localtime(parse_xmltv_date($prog->{start}))); 
    116         } 
    117  
    118         # if there is no timezone present in stop time, put one there 
    119         if (($prog->{stop} !~ /\+/) && ($prog->{stop} !~ /\-/)) { 
    120                 $prog->{stop} = POSIX::strftime("%Y%m%d%H%M %z",localtime(parse_xmltv_date($prog->{stop}))); 
     138        if ($opt->{timeoffset} ne "None") { 
     139                # if there is no timezone present in start time, put one there 
     140                if (($prog->{start} !~ /\+/) && ($prog->{start} !~ /\-/)) { 
     141                        $prog->{start} = POSIX::strftime("%Y%m%d%H%M %z",localtime(parse_xmltv_date($prog->{start}))); 
     142                } 
     143 
     144                # if there is no timezone present in stop time, put one there 
     145                if (($prog->{stop} !~ /\+/) && ($prog->{stop} !~ /\-/)) { 
     146                        $prog->{stop} = POSIX::strftime("%Y%m%d%H%M %z",localtime(parse_xmltv_date($prog->{stop}))); 
     147                } 
    121148        } 
    122149 
     
    171198        return $gmt_offset; 
    172199} 
    173 ############################################################################## 
     200 
     201############################################################################## 
     202 
     203sub find_database_settings_file 
     204{ 
     205        foreach my $cfgfile (split(/:/,$opt->{mysql_file})) { 
     206                return $cfgfile if ((-f $cfgfile) && (-r $cfgfile)); 
     207        } 
     208 
     209        die "could not find MythTV mysql.txt config file, cannot proceed. ". 
     210            "(looked in ".$opt->{mysql_file}.")\n"; 
     211} 
     212 
     213############################################################################## 
     214 
     215sub get_database_settings 
     216{ 
     217        my $cfgfile = &find_database_settings_file; 
     218        open(F,"<$cfgfile") || die "could not read $cfgfile: $!\n"; 
     219        while (<F>) { 
     220                chop; 
     221 
     222                if ($_ =~ /^DBHostName=(.*)$/) { 
     223                        $opt->{dbhost} = $1; 
     224                } elsif ($_ =~ /^DBUserName=(.*)$/) { 
     225                        $opt->{dbuser} = $1; 
     226                } elsif ($_ =~ /^DBPassword=(.*)$/) { 
     227                         $opt->{dbpass} = $1; 
     228                } elsif ($_ =~ /^DBName=(.*)$/) { 
     229                        $opt->{dbname} = $1; 
     230                } 
     231        } 
     232        close(F); 
     233} 
     234 
     235############################################################################## 
     236 
     237sub get_timeoffset_setting 
     238{ 
     239        $dbh = DBI->connect("dbi:mysql:database=".$opt->{dbname}.":host=".$opt->{dbhost}, 
     240            $opt->{dbuser}, $opt->{dbpass}) || die "couldn't connect to database ".$opt->{dbname}.": $!\n"; 
     241 
     242        my $q = "SELECT data FROM settings WHERE value LIKE 'TimeOffset'"; 
     243        $opt->{timeoffset} = $dbh->selectrow_array($q) || die "could not execute query $q: $!\n"; 
     244} 
     245 
  • postprocessors/augment_timezone.conf

    r349 r355  
    22            'option_ready' => '--version', 
    33            'max_runtime' => '2', 
    4             'desc' => 'Augment XMLTV start/stop times with local timezone ensuring start/stop times are correct regardless of MythTV\'s TImeOffset setting' 
     4            'desc' => 'Augment XMLTV start/stop times with local timezone ensuring start/stop times are correct if MythTV\'s TImeOffset setting is set to anything other than None' 
    55          }; 
  • status

    r348 r355  
    1212reconciler      reconciler_mk2      0.16 
    1313postprocessor   imdb_augment_data   0.06 
     14postprocessor   augment_timezone    0.02