diff --git a/db.sh b/db.sh new file mode 100755 index 0000000..a5e151d --- /dev/null +++ b/db.sh @@ -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 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index eca0abe..c398d2f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,7 +58,7 @@ services: context: ./api dockerfile: Dockerfile container_name: videodetect-api - restart: no + restart: unless-stopped ports: - "3000:3000" environment: diff --git a/scanner/scanner.pl b/scanner/scanner.pl index 67d98b4..a32ed9a 100755 --- a/scanner/scanner.pl +++ b/scanner/scanner.pl @@ -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(); } \ No newline at end of file