This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<package xmlns="http://www.idpf.org/2007/opf" dir="ltr" prefix="se: http://standardebooks.org/vocab/1.0" unique-identifier="uid" version="3.0" xml:lang="en-US"> | |
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/"> | |
<!--The DCMES elements--> | |
<dc:identifier id="uid">url:https://standardebooks.org/ebooks/lewis-carroll/alices-adventures-in-wonderland</dc:identifier> | |
<dc:title id="title">Alice's Adventures in Wonderland</dc:title> | |
<dc:language>en-GB</dc:language> | |
<dc:creator id="author">Lewis Carroll</dc:creator> | |
<dc:publisher id="publisher">Standard Ebooks</dc:publisher> | |
<dc:date>2015-05-12T00:01:00Z</dc:date> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<package xmlns="http://www.idpf.org/2007/opf" dir="ltr" prefix="se: http://standardebooks.org/vocab/1.0" unique-identifier="uid" version="3.0" xml:lang="en-US"> | |
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/"> | |
<!--The DCMES elements--> | |
<!--The meta elements--> | |
<!--The link elements--> | |
</metadata> | |
<manifest> | |
<!--The item elements--> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let path = document.at_xpath(xpath, namespaces: namespace)?.text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let xpath = "//ctn:rootfile[@full-path]/@full-path" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let namespace = ["ctn": "urn:oasis:names:tc:opendocument:xmlns:container"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class EPUBBook { | |
let container: ContainerDocument | |
init?(contentsOf baseURL: URL) { | |
// Find the location of container.xml | |
let containerURL = baseURL.appendingPathComponent("META-INF/container.xml") | |
// Parse the container file | |
guard let container = ContainerDocument(url: containerURL) else { return nil } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<container xmlns="urn:oasis:names:tc:opendocument:xmlns:container" version="1.0"> | |
<rootfiles> | |
<rootfile full-path="epub/content.opf" media-type="application/oebps-package+xml"/> | |
</rootfiles> | |
</container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ZIPFoundation | |
class EPUBParser { | |
static func parseFile(at sourceURL: URL) -> EPUBBook? { | |
// Get the ePub's filename | |
let filename = sourceURL.deletingPathExtension().lastPathComponent | |
// The directory to save the unzipped files | |
let destinationURL = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(filename) | |
// Get the file manager | |
let fileManager = FileManager() |
NewerOlder