forked from seihmd/openbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbook_func.go
212 lines (181 loc) · 4.22 KB
/
book_func.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package openbd
import (
"errors"
"strings"
"time"
)
// IsValidData validates book has valid data
func (b *Book) IsValidData() bool {
return b.GetISBN() != ""
}
// GetPublisher returns Publisher
func (b *Book) GetPublisher() string {
return b.Summary.Publisher
}
// GetISBN returns ISBN
func (b *Book) GetISBN() string {
return b.Summary.ISBN
}
// GetPubdateStr returns PubdateStr
func (b *Book) GetPubdateStr() string {
return b.Summary.Pubdate
}
// GetPubdate returns Pubdate
func (b *Book) GetPubdate() (d time.Time, err error) {
p := b.Summary.Pubdate
if p == "" {
err = errors.New("no pubdate")
return
}
layoutYMD := "20060102"
layoutYM := "200601"
if strings.Contains(p, "-") {
layoutYMD = "2006-01-02"
layoutYM = "2006-01"
}
d, err = time.Parse(layoutYMD, p)
if err != nil {
d, err = time.Parse(layoutYM, p)
}
return
}
// GetTitle returns Title
func (b *Book) GetTitle() string {
title := b.Onix.DescriptiveDetail.TitleDetail.TitleElement.TitleText.Content
if title == "" {
title = b.Summary.Title
}
return title
}
// GetSeries returns Series
func (b *Book) GetSeries() string {
return b.Summary.Series
}
// GetAuthor returns Author
func (b *Book) GetAuthor() string {
return b.Summary.Author
}
// GetCover returns Cover
func (b *Book) GetCover() string {
return b.Summary.Cover
}
// GetVolume returns Volume
func (b *Book) GetVolume() string {
return b.Summary.Volume
}
// GetImageLink returns ImageLink
func (b *Book) GetImageLink() (l string) {
if b.Summary.Cover != "" {
l = b.Summary.Cover
return
}
srs := b.Onix.CollateralDetail.SupportingResource
if len(srs) == 0 {
return
}
for _, sr := range srs {
if len(sr.ResourceVersion) > 0 {
l = sr.ResourceVersion[0].ResourceLink
break
}
}
return
}
// GetDescription returns Description
func (b *Book) GetDescription() string {
tcs := b.Onix.CollateralDetail.TextContent
d := ""
for _, tc := range tcs {
if tc.TextType == textTypeBrief && d == "" {
d = tc.Text
}
if tc.TextType == textTypeDescription {
d = tc.Text
}
}
return d
}
// GetTableOfContents returns TableOfContents
func (b *Book) GetTableOfContents() string {
tcs := b.Onix.CollateralDetail.TextContent
toc := ""
for _, tc := range tcs {
if tc.TextType == textTypeToc {
toc = tc.Text
}
}
return toc
}
// GetPages returns Pages
func (b *Book) GetPages() (int, error) {
extents := b.Onix.DescriptiveDetail.Extent
for _, item := range extents {
//11:Pages
if item.ExtentType == "11" {
i, err := item.ExtentValue.Int64()
return int(i), err
}
}
return 0, errors.New("no page data")
}
func (b *Book) GetPrice() (int, error) {
prices := b.Onix.ProductSupply.SupplyDetail.Price
for _, item := range prices {
if item.PriceType == "03" || item.PriceType == "01" {
i, err := item.PriceAmount.Int64()
return int(i), err
}
}
return 0, errors.New("no price data")
}
// GetDescriptions returns Descriptions
func (b *Book) GetDescriptions() (d Descriptions) {
tcs := b.Onix.CollateralDetail.TextContent
for _, item := range tcs {
if item.TextType == textTypeBrief {
d.ShortDescription = item.Text
} else if item.TextType == textTypeDescription {
d.Description = item.Text
} else if item.TextType == textJBPADescription {
d.JBPADescription = item.Text
}
}
return
}
func (b *Book) GetSubject() string {
for _, item := range b.Onix.DescriptiveDetail.Subject {
if item.SubjectSchemeIdentifier == subjectKeyword {
return item.SubjectHeadingText
}
}
return ""
}
func (b *Book) GetSubjectCode() string {
for _, item := range b.Onix.DescriptiveDetail.Subject {
if item.SubjectSchemeIdentifier == "78" {
return item.SubjectCode
}
}
return ""
}
func (b *Book) GetTitleCollationKey() string {
return b.DescriptiveDetail.TitleDetail.TitleElement.TitleText.Collationkey
}
func (b *Book) GetFormSize() string {
if b.Onix.DescriptiveDetail.ProductForm == "BA" {
return b.Onix.DescriptiveDetail.ProductFormDetail
}
if b.Onix.DescriptiveDetail.ProductForm == "BZ" {
var w, h string
for _, m := range b.Onix.DescriptiveDetail.Measure {
if m.MeasureType == "01" {
w = m.Measurement + m.MeasureUnitCode
}
if m.MeasureType == "02" {
h = m.Measurement + m.MeasureUnitCode
}
}
return w + "/" + h
}
return ""
}