This commit is contained in:
parent
e47a254cad
commit
d63dfc88d7
5 changed files with 25 additions and 3 deletions
|
@ -16,6 +16,7 @@ import (
|
|||
|
||||
"git.lastassault.de/speatzle/morffix/constants"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"gopkg.in/vansante/go-ffprobe.v2"
|
||||
)
|
||||
|
||||
var videoFileExtensions = []string{".mkv", ".mp4", ".webm", ".flv", ".avi"}
|
||||
|
@ -226,8 +227,15 @@ func scanLibrary(ctx context.Context, id int) {
|
|||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
// File Does not Exist Yet
|
||||
|
||||
slog.InfoContext(ctx, "File is New", "path", fullPath)
|
||||
_, err = tx.Exec(ctx, "INSERT INTO files (library_id, path, size, status, health) VALUES ($1, $2, $3, $4, $5)", id, fPath, info.Size(), constants.FILE_STATUS_NEW, constants.FILE_HEALTH_UNKNOWN)
|
||||
slog.InfoContext(ctx, "File is New, Running FFProbe...", "path", fullPath)
|
||||
|
||||
ffprobeData, err := ffprobe.ProbeURL(ctx, fullPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ffprobe New File: %w", err)
|
||||
}
|
||||
slog.InfoContext(ctx, "ffprobe Done", "path", fullPath)
|
||||
|
||||
_, err = tx.Exec(ctx, "INSERT INTO files (library_id, path, size, status, health, ffprobe_data) VALUES ($1, $2, $3, $4, $5, $6)", id, fPath, info.Size(), constants.FILE_STATUS_NEW, constants.FILE_HEALTH_UNKNOWN, ffprobeData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Add New File to DB: %w", err)
|
||||
}
|
||||
|
@ -248,7 +256,14 @@ func scanLibrary(ctx context.Context, id int) {
|
|||
}
|
||||
} else {
|
||||
slog.InfoContext(ctx, "File Has Changed", "path", fullPath, "old_mod_time", oldModTime, "new_mod_time", newModTime, "old_size", oldSize, "new_size", info.Size())
|
||||
_, err = tx.Exec(ctx, "UPDATE files SET size = $2, status = $3, health = $4, mod_time = $5 WHERE id = $1", fileID, info.Size(), constants.FILE_STATUS_CHANGED, constants.FILE_HEALTH_UNKNOWN, newModTime)
|
||||
|
||||
ffprobeData, err := ffprobe.ProbeURL(ctx, fullPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ffprobe Changed File: %w", err)
|
||||
}
|
||||
slog.InfoContext(ctx, "ffprobe Done", "path", fullPath)
|
||||
|
||||
_, err = tx.Exec(ctx, "UPDATE files SET size = $2, status = $3, health = $4, mod_time = $5, ffprobe_data = $6 WHERE id = $1", fileID, info.Size(), constants.FILE_STATUS_CHANGED, constants.FILE_HEALTH_UNKNOWN, newModTime, ffprobeData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Updating Changed File in DB: %w", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue