Ticket #6006: myth.rebuilddatabase.pl.2.diff

File myth.rebuilddatabase.pl.2.diff, 3.5 KB (added by kb9vqf@…, 15 years ago)
  • myth.

    old new  
    2828## ./myth.rebuilddatabase.pl
    2929
    3030## Change log:
     31## 12-14-2008 (kb9vqf@pearsoncomputing.net)
     32##  Updated script to:
     33##   Populate file size
     34##   Correctly handle start date and time
     35##   Detect recording length with mplayer
     36##   Automatically preview file with xine
    3137## 9-19-2003: (awithers@anduin.com)
    3238##  Anduin fights the urge to make code more readable (aka C like).  Battle
    3339##  of urges ends in stalemate: code was reindented but not "changed" (much).
     
    7278my $norename = 0;
    7379my $storagegroup = "Default";
    7480
     81my $filesize = 0;
     82
    7583my $date_regx = qr/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
    7684my $db_date_regx = qr/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/;
    7785my $channel_regx = qr/(\d\d\d\d)/;
     
    277285
    278286
    279287    # normal case: import file into the database
     288    $filesize = `xine ${show}`;
    280289
    281290    my ($channel, $syear, $smonth, $sday, $shour, $sminute, $ssecond,
    282291        $eyear, $emonth, $eday, $ehour, $eminute, $esecond);
     
    376385        $newtitle = GetAnswer("... title", $newtitle);
    377386        $newsubtitle = GetAnswer("... subtitle", $newsubtitle);
    378387        $newdescription = GetAnswer("Description", $newdescription);
     388        $starttime = "$syear-$smonth-$sday $shour:$sminute:$ssecond";
    379389        $starttime = GetAnswer("... start time (YYYY-MM-DD HH:MM:SS)", $starttime);
    380390        $recgroup = GetAnswer("... Recording Group", "Default");
    381391    }
     
    385395    } else {
    386396        $duration = "60";
    387397    }
     398
     399    $duration = `mplayer -identify ${show} -frames 0 2> /dev/null | grep ID_LENGTH`;
     400    $duration =~ s/ID_LENGTH=//;
     401    $duration = $duration / 60;
     402    chomp $duration;
     403
    388404    $duration = GetAnswer("... duration (in minutes)", $duration);
    389405    $endtime = time_format("yyyy-mm{on}-dd hh:mm{in}:ss", str2time($starttime) + $duration * 60);
    390406
     
    396412        $time1 =~ s/[ \-:]//g;
    397413        $mythfile = sprintf("%s_%s.%s", $channel, $time1, $ext);
    398414    }
    399 
    400     my $sql = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname, basename, progstart, progend, storagegroup, recgroup) values ((?), (?), (?), (?), (?), (?), (?), (?), (?), (?), (?), (?))";
     415    $filesize = `du -sk ${show}`;
     416    $filesize =~ s/     .*//;
     417    chomp $filesize;
     418    $filesize = "${filesize}000";
     419    my $sql = "insert into recorded (chanid, starttime, endtime, title, subtitle, description, hostname, basename, progstart, progend, storagegroup, recgroup, filesize) values ((?), (?), (?), (?), (?), (?), (?), (?), (?), (?), (?), (?), (?))";
    401420
    402421    if ($test_mode) {
    403422
    404423        $sql =~ s/\(\?\)/"%s"/g;
    405424        my $statement = sprintf($sql, $channel, $starttime, $endtime, $newtitle,
    406425                                $newsubtitle, $newdescription, $host, $mythfile,
    407                                 $starttime, $endtime, $storagegroup, $recgroup);
     426                                $starttime, $endtime, $storagegroup, $recgroup, $filesize);
    408427        print("Test mode: insert would have been been:\n");
    409428        print($statement, ";\n");
    410429
     
    413432        $sth = $dbh->prepare($sql);
    414433        $sth->execute($channel, $starttime, $endtime, $newtitle,
    415434                      $newsubtitle, $newdescription, $host, $mythfile,
    416                       $starttime, $endtime, $storagegroup, $recgroup)
     435                      $starttime, $endtime, $storagegroup, $recgroup, $filesize)
    417436            or die "Could not execute ($sql)\n";
    418437
    419438        if ($mythfile ne $showBase) {