API working

This commit is contained in:
Ryan Shpeherd
2026-09-09 11:19:00 -04:00
parent ea46d418bd
commit e4e5d75336
6 changed files with 24 additions and 14 deletions
+3 -1
View File
@@ -9,7 +9,9 @@ RUN apt update && apt install -y \
perl \
libdbi-perl \
build-essential \
ffmpeg
ffmpeg \
libstring-shellquote-perl
EXPOSE 3000
+34
View File
@@ -0,0 +1,34 @@
# VideoDetect — Scanner service (standalone compose file)
# Run: docker compose -f scanner-compose.yml up -d
services:
scanner:
build:
context: ./
dockerfile: Dockerfile
container_name: videodetect-scanner
restart: no
environment:
- DB_HOST=${DB_HOST}
- DB_PORT=3306
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- API_HOST=${API_HOST}
volumes:
- nas_input:/data:ro
- $PWD/scanner.pl:/app/scanner.pl:ro
networks:
- videodetect_videodetect-network
volumes:
nas_input:
driver: local
driver_opts:
type: nfs
o: addr=10.0.0.2,ro,nfsvers=4,hard,intr
device: ":/mnt/Bulk/Homes/ryan/Prawns"
networks:
videodetect_videodetect-network:
external: true
Regular → Executable
+14 -6
View File
@@ -4,12 +4,16 @@ use warnings;
use DBI;
use Digest::SHA qw(sha256_hex);
use JSON;
use String::ShellQuote qw/shell_quote/;
my $db_host = $ENV{'DB_HOST'} || 'mariadb';
my $db_name = $ENV{'DB_NAME'} || 'videodetect';
my $db_user = $ENV{'DB_USER'} || 'videodetect';
my $db_pass = $ENV{'DB_PASSWORD'} || 'videodetect123';
$SIG{INT} = sub { die "Interrupted\n"; };
my $dbh = DBI->connect("DBI:mysql:database=$db_name;host=$db_host", $db_user, $db_pass);
my @video_extensions = qw(mp4 mkv avi mov flv wmv mpg mpeg webm);
@@ -25,6 +29,7 @@ $sth->finish();
while(my $dir = shift @dir_queue) {
opendir(my $dh, $dir) or die "Cannot open directory $dir: $!";
print "$dir\n";
while (my $file = readdir($dh)) {
next if ($file eq '.' || $file eq '..');
my $full_path = "$dir/$file";
@@ -50,6 +55,7 @@ sub process_file {
}
}
print "$file_path\n";
my $sth = $dbh->prepare("SELECT id,file_size FROM videos WHERE file_path=?");
$sth->execute($file_path);
if(my $row = $sth->fetchrow_hashref()) {
@@ -59,7 +65,7 @@ sub process_file {
my $update_sth = $dbh->prepare("UPDATE videos SET file_size=?, last_scan_time=NOW() WHERE id=?");
$update_sth->execute($file_size, $row->{id});
$update_sth->finish();
create_review_task($row->{id});
create_aiscan_task($row->{id});
}
return; # Already exists and size matches
}
@@ -82,13 +88,13 @@ sub process_file {
$sth->finish();
my $video_id = $dbh->last_insert_id(undef, undef, 'videos', undef);
create_review_task($video_id);
create_aiscan_task($video_id);
}
sub create_review_task {
sub create_aiscan_task {
my ($video_id) = @_;
$dbh->do("DELETE FROM tasks WHERE video_id=$video_id AND task_type='REVIEW'");
my $sth = $dbh->prepare("INSERT INTO tasks (video_id, task_type, status) VALUES (?, 'REVIEW', 'PENDING')");
$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);
$sth->finish();
}
@@ -102,8 +108,10 @@ sub get_video_info {
my $hash = sha256_hex($fh);
close($fh);
# --- Run ffprobe to extract metadata ---
my $probe_cmd = qq{ffprobe -v quiet -print_format json -show_format -show_streams '$file_path'};
my $probe_cmd = 'ffprobe -v quiet -print_format json -show_format -show_streams ' . shell_quote($file_path);
my $output = `$probe_cmd`;
return undef unless defined $output && length($output);