-
Notifications
You must be signed in to change notification settings - Fork 3
/
data.go
69 lines (57 loc) · 1.56 KB
/
data.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
package main
import (
"fmt"
"net/url"
"path"
"strconv"
"strings"
)
type Certification struct {
username string
password string
}
type Author struct {
Id string
Name string
}
func (a Author) String() string {
return fmt.Sprintf("Author: %s-%s", a.Id, a.Name)
}
type Illust struct {
Id string
Name string
Author
}
func (i Illust) String() string {
return fmt.Sprintf("Illust: %s-%s %s", i.Id, i.Name, i.Author.String())
}
type Image struct {
Id int
Path string
Referer string
Illust
}
func (i Image) String() string {
return fmt.Sprintf("%s Image: %s", i.Illust, i.Path)
}
func (img Image) Format(format string, isDir bool) string {
format = strings.Replace(format, "{{Illust.Id}}", img.Illust.Id, -1)
format = strings.Replace(format, "{{Illust.Name}}", img.Illust.Name, -1)
format = strings.Replace(format, "{{Author.Id}}", img.Illust.Author.Id, -1)
format = strings.Replace(format, "{{Author.Name}}", img.Illust.Author.Name, -1)
format = strings.Replace(format, "{{Image.Id}}", strconv.Itoa(img.Id), -1)
if !isDir {
u, _ := url.Parse(img.Path)
format += path.Ext(u.Path)
}
format = strings.Replace(format, "/", "/", -1)
format = strings.Replace(format, "\\", "\", -1)
format = strings.Replace(format, ":", ":", -1)
format = strings.Replace(format, "*", "*", -1)
format = strings.Replace(format, "?", "?", -1)
format = strings.Replace(format, "\"", """, -1)
format = strings.Replace(format, "<", "<", -1)
format = strings.Replace(format, ">", ">", -1)
format = strings.Replace(format, "|", "|", -1)
return format
}