fix: sync issues
This commit is contained in:
@@ -87,12 +87,21 @@ func (s Store) Hashes() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exists
|
// Exists
|
||||||
func (s Store) HashExists(hash string) bool {
|
func (s Store) HashExists(hash string) (VideoInfo, bool) {
|
||||||
for _, m := range s {
|
for _, m := range s {
|
||||||
if m.Hash == hash {
|
if m.Hash == hash {
|
||||||
return true
|
return m, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return VideoInfo{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Store) Update(info VideoInfo) {
|
||||||
|
for i, m := range s {
|
||||||
|
if m.Hash == info.Hash {
|
||||||
|
s[i] = info
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,14 @@ func (d *DiscoverMedias) RunE(from, to string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "get file md5: %s", video)
|
return errors.Wrapf(err, "get file md5: %s", video)
|
||||||
}
|
}
|
||||||
|
name := filepath.Base(video)[0:strings.LastIndex(filepath.Base(video), ".")]
|
||||||
|
|
||||||
if store.HashExists(md5) {
|
if info, ok := store.HashExists(md5); ok {
|
||||||
|
info.Name = name
|
||||||
|
store.Update(info)
|
||||||
|
if err := store.Save(to); err != nil {
|
||||||
|
return errors.Wrapf(err, "save store: %s", to)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,7 +74,7 @@ func (d *DiscoverMedias) RunE(from, to string) error {
|
|||||||
return errors.Wrapf(err, "process video: %s", video)
|
return errors.Wrapf(err, "process video: %s", video)
|
||||||
}
|
}
|
||||||
info.Hash = md5
|
info.Hash = md5
|
||||||
info.Name = filepath.Base(video)
|
info.Name = name
|
||||||
|
|
||||||
store = store.Append(info)
|
store = store.Append(info)
|
||||||
d.log.Infof("store: %+v", store)
|
d.log.Infof("store: %+v", store)
|
||||||
@@ -243,7 +249,7 @@ func (d *DiscoverMedias) runCleanup(to string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
if store.HashExists(dir) {
|
if _, ok := store.HashExists(dir); ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"backend/common/media_store"
|
||||||
"backend/common/service/testx"
|
"backend/common/service/testx"
|
||||||
"backend/modules/medias"
|
"backend/modules/medias"
|
||||||
"backend/providers/postgres"
|
"backend/providers/postgres"
|
||||||
@@ -65,17 +66,24 @@ func (t *DiscoverMediasTestSuite) TestDiscoverMedias_getMediaDuration() {
|
|||||||
Convey("TestDiscoverMedias_getMediaDuration", t.T(), func() {
|
Convey("TestDiscoverMedias_getMediaDuration", t.T(), func() {
|
||||||
duration, err := t.Svc.getMediaDuration("/projects/mp-qvyun/backend/fixtures/medias/video.mp4")
|
duration, err := t.Svc.getMediaDuration("/projects/mp-qvyun/backend/fixtures/medias/video.mp4")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
t.T().Logf("Duration: %0.8f", duration)
|
t.T().Logf("Duration: %d", duration)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *DiscoverMediasTestSuite) Test_globMedias() {
|
func (t *DiscoverMediasTestSuite) Test_globMedias() {
|
||||||
Convey("Test_globMedias", t.T(), func() {
|
Convey("Test_globMedias", t.T(), func() {
|
||||||
f, err := t.Svc.globVideos("/mnt/yangpingliang/publish/processed")
|
store, err := media_store.NewStore("/projects/mp-qvyun/backend/fixtures/processed")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
for _, item := range f {
|
hash := "eed0fa530f95531f9fac2a962dfbc7ea"
|
||||||
t.T().Logf("Item: %s", item)
|
store.Update(media_store.VideoInfo{
|
||||||
}
|
Hash: hash,
|
||||||
|
Name: "video",
|
||||||
|
Duration: 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
info, ok := store.HashExists(hash)
|
||||||
|
So(ok, ShouldBeTrue)
|
||||||
|
So(info.Name, ShouldEqual, "video")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user