Small fixes

This commit is contained in:
Ryan Shpeherd
2026-10-28 09:32:41 -04:00
parent 5e5972c31a
commit 554f20a1e2
5 changed files with 276 additions and 5 deletions
+22 -3
View File
@@ -82,8 +82,9 @@ sub process_file {
my $file_size = -s $file_path;
if ($file_size != $row->{file_size}) {
warn "File size mismatch for $file_path. Updating record.";
my $update_sth = $dbh->prepare("UPDATE videos SET file_size=?, last_scan_time=NOW() WHERE id=?");
$update_sth->execute($file_size, $row->{id});
my $info = get_video_info($file_path);
my $update_sth = $dbh->prepare("UPDATE videos SET file_size=?, last_scan_time=NOW(), resolution_w=?, resolution_h=?, codec=?, duration=?, updated_at=NOW() WHERE id=?");
$update_sth->execute($file_size, $info->{resolution_w}, $info->{resolution_h}, $info->{codec}, $info->{duration}, $row->{id});
$update_sth->finish();
create_aiscan_task($row->{id});
} else {
@@ -101,6 +102,24 @@ sub process_file {
warn "Failed to get video info for $file_path. Skipping.";
return;
}
$sth = $dbh->prepare("SELECT id,file_path FROM videos WHERE file_size=? AND file_hash=?");
$sth->execute(-s $file_path, $info->{file_hash});
while(my $row = $sth->fetchrow_hashref()) {
if(-e $row->{file_path}) {
print "Duplicate found: $file_path matches existing file $row->{file_path}\n";
} else {
print "MOVED FILE: $file_path previously existed as $row->{file_path}\n";
my $upd = $dbh->prepare("UPDATE videos SET file_path=?,last_scan_time=NOW(),updated_at=NOW() WHERE id=?");
$upd->execute($file_path, $row->{id});
$upd->finish();
$sth->finish();
return;
}
}
$sth->finish();
$sth = $dbh->prepare("INSERT INTO videos (file_path, file_size, file_hash, resolution_w, resolution_h, codec, duration, last_scan_time) VALUES (?, ?, ?, ?, ?, ?, ?, NOW())");
$sth->execute(
$file_path,
@@ -136,7 +155,7 @@ sub get_video_info {
# --- Compute SHA-256 hash of the file ---
return undef unless -f $file_path && -r $file_path;
open(my $fh, '<:raw', $file_path) or do { warn "Cannot open $file_path: $!"; return undef; };
my $hash = sha256_hex($fh);
my $hash = Digest::SHA->new(256)->addfile($fh)->hexdigest;
close($fh);