share_sub_cache_helper.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package sub_share_center
  2. import (
  3. "os"
  4. "path/filepath"
  5. "github.com/ChineseSubFinder/ChineseSubFinder/pkg"
  6. "github.com/sirupsen/logrus"
  7. )
  8. // CopySub2Cache 检测原有字幕是否存在,然后放到缓存目录中
  9. func CopySub2Cache(log *logrus.Logger, orgSubFileFPath, imdbID string, year int, lowTrust bool) (bool, string) {
  10. nowFolderDir, err := pkg.GetShareFolderByYear(year)
  11. if err != nil {
  12. log.Errorln("CheckOrgSubFileExistAndCopy2Cache.GetShareFolderByYear", err)
  13. return false, ""
  14. }
  15. if lowTrust == true {
  16. // 低可信度的字幕存储位置
  17. nowFolderDir = filepath.Join(nowFolderDir, "low_trust")
  18. }
  19. err = os.MkdirAll(filepath.Join(nowFolderDir, imdbID), os.ModePerm)
  20. if err != nil {
  21. log.Errorln("CheckOrgSubFileExistAndCopy2Cache.MkdirAll", err)
  22. return false, ""
  23. }
  24. desSubFileFPath := filepath.Join(nowFolderDir, imdbID, filepath.Base(orgSubFileFPath))
  25. err = pkg.CopyFile(orgSubFileFPath, desSubFileFPath)
  26. if err != nil {
  27. log.Errorln("CheckOrgSubFileExistAndCopy2Cache.CopyFile", err)
  28. return false, ""
  29. }
  30. return true, desSubFileFPath
  31. }
  32. // ClearExpiredFiles 情况过期的字幕文件,比如数据库中没有其的引用,那么就需要清理
  33. func ClearExpiredFiles() {
  34. }