skip_scan_info.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package models
  2. import (
  3. "crypto/sha256"
  4. "fmt"
  5. "path/filepath"
  6. )
  7. type SkipScanInfo struct {
  8. /*
  9. 这里的 UID 计算方式有两种:
  10. 1. 电影,由电影的文件夹路径计算 sha256 得到,X:\电影\Three Thousand Years of Longing (2022)
  11. 2. 连续剧,由连续剧的文件夹路径计算 sha256 得到,只能具体到一集(S01E01 这里是拼接出来的不是真正的文件名)
  12. X:\连续剧\绝命毒师S01E01
  13. */
  14. UID string `gorm:"type:varchar(64);primarykey"`
  15. Skip bool `gorm:"type:bool;default:false"`
  16. }
  17. func NewSkipScanInfoByUID(uid string, skip bool) *SkipScanInfo {
  18. var skipScanInfo SkipScanInfo
  19. skipScanInfo.UID = uid
  20. skipScanInfo.Skip = skip
  21. return &skipScanInfo
  22. }
  23. func GenerateUID4Movie(movieFPath string) string {
  24. movieDirPath := filepath.Dir(movieFPath)
  25. fileUID := fmt.Sprintf("%x", sha256.Sum256([]byte(movieDirPath)))
  26. return fileUID
  27. }
  28. func GenerateUID4Series(seriesDirFPath string, season, eps int) string {
  29. mixInfo := fmt.Sprintf("%sS%02dE%02d", seriesDirFPath, season, eps)
  30. fileUID := fmt.Sprintf("%x", sha256.Sum256([]byte(mixInfo)))
  31. return fileUID
  32. }
  33. func NewSkipScanInfoByMovie(movieFPath string, skip bool) *SkipScanInfo {
  34. var skipScanInfo SkipScanInfo
  35. skipScanInfo.UID = GenerateUID4Movie(movieFPath)
  36. skipScanInfo.Skip = skip
  37. return &skipScanInfo
  38. }
  39. func NewSkipScanInfoBySeries(seriesDirFPath string, season, eps int, skip bool) *SkipScanInfo {
  40. var skipScanInfo SkipScanInfo
  41. skipScanInfo.UID = GenerateUID4Series(seriesDirFPath, season, eps)
  42. skipScanInfo.Skip = skip
  43. return &skipScanInfo
  44. }