mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
feat(model): add ProbeData field and UpdateProbeData repository method
Add probe_data TEXT column to media_file for caching ffprobe results. Add UpdateProbeData to MediaFileRepository interface and implementations. Use hash:"ignore" tag so probe data doesn't affect MediaFile fingerprints.
This commit is contained in:
parent
5af03e1feb
commit
67d33558dd
@ -50,11 +50,21 @@ func upAddCodecAndUpdateTranscodings(_ context.Context, tx *sql.Tx) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Add probe_data column for caching ffprobe results.
|
||||
_, err = tx.Exec(`ALTER TABLE media_file ADD COLUMN probe_data TEXT DEFAULT NULL`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func downAddCodecAndUpdateTranscodings(_ context.Context, tx *sql.Tx) error {
|
||||
_, err := tx.Exec(`DROP INDEX IF EXISTS media_file_codec`)
|
||||
_, err := tx.Exec(`ALTER TABLE media_file DROP COLUMN probe_data`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`DROP INDEX IF EXISTS media_file_codec`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -58,6 +58,7 @@ type MediaFile struct {
|
||||
BitDepth int `structs:"bit_depth" json:"bitDepth"`
|
||||
Channels int `structs:"channels" json:"channels"`
|
||||
Codec string `structs:"codec" json:"codec"`
|
||||
ProbeData string `structs:"probe_data" json:"-" hash:"ignore"`
|
||||
Genre string `structs:"genre" json:"genre"`
|
||||
Genres Genres `structs:"-" json:"genres,omitempty"`
|
||||
SortTitle string `structs:"sort_title" json:"sortTitle,omitempty"`
|
||||
@ -440,6 +441,7 @@ type MediaFileRepository interface {
|
||||
CountBySuffix(options ...QueryOptions) (map[string]int64, error)
|
||||
Exists(id string) (bool, error)
|
||||
Put(m *MediaFile) error
|
||||
UpdateProbeData(id string, data string) error
|
||||
Get(id string) (*MediaFile, error)
|
||||
GetWithParticipants(id string) (*MediaFile, error)
|
||||
GetAll(options ...QueryOptions) (MediaFiles, error)
|
||||
|
||||
@ -163,6 +163,11 @@ func (r *mediaFileRepository) Put(m *model.MediaFile) error {
|
||||
return r.updateParticipants(m.ID, m.Participants)
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) UpdateProbeData(id string, data string) error {
|
||||
_, err := r.executeSQL(Update(r.tableName).Set("probe_data", data).Where(Eq{"id": id}))
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *mediaFileRepository) selectMediaFile(options ...model.QueryOptions) SelectBuilder {
|
||||
sql := r.newSelect(options...).Columns("media_file.*", "library.path as library_path", "library.name as library_name").
|
||||
LeftJoin("library on media_file.library_id = library.id")
|
||||
|
||||
@ -109,6 +109,17 @@ func (m *MockMediaFileRepo) Put(mf *model.MediaFile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) UpdateProbeData(id string, data string) error {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
}
|
||||
if d, ok := m.Data[id]; ok {
|
||||
d.ProbeData = data
|
||||
return nil
|
||||
}
|
||||
return model.ErrNotFound
|
||||
}
|
||||
|
||||
func (m *MockMediaFileRepo) Delete(id string) error {
|
||||
if m.Err {
|
||||
return errors.New("error")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user