Ticket #334: mythtv-mythlink-2.patch

File mythtv-mythlink-2.patch, 3.3 KB (added by sphery <mtdean@…>, 14 years ago)

Oops. Attached an old version of the patch before. Use this one instead.

  • contrib/mythlink.pl

     
    4141    $replacement_char = $dreplacement_char;
    4242    $space_char = $dspace_char;
    4343
    44 # Load the destination directory, if one was specified
     44# Load the destination directory and other options, if specified
    4545    GetOptions('dest|destination|path=s'    => \$dest,
    4646               'format=s'                   => \$format,
    4747               'sepchar|separator-char=s'   => \$separator_char,
     
    219219# Bad paths
    220220    die "$dest is not a directory.\n" unless (-d $dest);
    221221
     222# Prepare a database query
     223    $sh = $dbh->prepare(q{SELECT basename, DATE_FORMAT(starttime, '%Y-%m-%d-%H-%i-%S'), DATE_FORMAT(endtime, '%Y-%m-%d-%H-%i-%S'), title, subtitle, description, recgroup, category, originalairdate FROM recorded})
     224        or die "Unable to prepare query: ".$dbh->errstr."\n";
     225
     226# Create symlinks for the files on this machine
     227
     228# Query the desired info about the recordings
     229    $sh->execute or die "Could not execute ($q):  $!\n\n";
     230    $sh->bind_columns(\$basename,\$starttime,\$endtime,\$title,\$subtitle,\$description,\$recgroup,\$category,\$oad);
     231
    222232# Delete any old links
    223233    foreach my $file (<$dest/*>) {
    224234        next unless (-l $file);
    225235        unlink $file or die "Couldn't remove old symlink $file:  $!\n";
    226236    }
    227237
    228 # Prepare a database query
    229     $sh = $dbh->prepare('SELECT title, subtitle, description, recgroup, category, originalairdate FROM recorded WHERE chanid=? AND starttime=? AND endtime=?');
     238# Iterate over all the recordings
     239    while ($sh->fetchrow_arrayref) {
    230240
    231 # Create symlinks for the files on this machine
    232     foreach my $file (<$video_dir/*.nuv>) {
    233         next if ($file =~ /^ringbuf/);
    234     # Pull out the various parts that make up the filename
    235         my ($channel,
    236             $syear, $smonth, $sday, $shour, $sminute, $ssecond,
    237             $eyear, $emonth, $eday, $ehour, $eminute, $esecond) = $file =~/^$video_dir\/([a-z0-9]+)_(....)(..)(..)(..)(..)(..)_(....)(..)(..)(..)(..)(..)\.nuv$/i;
    238     # Found a bad filename?
    239         unless ($channel) {
    240             print "Unknown filename format:  $file\n";
    241             next;
    242         }
    243     # Query the desired info about this recording
    244         $sh->execute($channel, "$syear$smonth$sday$shour$sminute$ssecond", "$eyear$emonth$eday$ehour$eminute$esecond")
    245             or die "Could not execute ($q):  $!\n\n";
    246         my ($title, $subtitle, $description, $recgroup, $category, $oad) = $sh->fetchrow_array;
     241    # Verify the file exists on this host
     242        my $file = $video_dir."/".$basename;
     243        next unless (-e $file);
     244
    247245    # Format some fields we may be parsing below
    248246        # Start time
     247        my ($syear, $smonth, $sday, $shour, $sminute, $ssecond) = split(/\-/, $starttime, 6);
    249248        my $meridian = ($shour > 12) ? 'AM' : 'PM';
    250249        my $hour = ($shour > 12) ? $shour - 12 : $shour;
    251250        if ($hour < 10) {
     
    255254            $hour = 12;
    256255        }
    257256        # End time
     257        my ($eyear, $emonth, $eday, $ehour, $eminute, $esecond) = split(/\-/, $endtime, 6);
    258258        my $emeridian = ($ehour > 12) ? 'AM' : 'PM';
    259259        my $ethour = ($ehour > 12) ? $ehour - 12 : $ehour;
    260260        if ($ethour < 10) {