From 16be0fc1027a046e1a3aa1bb8d2bbcbe662f641a Mon Sep 17 00:00:00 2001 From: Andreas Brachold Date: Sun, 2 Dec 2007 20:34:53 +0000 Subject: * contrib/update-xxv: fix typo TIMERS: On VPS assign event based vpsstarttime RECORDS: reorder inotify function --- contrib/update-xxv | 4 +-- lib/XXV/MODULES/RECORDS.pm | 77 +++++++++++++++++++++++++++++----------------- lib/XXV/MODULES/TIMERS.pm | 29 +++++++++-------- 3 files changed, 68 insertions(+), 42 deletions(-) diff --git a/contrib/update-xxv b/contrib/update-xxv index dd2d31a..9fdd01c 100755 --- a/contrib/update-xxv +++ b/contrib/update-xxv @@ -140,7 +140,7 @@ importDb() showInfo 'Restoring Data' for table in $tables ; do savFile="$exportDir/$table.sav" - if [ -e "$savfile" ]; then + if [ -e "$savFile" ]; then if ! eval mysql $mysqlParams -f -B $database -e \ "\"load data infile '$savFile' into table $table;\"" ; then showError "Can't load table '$table'" @@ -289,7 +289,7 @@ fi # backup if [ -n $backupTarget ] ; then showInfo 'Performing backup...' - mysqldump $mysqlParams $database | gzip >"$backupTarget.gz" 2>/dev/null + mysqldump $mysqlParams $database $tables | gzip >"$backupTarget.gz" 2>/dev/null if [ $? -ne 0 ] ; then showError 'Backup failed!!!' exit 1 diff --git a/lib/XXV/MODULES/RECORDS.pm b/lib/XXV/MODULES/RECORDS.pm index f911448..106e867 100644 --- a/lib/XXV/MODULES/RECORDS.pm +++ b/lib/XXV/MODULES/RECORDS.pm @@ -298,36 +298,25 @@ sub _init { return 0; } - $obj->{inotify} = new Linux::Inotify2 - or panic "Unable to create new inotify object: $!"; - - if($obj->{inotify}) { - Event->io( + my $updatefile = sprintf("%s/.update",$obj->{videodir}); + if( -r $updatefile) { + $obj->{inotify} = new Linux::Inotify2 + or panic sprintf("Unable to create new inotify object: %s",$!); + + if($obj->{inotify}) { + # Bind watch to event::io + Event->io( fd =>$obj->{inotify}->fileno, poll => 'r', - cb => sub { - $obj->{inotify}->poll - }); - $obj->{inotify}->watch($obj->{videodir}."/.update", IN_ALL_EVENTS, #IN_UPDATE - sub { - my $e = shift; - lg sprintf "inotify events for <%s>:%d received: %x\n", $e->fullname, $e->cookie, $e->mask; - if((time - $obj->{lastupdate}) > 15 - && $obj->readData()) { - $obj->{lastupdate} = time; - # Update preview images after five minutes - Event->timer( - after => 300, - cb => sub { - $_[0]->w->cancel; - if((time - $obj->{lastupdate}) >= 250 && $obj->readData()) { - $obj->{lastupdate} = time; - } - } - ); - } - } - ); + cb => sub { $obj->{inotify}->poll } + ); + # watch update file + $obj->{inotify}->watch( + $updatefile, + IN_ALL_EVENTS, + sub { my $e = shift; $obj->_notify_readData($e); } + ); + } } # Interval to read recordings and put to DB @@ -352,6 +341,38 @@ sub _init { 1; } +# ------------------ +# Callback to reread data if /video/.update changed by VDR +# trigged by file notifcation from inotify +sub _notify_readData { +# ------------------ + my $obj = shift || return error('No object defined!'); + my $e = shift; + lg sprintf "notify events for %s:%d received: %x\n", $e->fullname, $e->cookie, $e->mask; + + if((time - $obj->{lastupdate}) > 15 # Only if last update prior 15 seconds (avoid callback chill) + && $obj->readData()) { + + $obj->{lastupdate} = time; + + # Update preview images after five minutes + my $tmod = main::getModule('TIMERS'); + my $after = ($tmod->{prevminutes}) * 2; + $after = 300 if($after <= 300); + + Event->timer( + after => $after, + cb => sub { + $_[0]->w->cancel; + if((time - $obj->{lastupdate}) >= ($after - 30) + && $obj->readData()) { + $obj->{lastupdate} = time; + } + } + ); + } +} + # ------------------ sub dot1000 { # ------------------ diff --git a/lib/XXV/MODULES/TIMERS.pm b/lib/XXV/MODULES/TIMERS.pm index 8cfa91e..a4e797d 100644 --- a/lib/XXV/MODULES/TIMERS.pm +++ b/lib/XXV/MODULES/TIMERS.pm @@ -957,6 +957,7 @@ sub insert { # Search for event at EPG my $e = $obj->_getNextEpgId( { Id => $data->[0], + Status => $data->[1], ChannelID => $data->[2], File => $data->[8], NextStartTime => $data->[10], @@ -1269,7 +1270,11 @@ SELECT SQL_CACHE t.Id as Id, t.Status as Status,t.ChannelID as ChannelID, WHERE (Status & 1) AND e.eventid > 0 AND t.eventid = e.eventid - AND ((e.starttime != t.eventstarttime) OR (e.duration != t.eventduration)) + AND ( + (((t.Status & 4) = 0) AND e.starttime != t.eventstarttime) + OR ((t.Status & 4) AND e.vpstime != t.eventstarttime) + OR (e.duration != t.eventduration) + ) AND SUBSTRING_INDEX( t.File , '~', 1 ) LIKE CONCAT('%', e.title ,'%') |; my $erg = $obj->{dbh}->selectall_hashref($sql, 'Id'); @@ -1520,16 +1525,16 @@ sub _getNextEpgId { my $e; my @file = split('~', $timer->{File}); - + my $timemode = ($timer->{Status} & 4) ? 'vpstime' : 'starttime'; if(scalar @file >= 2) { # title and subtitle defined - my $sth = $obj->{dbh}->prepare(qq| - SELECT SQL_CACHE eventid,starttime,duration from EPG + my $sth = $obj->{dbh}->prepare(sprintf(qq| + SELECT SQL_CACHE eventid,%s as starttime,duration from EPG WHERE channel_id = ? - AND ((UNIX_TIMESTAMP(starttime) + (duration/2)) between ? and ? ) + AND ((UNIX_TIMESTAMP(%s) + (duration/2)) between ? and ? ) AND (title like ? or title like ? ) - ORDER BY ABS(( ? )-UNIX_TIMESTAMP(starttime)) LIMIT 1 - |); + ORDER BY ABS(( ? )-UNIX_TIMESTAMP(%s)) LIMIT 1 + |,$timemode,$timemode,$timemode)); if(!$sth->execute($timer->{ChannelID}, $timer->{NextStartTime}, $timer->{NextStopTime}, @@ -1542,14 +1547,14 @@ sub _getNextEpgId { $e = $sth->fetchrow_hashref(); } else { - my $sth = $obj->{dbh}->prepare(qq| - SELECT SQL_CACHE eventid,starttime,duration from EPG + my $sth = $obj->{dbh}->prepare(sprintf(qq| + SELECT SQL_CACHE eventid,%s as starttime,duration from EPG WHERE channel_id = ? - AND ((UNIX_TIMESTAMP(starttime) + (duration/2)) between ? and ? ) + AND ((UNIX_TIMESTAMP(%s) + (duration/2)) between ? and ? ) AND (title like ? ) - ORDER BY ABS(( ? )-UNIX_TIMESTAMP(starttime)) LIMIT 1 - |); + ORDER BY ABS(( ? )-UNIX_TIMESTAMP(%s)) LIMIT 1 + |,$timemode,$timemode,$timemode)); if(!$sth->execute($timer->{ChannelID}, $timer->{NextStartTime}, $timer->{NextStopTime}, -- cgit v1.2.3