package fix_GOP_COMM; use File::Copy; use DBI; # Load the nuv utilities use nuv_utils; # Make sure we have pointers to the main:: namespace for certain variables *gui = *main::gui; *dbh = *main::dbh; sub new { my $class = shift; my $self = { 'name' => '(Re)build GOP and Commercial markups', 'enabled' => 1, 'errors' => undef, 'episode' => undef, 'savepath' => '.', 'sql_file' => undef, 'doIt' => undef, @_ #allows user-specified attributes to override the defaults }; bless($self, $class); # Return return $self; } sub gather_data { my $self = shift; # Make sure the user knows what he/she is doing my $copy = 0; if($gui->query_text("\nYou have chosen to rescan GOP and commercial markups.\n" ."Are you sure?\n", 'yesno', 'Yes')) { $self->{doIt}=1; } else { $self->{doIt}=0; } } sub execute { my $self = shift; # Gather any necessary data $self->{episode} = shift; $self->gather_data; # Clear out all recordedmarkup records for this show. $q = "DELETE FROM recordedmarkup WHERE chanid=? AND starttime=?"; $sh = $dbh->prepare($q); $sh->execute($self->{episode}->{channel}, $self->{episode}->{start_time}) or die "Count not execute ($q): $!\n\n"; # This one's a bit strange: if commflagged isn't 0, mythcommflag will say something # else is flagging commercials. But: If you attempt to just update commflag, the # starttime column gets updated too (???) as if there's a trigger there or as if # I'm doing something truly daft that I just don't understand. In any case, # I'm feeding the starttime back into the record - that seems to keep things sane. $q = "UPDATE recorded SET commflagged=0,starttime=? WHERE chanid=? AND starttime=?"; $sh = $dbh->prepare($q); $sh->execute($self->{episode}->{start_time},$self->{episode}->{channel}, $self->{episode}->{start_time}) or die "Count not execute ($q): $!\n\n"; my $command = "mythcommflag --chanid ".$self->{episode}->{channel}." --starttime ".$self->{episode}->{start_time}; print "Running $command\n"; push @{$self->{children}}, fork_command($command); # Wait for child processes to finish. Which (at the moment) never happens - instead # the mythcommflag program hangs on a futex for an extremely long time (I have never # seen the futex clear - perhaps I'm too impatient?? 1 while (wait > 0); $self->{children} = undef; sleep(5); } sub cleanup { # Nothing to do here } 1; #return true