5 // Created by Heberti Almeida on 09/04/15.
6 // Extended by Kevin Jantzer on 12/30/15
7 // Copyright (c) 2015 Folio Reader. All rights reserved.
12 open class FRBook: NSObject {
13 var metadata = FRMetadata()
18 public var opfResource: FRResource!
19 public var tocResource: FRResource?
20 public var uniqueIdentifier: String?
21 public var coverImage: FRResource?
22 public var name: String?
23 public var resources = FRResources()
24 public var tableOfContents: [FRTocReference]!
25 public var flatTableOfContents: [FRTocReference]!
28 return smils.smils.count > 0
32 return metadata.titles.first
35 var authorName: String? {
36 return metadata.creators.first?.name
39 // MARK: - Media Overlay Metadata
40 // http://www.idpf.org/epub/301/spec/epub-mediaoverlays.html#sec-package-metadata
42 var duration: String? {
43 return metadata.find(byProperty: "media:duration")?.value
46 var activeClass: String {
47 guard let className = metadata.find(byProperty: "media:active-class")?.value else {
48 return "epub-media-overlay-active"
53 var playbackActiveClass: String {
54 guard let className = metadata.find(byProperty: "media:playback-active-class")?.value else {
55 return "epub-media-overlay-playing"
60 // MARK: - Media Overlay (SMIL) retrieval
63 Get Smil File from a resource (if it has a media-overlay)
65 func smilFileForResource(_ resource: FRResource?) -> FRSmilFile? {
66 guard let resource = resource, let mediaOverlay = resource.mediaOverlay else { return nil }
68 // lookup the smile resource to get info about the file
69 guard let smilResource = resources.findById(mediaOverlay) else { return nil }
71 // use the resource to get the file
72 return smils.findByHref(smilResource.href)
75 func smilFile(forHref href: String) -> FRSmilFile? {
76 return smilFileForResource(resources.findByHref(href))
79 func smilFile(forId ID: String) -> FRSmilFile? {
80 return smilFileForResource(resources.findById(ID))
83 // @NOTE: should "#" be automatically prefixed with the ID?
84 func duration(for ID: String) -> String? {
85 return metadata.find(byProperty: "media:duration", refinedBy: ID)?.value