Ticket #1582: myth.rebuilddatabase.pl.diff

File myth.rebuilddatabase.pl.diff, 2.5 KB (added by red321, 20 years ago)

Patch to correctly rename imported files

  • myth.rebuilddatabase.pl

     
    4949##    - changed all the DB calls to use parameters (avoids escape issues,
    5050##      and it looks better)
    5151
     52## 23-03-2006: (red321)
     53## Swapped the rename stage and the DB fill stage, script was adding the old basename
     54## to the database, and then renaming the file, leaving
     55## a dead link in 0.19
     56
    5257use strict;
    5358use DBI;
    5459use Getopt::Long;
     
    330335                        print "Enter description: ";
    331336                        chomp(my $tmp_description = <STDIN>);
    332337                        if ($tmp_description) {$description = $tmp_description;}
     338                       
     339## rename file to proper format
     340           
     341                        if ($starttime =~ m/$db_date_regx/) {
     342                                ($syear, $smonth, $sday, $shour, $sminute, $ssecond) =
     343                                ($1, $2, $3, $4, $5, $6);
     344                        }
    333345
     346                        if ($endtime =~ m/$db_date_regx/) {
     347                                ($eyear, $emonth, $eday, $ehour, $eminute, $esecond) =
     348                                ($1, $2, $3, $4, $5, $6);
     349                        }
     350
     351                        my $new_file = "$dir/$channel"."_$syear$smonth$sday$shour$sminute$ssecond"."_$eyear$emonth$eday$ehour$eminute$esecond.nuv";
     352                        my $basename = $new_file;
     353                        $basename =~ s/$dir\/(.*)/$1/s;
     354                        if (!$test_mode) {
     355                                                rename("$show", "$new_file");
     356                        } else {
     357                                print("Test mode: rename would have done\n");
     358                                print("  From: '$show'\n");
     359                                print("  To: '$new_file'\n");
     360                        }
     361               
     362
    334363## add records to db
    335364                        my $i = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname, basename, progstart, progend) values ((?), (?), (?), (?), (?), (?), (?), (?), (?), (?))";
    336365
     
    349378                               
    350379                        }
    351380
    352 ## rename file to proper format
    353            
    354                 if ($starttime =~ m/$db_date_regx/) {
    355                         ($syear, $smonth, $sday, $shour, $sminute, $ssecond) =
    356                                 ($1, $2, $3, $4, $5, $6);
    357                 }
    358381
    359                 if ($endtime =~ m/$db_date_regx/) {
    360                         ($eyear, $emonth, $eday, $ehour, $eminute, $esecond) =
    361                                 ($1, $2, $3, $4, $5, $6);
    362                 }
    363 
    364         my $new_file = "$dir/$channel"."_$syear$smonth$sday$shour$sminute$ssecond"."_$eyear$emonth$eday$ehour$eminute$esecond.nuv";
    365         if (!$test_mode) {
    366             rename("$show", "$new_file");
    367         } else {
    368             print("Test mode: rename would have done\n");
    369             print("  From: '$show'\n");
    370             print("  To: '$new_file'\n");
    371         }
    372 
    373382## commercial flag
    374383 
    375384        print("Building a seek table should improve FF/RW and JUMP functions when watching this video\n");