-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseriesmanager.go
executable file
·93 lines (70 loc) · 2.09 KB
/
seriesmanager.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
90
91
92
93
package main
import (
"flag"
"fmt"
"path"
)
const CONFIG_FILE = ".sm-config.json"
func main() {
var createSymlinks, testRun, silent, force, moved, renameOnly bool
flag.BoolVar(&createSymlinks, "symlink", false, "Create a symlink in the original location")
flag.BoolVar(&testRun, "test", false, "Do only a test run, don't move files or create symlinks")
flag.BoolVar(&silent, "silent", false, "Silent run - do not print any output")
flag.BoolVar(&force, "force", false, "Force move - even if the target file exists (override)")
flag.BoolVar(&renameOnly, "rename", false, "Rename only - do not move")
flag.Parse()
config, err := LoadConfig(relativePath(CONFIG_FILE))
if err != nil {
fmt.Println(err)
config = CreateDefaultConfig()
config.Save(relativePath(CONFIG_FILE))
}
for _, inputPath := range config.InputPaths {
files, err := listFiles(inputPath, true)
if err != nil {
fmt.Printf("Error while loading '%s'\n", inputPath)
continue
}
files = extensionFilter(files, config.Extensions)
detector := config.seriesDetector
sedetector := config.sessionEpisodeDetector
generator := config.nameGenerator
for _, file := range files {
det, err := detector.Detect(file)
season, episode, err2 := sedetector.Detect(file)
if err == nil && err2 == nil {
if renameOnly {
generator = NewNameGenerator(path.Dir(file), generator.pad, true)
}
gen := generator.GenerateLocation(det, season, episode, getExtension(file))
if gen == file {
continue
}
exists := exists(gen)
if exists && !force {
if !silent {
fmt.Printf("Skipping %s\n%s exists\n---\n", file, gen)
}
continue
}
moved = true
if !testRun {
makePath(generator.GenerateFilepath(det, season, episode))
move(file, gen)
if createSymlinks {
createSymlink(gen, file)
}
}
if !silent {
fmt.Printf("%s\n%s\n\n", file, gen)
}
}
}
}
if testRun && !silent {
fmt.Println("Test run - no files moved or renamed")
}
if !moved && !silent {
fmt.Println("No files moved or renamed, everything's where it belongs")
}
}