-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtv_show_service.go
75 lines (71 loc) · 1.92 KB
/
tv_show_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"encoding/json"
"fmt"
"github.com/tsotosa/atmm/config"
"github.com/tsotosa/atmm/gconst"
"github.com/tsotosa/atmm/model"
"go.uber.org/zap"
"io/fs"
"path/filepath"
)
func ScanForTvShowFiles(rootScanDir string, filesToHandle *[]model.TvShowEpisodeFile) error {
err := filepath.WalkDir(rootScanDir, func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() {
s := model.TvShowEpisodeFile{
FilenameOriginal: d.Name(),
AbsolutePath: fmt.Sprintf("%v", path),
}
*filesToHandle = append(*filesToHandle, s)
}
return nil
})
if err != nil {
return err
}
return nil
}
func RemoveAlreadyHandledTvShows(filesToHandle *[]model.TvShowEpisodeFile) {
var x []model.TvShowEpisodeFile
for _, file := range *filesToHandle {
y := Get([]byte(gconst.TvShowEpisodeFilesBucket), []byte(file.AbsolutePath))
//zap.S().Infof("found in db: [%s]", y)
if y == nil {
//zap.S().Infof("not found in db")
x = append(x, file)
continue
}
var s model.TvShowEpisodeFile
err := json.Unmarshal(y, &s)
if err != nil {
zap.S().Warnf("failed to unmarshall: [%s]", y)
continue
}
//zap.S().Infof("%#v", s)
if s.SuccessfulCopyFile && s.SuccessfulParseOriginal {
//zap.S().Infof("remove from slice: [%s]", y)
continue
}
if (!s.SuccessfulCopyFile || !s.SuccessfulParseOriginal) && !config.Conf.TvShowEpisodeFileRetryFailed {
//zap.S().Infof("remove from slice: [%s]", y)
continue
}
x = append(x, file)
}
*filesToHandle = x
}
func SaveTvShowEpisodeFileToDb(f model.TvShowEpisodeFile) error {
encoded, err := json.Marshal(f)
if err != nil {
zap.S().Warnf("failed to marshal show, cannot store it to db. struct is: %#v", f)
return err
//continue
}
err = Put([]byte(gconst.TvShowEpisodeFilesBucket), []byte(f.AbsolutePath), encoded)
if err != nil {
zap.S().Warnf("failed to save show, cannot store it to db. encoded is: %#v", encoded)
return err
//continue
}
return err
}