@@ -11,6 +11,8 @@ import (
11
11
"github.com/feedbooks/webpub-streamer/models"
12
12
)
13
13
14
+ const epub3 = "3.0"
15
+
14
16
func init () {
15
17
parserList = append (parserList , List {fileExt : "epub" , parser : EpubParser })
16
18
}
@@ -55,7 +57,9 @@ func EpubParser(filePath string, selfURL string) (models.Publication, error) {
55
57
publication .Metadata .Language = book .Opf .Metadata .Language
56
58
addIdentifier (& publication , book , epubVersion )
57
59
publication .Metadata .Right = strings .Join (book .Opf .Metadata .Rights , " " )
58
- publication .Metadata .Description = book .Opf .Metadata .Description [0 ]
60
+ if len (book .Opf .Metadata .Description ) > 0 {
61
+ publication .Metadata .Description = book .Opf .Metadata .Description [0 ]
62
+ }
59
63
60
64
if len (book .Opf .Metadata .Publisher ) > 0 {
61
65
for _ , pub := range book .Opf .Metadata .Publisher {
@@ -80,6 +84,10 @@ func EpubParser(filePath string, selfURL string) (models.Publication, error) {
80
84
}
81
85
}
82
86
87
+ if epubVersion == epub3 {
88
+ findContributorInMeta (& publication , book , epubVersion )
89
+ }
90
+
83
91
fillSpineAndResource (& publication , book )
84
92
addCoverRel (& publication , book )
85
93
@@ -141,12 +149,35 @@ func findInManifestByID(book *epub.Book, ID string) models.Link {
141
149
return models.Link {}
142
150
}
143
151
152
+ func findContributorInMeta (publication * models.Publication , book * epub.Book , epubVersion string ) {
153
+
154
+ for _ , meta := range book .Opf .Metadata .Meta {
155
+ if meta .Property == "dcterms:creator" || meta .Property == "dcterms:contributor" {
156
+ cont := epub.Author {}
157
+ cont .Data = meta .Data
158
+ cont .ID = meta .ID
159
+ addContributor (publication , book , epubVersion , cont )
160
+
161
+ }
162
+ }
163
+
164
+ }
165
+
144
166
func addContributor (publication * models.Publication , book * epub.Book , epubVersion string , cont epub.Author ) {
145
167
var contributor models.Contributor
168
+ var role string
146
169
147
170
contributor .Name = cont .Data
171
+ if epubVersion == "3.0" {
172
+ meta := findMetaByRefineAndProperty (book , cont .ID , "role" )
173
+ if meta .Property == "role" {
174
+ role = meta .Data
175
+ }
176
+ } else {
177
+ role = cont .Role
178
+ }
148
179
149
- switch contributor . Role {
180
+ switch role {
150
181
case "aut" :
151
182
publication .Metadata .Author = append (publication .Metadata .Author , contributor )
152
183
case "trl" :
@@ -170,14 +201,7 @@ func addContributor(publication *models.Publication, book *epub.Book, epubVersio
170
201
case "pbl" :
171
202
publication .Metadata .Publisher = append (publication .Metadata .Publisher , contributor )
172
203
default :
173
- if epubVersion == "3.0" {
174
- meta := findMetaByRefineAndProperty (book , cont .ID , "role" )
175
- if meta .Property == "role" {
176
- contributor .Role = meta .Data
177
- }
178
- } else {
179
- contributor .Role = cont .Role
180
- }
204
+ contributor .Role = role
181
205
publication .Metadata .Contributor = append (publication .Metadata .Contributor , contributor )
182
206
}
183
207
}
0 commit comments