GithubHelp home page GithubHelp logo

dancarvajc / bookbinder Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ricardohg/bookbinder

0.0 0.0 0.0 4.9 MB

A Swift ePub parser framework for iOS.

License: MIT License

Shell 0.20% Ruby 0.32% Objective-C 0.20% CSS 1.87% Swift 17.22% HTML 80.19%

bookbinder's Introduction

Bookbinder

A Swift ePub parser framework for iOS.

You can read How to Parse an ePub File for iOS to learn more.

Requirements

  • Swift 5.0+
  • iOS 10.0+
  • ARC

Basic Usage

  1. Create bookbinder instance with default configuration
    // default configuration uses `NSTemporaryDirectory` as root directory to unzip ePub file
    let bookbinder = Bookbinder()
    
  2. Parse ePub file by one line
    let ebook = bookbinder.bindBook(at: ePubFileURL)
    
  3. Ready made interface of ebook
    // cover image
    let coverImageURLs = ebook.coverImageURLs
    // toc
    let tocURL = ebook.tocURL
    // ncx
    let ncx = ebook.ncx
    // primary spine items
    let pages = ebook.pages
    // others
    let mainAuthor = ebook.opf.metadata.creators.first
    ...
    
  4. Playground in BookbinderTests
    // study `Bookbinder` from unit test
    let ebook = EPUBBook(identifier: "Alice's_Adventures_in_Wonderland", contentsOf: url)
    expect(ebook).notTo(beNil())
    expect(ebook?.identifier).to(equal("Alice's_Adventures_in_Wonderland"))
    expect(ebook?.baseURL).to(equal(url))
    expect(ebook?.resourceBaseURL).to(equal(url.appendingPathComponent("epub")))
    expect(ebook?.container).notTo(beNil())
    expect(ebook?.opf).notTo(beNil())
    expect(ebook?.uniqueID).to(equal("url:https://standardebooks.org/ebooks/lewis-carroll/alices-adventures-in-wonderland"))
    expect(ebook?.releaseID).to(equal("\(ebook?.uniqueID ?? "")@2017-03-09T17:21:15Z"))
    expect(ebook?.publicationDate).to(equal(ISO8601DateFormatter().date(from: "2015-05-12T00:01:00Z")))
    ...
    

Advanced Usage

  1. Create bookbinder instance with custom configuration
    let configuration = BookbinderConfiguration(rootURL: customRootURL)
    let bookbinder = Bookbinder(configuration: configuration)
    
  2. Subclass EPUBBook
    class CustomBook: EPUBBook {
        lazy var firstAuthors: [String] = {
            return opf.metadata.creators
        }()
        
        lazy var secondAuthors: [String] = {
            return opf.metadata.contributors
        }()
        
        ...
    }
    
    let bookbinder = Bookbinder()
    let ebook = bookbinder.bindBook(at: url, to: CustomBook.self)
    
  3. Custom OPF XPath
    import Kanna
    
    struct GuideRef {
        let title: String
        let href: String
        let type: String
        
        init(_ reference: XMLElement) {
            title = reference["title"] ?? ""
            href = reference["href"] ?? ""
            type = reference["type"] ?? ""
        }
    }
    
    class CustomBook: EPUBBook {
        // http://www.idpf.org/epub/20/spec/OPF_2.0.1_draft.htm#Section2.6
        lazy var guideRefs: [GuideRef] = {
            var refs = [GuideRef]()
            let xpath = "/opf:package/opf:guide/opf:reference"
            let references = opf.document.xpath(xpath, namespaces: XPath.opf.namespace)
            for reference in references {
                refs.append(GuideRef(reference))
            }
            return refs
        }()
        
        ...
    }
    

Installation

Please add it to your Cartfile:

github "stonezhl/Bookbinder" ~> 1.0.0

Please add it to your Podfile:

use_frameworks!
pod 'Bookbinder', '~> 1.0.0'

License

Bookbinder is released under the MIT license. See LICENSE for details.

bookbinder's People

Contributors

ricardohg avatar stonezhl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.