Changeset 355
- Timestamp:
- 12/12/06 15:03:32 (7 years ago)
- Files:
-
- 3 modified
-
postprocessors/augment_timezone (modified) (8 diffs)
-
postprocessors/augment_timezone.conf (modified) (1 diff)
-
status (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
postprocessors/augment_timezone
r349 r355 1 1 #!/usr/bin/perl -w 2 2 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" 4 5 # * to be used as a postprocessor for XMLTV data 5 6 # * can be used in conjunction with 'shepherd' XMLTV reconciler or standalone … … 11 12 # start/stop times are in 'localtime'. 12 13 # 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 16 21 # 17 22 # 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 # 19 26 # provided your unix system is configured into the correct timezone, 20 27 # this will work just fine including boundaries crossing daylight savings. 21 28 # 22 29 # 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. 24 31 25 32 use strict; 26 33 my $progname = "adjust_timezone"; 27 my $version = "0.0 1";34 my $version = "0.02"; 28 35 29 36 use XMLTV; 30 37 use POSIX qw(strftime mktime); 31 38 use Getopt::Long; 39 use DBI; 40 32 41 33 42 $| = 1; 43 my $dbh; 34 44 35 45 my $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 37 54 $opt->{debug} = 0; 38 55 … … 40 57 GetOptions( 41 58 'output=s' => \$opt->{output_file}, 59 'mysql_file=s' => \$opt->{mysql_file}, 42 60 43 61 'help' => \$opt->{help}, … … 66 84 Supported options include: 67 85 --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}) 68 87 --debug enable debugging 69 88 … … 74 93 } 75 94 76 @ARGV = ('-') if not @ARGV; 77 78 # go go go! 95 &get_database_settings; 96 &get_timeoffset_setting; 97 98 if ($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 } 79 103 80 104 my %writer_args = ( encoding => 'ISO-8859-1' ); … … 87 111 'generator-info-name' => "$progname $version"} ); 88 112 113 @ARGV = ('-') if not @ARGV; 89 114 foreach 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); 91 116 XMLTV::parsefiles_callback(undef, undef, \&channel_cb,\&programme_cb, $file); 92 117 } … … 111 136 my $prog=shift; 112 137 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 } 121 148 } 122 149 … … 171 198 return $gmt_offset; 172 199 } 173 ############################################################################## 200 201 ############################################################################## 202 203 sub 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 215 sub 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 237 sub 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 2 2 'option_ready' => '--version', 3 3 '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' 5 5 }; -
status
r348 r355 12 12 reconciler reconciler_mk2 0.16 13 13 postprocessor imdb_augment_data 0.06 14 postprocessor augment_timezone 0.02
