-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
103 lines (92 loc) · 2.33 KB
/
types.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
94
95
96
97
98
99
100
101
102
103
package editor
import (
"math"
"strconv"
)
type Tag struct {
Title string
Artist string
Album string
Track int
Year int
Comment string
Genre string
Cover Cover
}
func (tag Tag) String() string {
return "Title: " + tag.Title + "\n" +
"Artist: " + tag.Artist + "\n" +
"Album: " + tag.Album + "\n" +
"Track: " + strconv.Itoa(tag.Track) + "\n" +
"Year: " + strconv.Itoa(tag.Year) + "\n" +
"Comment: " + tag.Comment + "\n" +
"Genre: " + tag.Genre + "\n" +
"Cover: " + tag.Cover.String()
}
func (tag Tag) Size() int {
size := len(tag.Title) +
len(tag.Artist) +
len(tag.Album) +
len(tag.Comment) +
len(tag.Genre) +
tag.Cover.Size()
if tag.Track != 0 {
size += int(math.Log10(float64(tag.Track)))
}
if tag.Year != 0 {
size += int(math.Log10(float64(tag.Year)))
}
return size
}
func (tag Tag) Empty() bool {
return len(tag.Title) == 0 &&
len(tag.Artist) == 0 &&
len(tag.Album) == 0 &&
tag.Track == 0 && tag.Year == 0 &&
len(tag.Comment) == 0 &&
len(tag.Genre) == 0 &&
tag.Cover.Empty()
}
func (tag *Tag) MergeWith(src Tag) {
if len(tag.Title) == 0 {
tag.Title = src.Title
}
if len(tag.Artist) == 0 {
tag.Artist = src.Artist
}
if len(tag.Album) == 0 {
tag.Album = src.Album
}
if tag.Track == 0 {
tag.Track = src.Track
}
if tag.Year == 0 {
tag.Year = src.Year
}
if len(tag.Comment) == 0 {
tag.Comment = src.Comment
}
if len(tag.Genre) == 0 {
tag.Genre = src.Genre
}
if tag.Cover.Empty() {
tag.Cover = src.Cover
}
}
type Cover struct {
Mime string
Type string
Description string
Data []byte
}
func (cover Cover) String() string {
return "Mime: " + cover.Mime + "\n" +
"Type: " + cover.Type + "\n" +
"Description: " + cover.Description
}
func (cover Cover) Size() int {
return len(cover.Mime) + len(cover.Type) + len(cover.Description) + len(cover.Data)
}
func (cover Cover) Empty() bool {
return cover.Size() == 0
}