Add scanner step to set review tasks

This commit is contained in:
Ryan Shpeherd
2026-09-14 14:42:54 -04:00
parent 4be2684830
commit 3eb5b5b08b
3 changed files with 42 additions and 4 deletions
Executable
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
docker run --rm -it mariadb:10.11 mariadb --user=videodetect --password=videodetect --host=10.0.1.7 --port=3306 videodetect
+1 -1
View File
@@ -58,7 +58,7 @@ services:
context: ./api
dockerfile: Dockerfile
container_name: videodetect-api
restart: no
restart: unless-stopped
ports:
- "3000:3000"
environment:
+39 -3
View File
@@ -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();
}
@@ -163,3 +175,27 @@ sub get_video_info {
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();
}