API working
This commit is contained in:
+1
-1
@@ -50,7 +50,7 @@ get '/api/v1/video' => sub {
|
||||
}
|
||||
|
||||
return $ref;
|
||||
}
|
||||
};
|
||||
|
||||
get '/api/v1/video/:video' => sub {
|
||||
my $video = route_parameters->get("video");
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ plugins:
|
||||
host: 'mariadb'
|
||||
port: 3306
|
||||
username: 'videodetect'
|
||||
password: 'videodetect123'
|
||||
password: 'changeme_videodetect'
|
||||
connection_check_threshold: 10
|
||||
dbi_params:
|
||||
RaiseError: 1
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
+3
-1
@@ -9,7 +9,9 @@ RUN apt update && apt install -y \
|
||||
perl \
|
||||
libdbi-perl \
|
||||
build-essential \
|
||||
ffmpeg
|
||||
ffmpeg \
|
||||
libstring-shellquote-perl
|
||||
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Regular → Executable
+14
-6
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user