61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
|
package models
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"strconv"
|
||
|
"velvettear/badger/internal/config"
|
||
|
"velvettear/badger/internal/tools"
|
||
|
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
// exported function(s)
|
||
|
func (track *Track) HasChanged() (bool, error) {
|
||
|
if config.ChangeDetectionChecksum() {
|
||
|
checksum, error := tools.XxHash(track.Path)
|
||
|
if error != nil {
|
||
|
return true, error
|
||
|
}
|
||
|
if track.Checksum != strconv.FormatUint(checksum, 10) {
|
||
|
return true, nil
|
||
|
}
|
||
|
}
|
||
|
if !config.ChangeDetectionModified() && config.ChangeDetectionSize() {
|
||
|
return false, nil
|
||
|
}
|
||
|
stats, error := os.Stat(track.Path)
|
||
|
if error != nil {
|
||
|
return true, error
|
||
|
}
|
||
|
if config.ChangeDetectionModified() {
|
||
|
if track.Modified != stats.ModTime().UnixMilli() {
|
||
|
return true, nil
|
||
|
}
|
||
|
}
|
||
|
if config.ChangeDetectionSize() {
|
||
|
if track.Size != stats.Size() {
|
||
|
return true, nil
|
||
|
}
|
||
|
}
|
||
|
return false, nil
|
||
|
}
|
||
|
|
||
|
// struct(s)
|
||
|
type Track struct {
|
||
|
gorm.Model
|
||
|
ID int
|
||
|
Path string
|
||
|
Title string
|
||
|
Date string
|
||
|
TrackNo string
|
||
|
DiscNo string
|
||
|
Duration string
|
||
|
Bitrate int
|
||
|
Fingerprint string
|
||
|
Checksum string
|
||
|
Modified int64
|
||
|
Size int64
|
||
|
ArtistID int
|
||
|
AlbumID int
|
||
|
}
|