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
+1 -1
View File
@@ -50,7 +50,7 @@ get '/api/v1/video' => sub {
} }
return $ref; return $ref;
} };
get '/api/v1/video/:video' => sub { get '/api/v1/video/:video' => sub {
my $video = route_parameters->get("video"); my $video = route_parameters->get("video");
+1 -1
View File
@@ -13,7 +13,7 @@ plugins:
host: 'mariadb' host: 'mariadb'
port: 3306 port: 3306
username: 'videodetect' username: 'videodetect'
password: 'videodetect123' password: 'changeme_videodetect'
connection_check_threshold: 10 connection_check_threshold: 10
dbi_params: dbi_params:
RaiseError: 1 RaiseError: 1
+2 -2
View File
@@ -59,9 +59,9 @@ services:
context: ./api context: ./api
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: videodetect-api container_name: videodetect-api
restart: unless-stopped restart: no
ports: ports:
- "5001:5000" - "3000:3000"
environment: environment:
- DB_HOST=mariadb - DB_HOST=mariadb
- DB_PORT=3306 - DB_PORT=3306
+3 -1
View File
@@ -9,7 +9,9 @@ RUN apt update && apt install -y \
perl \ perl \
libdbi-perl \ libdbi-perl \
build-essential \ build-essential \
ffmpeg ffmpeg \
libstring-shellquote-perl
EXPOSE 3000 EXPOSE 3000
@@ -4,10 +4,10 @@
services: services:
scanner: scanner:
build: build:
context: ./scanner context: ./
dockerfile: Dockerfile dockerfile: Dockerfile
container_name: videodetect-scanner container_name: videodetect-scanner
restart: unless-stopped restart: no
environment: environment:
- DB_HOST=${DB_HOST} - DB_HOST=${DB_HOST}
- DB_PORT=3306 - DB_PORT=3306
@@ -15,9 +15,9 @@ services:
- DB_USER=${DB_USER} - DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD} - DB_PASSWORD=${DB_PASSWORD}
- API_HOST=${API_HOST} - API_HOST=${API_HOST}
- CONFIG_PATH=/app/config.yaml
volumes: volumes:
- nas_input:/data:ro - nas_input:/data:ro
- $PWD/scanner.pl:/app/scanner.pl:ro
networks: networks:
- videodetect_videodetect-network - videodetect_videodetect-network
Regular → Executable
+14 -6
View File
@@ -4,12 +4,16 @@ use warnings;
use DBI; use DBI;
use Digest::SHA qw(sha256_hex); use Digest::SHA qw(sha256_hex);
use JSON; use JSON;
use String::ShellQuote qw/shell_quote/;
my $db_host = $ENV{'DB_HOST'} || 'mariadb'; my $db_host = $ENV{'DB_HOST'} || 'mariadb';
my $db_name = $ENV{'DB_NAME'} || 'videodetect'; my $db_name = $ENV{'DB_NAME'} || 'videodetect';
my $db_user = $ENV{'DB_USER'} || 'videodetect'; my $db_user = $ENV{'DB_USER'} || 'videodetect';
my $db_pass = $ENV{'DB_PASSWORD'} || 'videodetect123'; 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 $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); 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) { while(my $dir = shift @dir_queue) {
opendir(my $dh, $dir) or die "Cannot open directory $dir: $!"; opendir(my $dh, $dir) or die "Cannot open directory $dir: $!";
print "$dir\n";
while (my $file = readdir($dh)) { while (my $file = readdir($dh)) {
next if ($file eq '.' || $file eq '..'); next if ($file eq '.' || $file eq '..');
my $full_path = "$dir/$file"; 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=?"); my $sth = $dbh->prepare("SELECT id,file_size FROM videos WHERE file_path=?");
$sth->execute($file_path); $sth->execute($file_path);
if(my $row = $sth->fetchrow_hashref()) { 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=?"); 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->execute($file_size, $row->{id});
$update_sth->finish(); $update_sth->finish();
create_review_task($row->{id}); create_aiscan_task($row->{id});
} }
return; # Already exists and size matches return; # Already exists and size matches
} }
@@ -82,13 +88,13 @@ sub process_file {
$sth->finish(); $sth->finish();
my $video_id = $dbh->last_insert_id(undef, undef, 'videos', undef); 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) = @_; my ($video_id) = @_;
$dbh->do("DELETE FROM tasks WHERE video_id=$video_id AND task_type='REVIEW'"); $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 (?, 'REVIEW', 'PENDING')"); my $sth = $dbh->prepare("INSERT INTO tasks (video_id, task_type, status) VALUES (?, 'AISCAN', 'PENDING')");
$sth->execute($video_id); $sth->execute($video_id);
$sth->finish(); $sth->finish();
} }
@@ -102,8 +108,10 @@ sub get_video_info {
my $hash = sha256_hex($fh); my $hash = sha256_hex($fh);
close($fh); close($fh);
# --- Run ffprobe to extract metadata --- # --- 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`; my $output = `$probe_cmd`;
return undef unless defined $output && length($output); return undef unless defined $output && length($output);