Add scanner step to set review tasks
This commit is contained in:
+39
-3
@@ -50,6 +50,8 @@ for my $ext (sort { $ignored_extensions{$b} <=> $ignored_extensions{$a} } keys %
|
||||
print "Ignored extension $ext: $ignored_extensions{$ext} times\n";
|
||||
}
|
||||
|
||||
CreateReviewTasks();
|
||||
|
||||
sub process_file {
|
||||
my ($file_path) = @_;
|
||||
if (my ($ext)=$file_path =~ /^.+\.(\S+?)$/) {
|
||||
@@ -69,7 +71,12 @@ sub process_file {
|
||||
$update_sth->execute($file_size, $row->{id});
|
||||
$update_sth->finish();
|
||||
create_aiscan_task($row->{id});
|
||||
} else {
|
||||
my $update_sth = $dbh->prepare("UPDATE videos SET last_scan_time=NOW() WHERE id=?");
|
||||
$update_sth->execute($row->{id});
|
||||
$update_sth->finish();
|
||||
}
|
||||
|
||||
return; # Already exists and size matches
|
||||
}
|
||||
print "NEW:$file_path\n";
|
||||
@@ -97,9 +104,14 @@ sub process_file {
|
||||
|
||||
sub create_aiscan_task {
|
||||
my ($video_id) = @_;
|
||||
$dbh->do("DELETE FROM tasks WHERE video_id=$video_id AND task_type='AISCAN'");
|
||||
my $sth = $dbh->prepare("INSERT INTO tasks (video_id, task_type, status) VALUES (?, 'AISCAN', 'PENDING')");
|
||||
$sth->execute($video_id);
|
||||
create_task($video_id, 'AISCAN');
|
||||
}
|
||||
|
||||
sub create_task {
|
||||
my ($video_id, $task_type) = @_;
|
||||
$dbh->do("DELETE FROM tasks WHERE video_id=$video_id AND task_type=?", undef, $task_type);
|
||||
my $sth = $dbh->prepare("INSERT INTO tasks (video_id, task_type, status) VALUES (?, ?, 'PENDING')");
|
||||
$sth->execute($video_id, $task_type);
|
||||
$sth->finish();
|
||||
}
|
||||
|
||||
@@ -162,4 +174,28 @@ sub get_video_info {
|
||||
codec => $codec // 'unknown',
|
||||
duration => $duration,
|
||||
};
|
||||
}
|
||||
|
||||
sub CreateReviewTasks {
|
||||
my $sth = $dbh->prepare("
|
||||
SELECT *
|
||||
FROM tasks
|
||||
WHERE task_type='AISCAN'
|
||||
AND status='COMPLETED'
|
||||
AND JSON_VALUE(results, '$.verdict')=1
|
||||
AND JSON_VALUE(results, '$.reviewed') IS NULL
|
||||
");
|
||||
my $sth_update = $dbh->prepare("
|
||||
UPDATE tasks
|
||||
SET results = JSON_SET(results, '$.reviewed', 1)
|
||||
WHERE id = ?
|
||||
");
|
||||
|
||||
$sth->execute();
|
||||
while (my $row = $sth->fetchrow_hashref) {
|
||||
create_task($row->{video_id}, 'REVIEW');
|
||||
$sth_update->execute($row->{id});
|
||||
}
|
||||
$sth->finish();
|
||||
$sth_update->finish();
|
||||
}
|
||||
Reference in New Issue
Block a user