Skip to content

Commit f0d223e

Browse files
vandethohebertialmeida
authored andcommitted
Add methods returning Epub's title and Author (FolioReader#179)
1 parent b18e2cf commit f0d223e

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Source/EPUBCore/FRBook.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ open class FRBook: NSObject {
3030
return metadata.titles.first
3131
}
3232

33+
func authorName() -> String? {
34+
return metadata.creators.first?.name
35+
}
36+
3337
// MARK: - Media Overlay Metadata
3438
// http://www.idpf.org/epub/301/spec/epub-mediaoverlays.html#sec-package-metadata
3539

Source/EPUBCore/FREpubParser.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ class FREpubParser: NSObject, SSZipArchiveDelegate {
3131
}
3232
return UIImage(contentsOfFile: coverImage.fullHref)
3333
}
34+
35+
func parseTitle(_ epubPath: String) -> String? {
36+
37+
guard let book = readEpub(epubPath: epubPath, removeEpub: false), let title = book.title() else {
38+
return nil
39+
}
40+
return title
41+
}
42+
43+
func parseAuthorName(_ epubPath: String) -> String? {
44+
guard let book = readEpub(epubPath: epubPath, removeEpub: false), let authorName = book.authorName() else {
45+
return nil
46+
}
47+
return authorName
48+
}
49+
50+
51+
3452

3553
/**
3654
Unzip, delete and read an epub file.

Source/FolioReaderKit.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,16 @@ open class FolioReader: NSObject {
178178
return FREpubParser().parseCoverImage(epubPath)
179179
}
180180

181+
182+
// MARK: - Get Title
183+
open class func getTitle(_ epubPath: String) -> String? {
184+
return FREpubParser().parseTitle(epubPath)
185+
}
186+
187+
open class func getAuthorName(_ epubPath: String) -> String? {
188+
return FREpubParser().parseAuthorName(epubPath)
189+
}
190+
181191
// MARK: - Present Folio Reader
182192

183193
/**

0 commit comments

Comments
 (0)