API working
This commit is contained in:
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