-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.go
85 lines (75 loc) · 1.31 KB
/
io.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
package main
import (
"encoding/json"
"os"
"time"
)
func GetIgnores() ([]string, error) {
b, err := os.ReadFile("db/ignores.json")
if err != nil {
return nil, err
}
var ignores []string
if len(b) != 0 {
err = json.Unmarshal(b, &ignores)
if err != nil {
return nil, err
}
}
return ignores, nil
}
func SyncIgnores(ignores []string) error {
file, err := os.Create("db/ignores.json")
if ignores == nil {
ignores = []string{}
}
if err != nil {
return err
}
b, err := json.Marshal(&ignores)
if err != nil {
return err
}
_, err = file.Write(b)
if err != nil {
return err
}
return nil
}
func TimeStamp() error {
file, err := os.Create("db/timestamp.txt")
if err != nil {
return err
}
defer file.Close()
file.Write([]byte(time.Now().String()))
return nil
}
func SavePlaylistToJSON(items []ParsedItem, total int) error {
b, err := json.MarshalIndent(items, "", " ")
if err != nil {
return err
}
file, err := os.Create("db/playlist.json")
if err != nil {
return err
}
_, err = file.Write(b)
if err != nil {
return err
}
err = file.Close()
if err != nil {
return err
}
return nil
}
func InitDirs() error {
paths := []string{"songs", "db", "logs"}
for _, path := range paths {
if _, err := os.Stat(path); os.IsNotExist(err) {
os.Mkdir(path, 0775)
}
}
return nil
}