@@ -36,12 +36,12 @@ final class EPUBMetadataParser: Loggable {
36
36
37
37
let contributorsWithRoles = findContributorElements ( )
38
38
. compactMap { createContributor ( from: $0) }
39
-
39
+
40
40
let contributorsByRole = Dictionary ( grouping: contributorsWithRoles, by: \. role)
41
41
. mapValues { $0. map ( \. contributor) }
42
-
42
+
43
43
func contributorsForRole( role: String ? ) -> [ Contributor ] {
44
- return contributorsByRole [ role] ?? [ ]
44
+ contributorsByRole [ role] ?? [ ]
45
45
}
46
46
47
47
return Metadata (
@@ -422,22 +422,22 @@ final class EPUBMetadataParser: Loggable {
422
422
guard let name = localizedString ( for: element) else {
423
423
return nil
424
424
}
425
-
425
+
426
426
let knownRoles : Set = [ " aut " , " trl " , " edt " , " pbl " , " art " , " ill " , " clr " , " nrt " ]
427
-
427
+
428
428
// Look up for possible meta refines for contributor's role.
429
429
let role : String ? = element. attr ( " id " )
430
430
. map { id in metas [ " role " , refining: id] . map ( \. content) } ? . first
431
431
?? element. attr ( " role " ) // falls back to EPUB 2 role attribute
432
-
432
+
433
433
let roles = role. map { role in knownRoles. contains ( role) ? [ ] : [ role] } ?? [ ]
434
434
435
435
let contributor = Contributor (
436
436
name: name,
437
437
sortAs: element. attr ( " file-as " ) ,
438
438
roles: roles
439
439
)
440
-
440
+
441
441
let type : String ? = if element. tag == " creator " || element. attr ( " property " ) == " dcterms:creator " {
442
442
" aut "
443
443
} else if element. tag == " publisher " || element. attr ( " property " ) == " dcterms:publisher " {
@@ -449,9 +449,8 @@ final class EPUBMetadataParser: Loggable {
449
449
} else {
450
450
knownRoles. contains ( role!) ? role : nil
451
451
}
452
-
452
+
453
453
return ( role: type, contributor: contributor)
454
-
455
454
}
456
455
457
456
private lazy var readingProgression : ReadingProgression = {
@@ -490,14 +489,14 @@ final class EPUBMetadataParser: Loggable {
490
489
return metas [ " collection-type " , refining: id] . first? . content == " series "
491
490
}
492
491
. compactMap ( collection ( from: ) )
493
-
492
+
494
493
if !epub3Series. isEmpty {
495
494
return epub3Series
496
495
}
497
-
496
+
498
497
let epub2Position = metas [ " series_index " , in: . calibre] . first
499
498
. flatMap { Double ( $0. content) }
500
-
499
+
501
500
return metas [ " series " , in: . calibre]
502
501
. map { meta in
503
502
Metadata . Collection (
0 commit comments