Setbookmark

From MythTV Official Wiki
Revision as of 20:40, 21 April 2010 by Sphery (talk | contribs) (Move setbookmark from contrib)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Important.png Note: The correct title of this article is setbookmark. It appears incorrectly here due to technical restrictions.


Set a bookmark at program start if we recorded with pre-roll.

Usage

setbookmark --chanid=$CHANID% --starttime="%STARTTIMEISO%" --progstart="%PROGSTARTISO%"


The Script

Script.png setbookmark

#!/usr/bin/perl -w
# $Id: setbookmark,v 1.3 2008-06-27 22:14:22 ajlill Exp $
# Set a bookmark at progstart if we recorded with pre-roll
# Invoke as a user job like so:
# setbookmark --chanid=$CHANID% --starttime="%STARTTIMEISO%" --progstart="%PROGSTARTISO%"

use DBI;
use Getopt::Long;
use Time::Local;

my( $starttime, $progstart, $chanid, $database, $host, $user, $pass, $debug );
GetOptions( 'host=s'=>\$host, 
	    'database=s'=>\$database, 
	    'user=s'=>\$user, 
	    'pass=s'=>\$pass,
	    "starttime=s" => \$starttime,
            "progstart=s" => \$progstart,
	    "chanid=i" => \$chanid,
	    "debug!" => \$debug
            );

open( DBG, ">/tmp/setbookmark.dbg") if( $debug );

if (!$host) { $host="freevo"; }
if (!$database) { $database="mythconverg"; }
if (!$user) { $user="mythtv"; }
if (!$pass) { $pass="mythtv"; }

# TODO: look at the file and get the real fps
$fps = 30;

my $dbh = 
  DBI->connect("dbi:mysql:database=$database:host=$host","$user","$pass") or
  die "Cannot connect to database ($!)\n";

print DBG "Found progstart($progstart) for $chanid $starttime\n" if ( $debug );
if( $progstart ne $starttime ) {
  ($y,$mo,$d,$h,$m,$s) = split( /[-: T]/, $starttime);
  $st = timelocal($s,$m,$h,$d,$mo-1,$y);
  ($y,$mo,$d,$h,$m,$s) = split( /[-: T]/, $progstart);
  $pg = timelocal($s,$m,$h,$d,$mo-1,$y);
  $frames = ($pg - $st) * $fps;
  print DBG "Seconds starttime($st) progstart($pg) frames($frames)\n" if ( $debug );
} else {
  exit;
}
$sth = $dbh->prepare("insert into recordedmarkup ( chanid, starttime, mark, type ) values ( $chanid, \"$starttime\", $frames, 2 )");
$sth->execute();
$sth = $dbh->prepare("update recorded set bookmark = 1 where chanid = $chanid and starttime = \"$starttime\"");
$sth->execute();
exit 0;