-
Notifications
You must be signed in to change notification settings - Fork 1
/
name.go
82 lines (74 loc) · 1.43 KB
/
name.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
package stream
import (
"strconv"
"time"
)
func Format_Episode(e Episode) (string, error) {
b := []byte(e.Series())
b = append(b, " - S"...)
if v, err := e.Season(); err != nil {
return "", err
} else {
b = strconv.AppendInt(b, v, 10)
}
b = append(b, " E"...)
if v, err := e.Episode(); err != nil {
return "", err
} else {
b = strconv.AppendInt(b, v, 10)
}
b = append(b, " - "...)
b = append(b, e.Title()...)
clean(b)
return string(b), nil
}
func Format_Film(f Film) (string, error) {
b := []byte(f.Title())
b = append(b, " - "...)
if v, err := f.Date(); err != nil {
return "", err
} else {
b = v.AppendFormat(b, "2006")
}
clean(b)
return string(b), nil
}
func Format_Video(v Video) string {
b := []byte(v.Author())
b = append(b, " - "...)
b = append(b, v.Title()...)
clean(b)
return string(b)
}
func clean(path []byte) {
m := map[byte]bool{
'"': true,
'*': true,
'/': true,
':': true,
'<': true,
'>': true,
'?': true,
'\\': true,
'|': true,
}
for k, v := range path {
if m[v] {
path[k] = '-'
}
}
}
type Episode interface {
Series() string
Season() (int64, error)
Episode() (int64, error)
Title() string
}
type Film interface {
Title() string
Date() (time.Time, error)
}
type Video interface {
Author() string
Title() string
}