feat: complte media store
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -108,7 +109,7 @@ func (d *DiscoverMedias) processVideo(video string, to string) (media_store.Vide
|
||||
if err != nil {
|
||||
return info, errors.Wrapf(err, "get media duration: %s", video)
|
||||
}
|
||||
info.Duration = uint(duration)
|
||||
info.Duration = duration
|
||||
|
||||
return info, nil
|
||||
}
|
||||
@@ -295,7 +296,7 @@ func (d *DiscoverMedias) getPrice(dir string) (uint, error) {
|
||||
}
|
||||
|
||||
// getMediaDuration get the duration of a media file
|
||||
func (d *DiscoverMedias) getMediaDuration(file string) (float64, error) {
|
||||
func (d *DiscoverMedias) getMediaDuration(file string) (int64, error) {
|
||||
// ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input_video.mp4
|
||||
args := []string{
|
||||
"-v", "error",
|
||||
@@ -315,7 +316,7 @@ func (d *DiscoverMedias) getMediaDuration(file string) (float64, error) {
|
||||
return 0, errors.Wrapf(err, "get media duration: %s", file)
|
||||
}
|
||||
|
||||
return duration, nil
|
||||
return int64(math.Floor(duration)), nil
|
||||
}
|
||||
|
||||
// getMedias get the medias in the directory
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"backend/common/media_store"
|
||||
"backend/modules/medias"
|
||||
|
||||
@@ -27,7 +29,13 @@ func (d *StoreMedias) RunE(targetPath string) error {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "new store: %s", targetPath)
|
||||
}
|
||||
_ = store
|
||||
|
||||
for _, item := range store {
|
||||
err := d.mediasSvc.Upsert(context.Background(), 1, item)
|
||||
if err != nil {
|
||||
d.log.WithError(err).Errorf("upsert media: %s - %s", item.Hash, item.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user