From e4e5d75336abb48aa45168c38d6d0962a66236d0 Mon Sep 17 00:00:00 2001 From: Ryan Shpeherd Date: Wed, 9 Sep 2026 11:19:00 -0400 Subject: [PATCH] API working --- api/app.pl | 2 +- api/config.yml | 2 +- docker-compose.yml | 4 ++-- scanner/Dockerfile | 4 +++- .../docker-compose.yml | 6 +++--- scanner/scanner.pl | 20 +++++++++++++------ 6 files changed, 24 insertions(+), 14 deletions(-) rename scanner-compose.yml => scanner/docker-compose.yml (88%) mode change 100644 => 100755 scanner/scanner.pl diff --git a/api/app.pl b/api/app.pl index 311b72c..86ed8ab 100644 --- a/api/app.pl +++ b/api/app.pl @@ -50,7 +50,7 @@ get '/api/v1/video' => sub { } return $ref; -} +}; get '/api/v1/video/:video' => sub { my $video = route_parameters->get("video"); diff --git a/api/config.yml b/api/config.yml index 966e1c8..8b42713 100644 --- a/api/config.yml +++ b/api/config.yml @@ -13,7 +13,7 @@ plugins: host: 'mariadb' port: 3306 username: 'videodetect' - password: 'videodetect123' + password: 'changeme_videodetect' connection_check_threshold: 10 dbi_params: RaiseError: 1 diff --git a/docker-compose.yml b/docker-compose.yml index cad5136..6e03503 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -59,9 +59,9 @@ services: context: ./api dockerfile: Dockerfile container_name: videodetect-api - restart: unless-stopped + restart: no ports: - - "5001:5000" + - "3000:3000" environment: - DB_HOST=mariadb - DB_PORT=3306 diff --git a/scanner/Dockerfile b/scanner/Dockerfile index 65cc74d..9c4bbf2 100644 --- a/scanner/Dockerfile +++ b/scanner/Dockerfile @@ -9,7 +9,9 @@ RUN apt update && apt install -y \ perl \ libdbi-perl \ build-essential \ - ffmpeg + ffmpeg \ + libstring-shellquote-perl + EXPOSE 3000 diff --git a/scanner-compose.yml b/scanner/docker-compose.yml similarity index 88% rename from scanner-compose.yml rename to scanner/docker-compose.yml index cbad3a6..39ecb8e 100644 --- a/scanner-compose.yml +++ b/scanner/docker-compose.yml @@ -4,10 +4,10 @@ services: scanner: build: - context: ./scanner + context: ./ dockerfile: Dockerfile container_name: videodetect-scanner - restart: unless-stopped + restart: no environment: - DB_HOST=${DB_HOST} - DB_PORT=3306 @@ -15,9 +15,9 @@ services: - DB_USER=${DB_USER} - DB_PASSWORD=${DB_PASSWORD} - API_HOST=${API_HOST} - - CONFIG_PATH=/app/config.yaml volumes: - nas_input:/data:ro + - $PWD/scanner.pl:/app/scanner.pl:ro networks: - videodetect_videodetect-network diff --git a/scanner/scanner.pl b/scanner/scanner.pl old mode 100644 new mode 100755 index ba7c31f..3f04063 --- a/scanner/scanner.pl +++ b/scanner/scanner.pl @@ -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);