This repository has been archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
movgoupdate.go
89 lines (80 loc) · 1.55 KB
/
movgoupdate.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package movgo
import (
"fmt"
// "io"
"log"
"os"
"path/filepath"
// "time"
// "strings"
// "github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)
// var finished bool = false
func scanFileNames() {
err := filepath.Walk(os.Getenv("MOVIEGOBS_MOVIES_PATH"), updateDirVisit)
if err != nil {
fmt.Println(err)
}
}
func updateDirVisit(pAth string, f os.FileInfo, err error) error {
log.Printf("this is path: %s", pAth)
if err != nil {
fmt.Println(err) // can't walk here,
return nil // not a file. ignore.
}
if f.IsDir() {
return nil
}
ext := filepath.Ext(pAth)
if ext == "" {
return nil //not a pic or movie
} else if ext == ".mp4" {
if !movNameInDb(pAth) {
ProcessMovs(pAth)
}
} else if ext == ".avi" {
if !movNameInDb(pAth) {
ProcessMovs(pAth)
}
} else if ext == ".mkv" {
if !movNameInDb(pAth) {
ProcessMovs(pAth)
}
} else if ext == ".m4v" {
if !movNameInDb(pAth) {
ProcessMovs(pAth)
}
}
return nil
}
func movNameInDb(fn string) (result bool) {
sess := MovDBcon()
defer sess.Close()
MTc := sess.DB("moviegobs").C("moviegobs")
b1 := bson.M{"filepath": fn}
b2 := bson.M{"_Id": 0}
var PMedia []map[string]string
err := MTc.Find(b1).Select(b2).All(&PMedia)
if err != nil {
log.Println(err)
}
num := len(PMedia)
if num != 0 {
result = true
} else {
result = false
}
return
}
// func ProcessMovs(fn string) {
// isMovNameInDB := movNameInDb(fn)
// if !isMovNameInDB {
// }
// }
// MovUpdate needs to be exported
func MovUpdate() (finished bool) {
scanFileNames()
finished = true
return
}