Changeset 680

Show
Ignore:
Timestamp:
05/23/07 23:14:07 (6 years ago)
Author:
max
Message:

Added Shepherd::MythTV for interaction with MythTV database
Migrated augment_timezone postprocessor to use it

Files:
2 added
2 modified

Legend:

Unmodified
Added
Removed
  • postprocessors/augment_timezone

    r641 r680  
    3232use strict; 
    3333my $progname = "augment_timezone"; 
    34 my $version = "0.12"; 
     34my $version = "0.13"; 
    3535 
    3636use XMLTV; 
    3737use POSIX qw(strftime mktime); 
    3838use Getopt::Long; 
    39 use DBI; 
    4039use IO::File; 
     40use Shepherd::MythTV; 
    4141 
    4242$| = 1; 
    43 my $dbh; 
    4443my %stats; 
    4544 
    4645my $opt = { }; 
    4746$opt->{output_file} =   "output.xmltv"; 
    48 $opt->{mysql_file} =    "/usr/local/share/mythtv/mysql.txt". 
    49                         ":/usr/share/mythtv/mysql.txt". 
    50                         ":$ENV{HOME}/.mythtv/mysql.txt". 
    51                         ":/home/mythtv/.mythtv/mysql.txt". 
    52                         ":/root/.mythtv/mysql.txt". 
    53                         ":/etc/mythtv/mysql.txt"; 
    54  
    5547$opt->{debug} =                 0; 
    5648 
     
    8779 
    8880        if ($opt->{help} || $opt->{output_file} eq "") { 
     81                my $default_loc = &Shepherd::MythTV::standard_mysql_locations; 
    8982                print<<EOF 
    9083 
     
    9386Supported options include: 
    9487  --output={file}      Send final XMLTV output to {file} (default: $opt->{output_file}) 
    95   --mysql_file={file}  File where we look for mythtv database user/pass/dbi (default: $opt->{mysql_file}) 
     88  --mysql_file={file}  File where we look for mythtv database user/pass/dbi (default: $default_loc) 
    9689  --timeoffset={s}     Specify MythTV's setting, rather than try to look it up 
    9790                       in MythTV's database. (E.g. "Auto", "None", "+1000") 
     
    10396} 
    10497 
    105 &get_database_settings unless ($opt->{timeoffset}); 
     98unless ($opt->{timeoffset}) { 
     99        # Specify a non-standard location for mysql.txt 
     100        Shepherd::MythTV::setup($opt->{mysql_file}) if ($opt->{mysql_file}); 
     101 
     102        my $sql = "SELECT data FROM settings WHERE value LIKE 'TimeOffset'"; 
     103        ($opt->{timeoffset}) = Shepherd::MythTV::query($sql); 
     104        unless ($opt->{timeoffset}) { 
     105                print "         Won't augment any timezones!\n" . 
     106                      "         Assuming MythTV's timezone is \"None\".\n". 
     107                      "         *** If this is wrong, guide data may be in wrong timezone! ***\n\n"; 
     108        } 
     109} 
    106110 
    107111$opt->{timeoffset} = "None" if (!defined $opt->{timeoffset}); 
     
    217221} 
    218222 
    219 ############################################################################## 
    220  
    221 sub find_database_settings_file 
    222 { 
    223         foreach my $cfgfile (split(/:/,$opt->{mysql_file})) { 
    224                 return $cfgfile if ((-f $cfgfile) && (-r $cfgfile)); 
    225         } 
    226  
    227         printf "\nWARNING: Could not find MythTV mysql.txt config file\n". 
    228                "         (looked in ".$opt->{mysql_file}.")\n". 
    229                "         Assuming MythTV's timezone is \"None\".\n". 
    230                "         *** If this is wrong, guide data may be in wrong timezone! ***\n\n"; 
    231         $stats{missing_mysql_database_file}++; 
    232         return undef; 
    233 } 
    234  
    235 ############################################################################## 
    236  
    237 sub get_database_settings 
    238 { 
    239         my $cfgfile = &find_database_settings_file; 
    240         return if (!defined $cfgfile); 
    241  
    242         # 
    243         # find database settings 
    244         # 
    245  
    246         if (!(open(F,"<$cfgfile"))) { 
    247                 print "WARNING: could not read $cfgfile: $!\n". 
    248                       "Won't augment any timezones!\n"; 
    249                 $stats{mysql_database_file_unreadable}++; 
    250                 return; 
    251         } 
    252  
    253         while (<F>) { 
    254                 chop; 
    255  
    256                 if ($_ =~ /^DBHostName=(.*)$/) { 
    257                         $opt->{dbhost} = $1; 
    258                 } elsif ($_ =~ /^DBUserName=(.*)$/) { 
    259                         $opt->{dbuser} = $1; 
    260                 } elsif ($_ =~ /^DBPassword=(.*)$/) { 
    261                          $opt->{dbpass} = $1; 
    262                 } elsif ($_ =~ /^DBName=(.*)$/) { 
    263                         $opt->{dbname} = $1; 
    264                 } 
    265         } 
    266         close(F); 
    267  
    268         # 
    269         # look up the timeoffset setting 
    270         # 
    271  
    272         if (!($dbh = DBI->connect("dbi:mysql:database=".$opt->{dbname}.":host=".$opt->{dbhost},$opt->{dbuser}, $opt->{dbpass}))) { 
    273                 print "WARNING: Couldn't connect to database ".$opt->{dbname}.": $!\n". 
    274                       "         Won't augment any timezones!\n"; 
    275                 $stats{mysql_database_connect_failed}++; 
    276                 return; 
    277         } 
    278  
    279         my $q = "SELECT data FROM settings WHERE value LIKE 'TimeOffset'"; 
    280         if (!($opt->{timeoffset} = $dbh->selectrow_array($q))) { 
    281                 print "WARNING: Couldn't query database: $q: $!\n". 
    282                       "         Won't augment any timezones!\n"; 
    283                 $stats{mysql_database_query_failed}++; 
    284                 return; 
    285         } 
    286 } 
    287  
  • status

    r679 r680  
    1212postprocessor   imdb_augment_data   0.14 
    1313postprocessor   flag_aus_hdtv       0.16 
    14 postprocessor   augment_timezone    0.12 
     14postprocessor   augment_timezone    0.13 
    1515reference       channel_list        2 
    1616reference       Shepherd/Common.pm  0.9 
     17reference       Shepherd/MythTV.pm  0.1