archive.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/job/main/dm2/model"
  5. "go-common/app/service/main/archive/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. "go-common/library/net/metadata"
  9. )
  10. // videoDuration return video duration cid.
  11. func (s *Service) videoDuration(c context.Context, aid, cid int64) (duration int64, err error) {
  12. var cache = true
  13. if duration, err = s.dao.DurationCache(c, cid); err != nil {
  14. log.Error("dao.Duration(cid:%d) error(%v)", cid, err)
  15. err = nil
  16. cache = false
  17. } else if duration != model.NotFound {
  18. return
  19. }
  20. arg := &archive.ArgVideo2{Aid: aid, Cid: cid, RealIP: metadata.String(c, metadata.RemoteIP)}
  21. page, err := s.arcRPC.Video3(c, arg)
  22. if err != nil {
  23. if ecode.Cause(err).Code() == ecode.NothingFound.Code() {
  24. duration = 0
  25. err = nil
  26. log.Warn("acvSvc.Video3(%v) error(duration not exist)", arg)
  27. } else {
  28. log.Error("acvSvc.Video3(%v) error(%v)", arg, err)
  29. }
  30. } else {
  31. duration = page.Duration * 1000
  32. }
  33. if cache {
  34. s.cache.Do(c, func(ctx context.Context) {
  35. s.dao.SetDurationCache(ctx, cid, duration)
  36. })
  37. }
  38. return
  39. }