Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #173 from readium/2.0.0-alpha.1
Browse files Browse the repository at this point in the history
2.0.0-alpha.1
  • Loading branch information
mickael-menu authored Aug 11, 2020
2 parents 7753a9c + cbbedab commit ce1ea65
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/CODEOWNERS

This file was deleted.

4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

## [2.0.0-alpha.1]

### Added

* `ReadiumWebPubParser` to parse all Readium Web Publication profiles, including [Audiobooks](https://readium.org/webpub-manifest/extensions/audiobook.html) and [LCP for PDF](https://readium.org/lcp-specs/notes/lcp-for-pdf.html). It parses both manifests and packages.
Expand All @@ -16,4 +18,4 @@ All notable changes to this project will be documented in this file.
* [Prevent the embedded HTTP server from stopping when the device is locked](https://github.com/readium/r2-streamer-swift/pull/163), to allow background playback of audiobooks.

[unreleased]: https://github.com/readium/r2-streamer-swift/compare/master...HEAD
[x.x.x]: https://github.com/readium/r2-streamer-swift/compare/1.2.5...x.x.x
[2.0.0-alpha.1]: https://github.com/readium/r2-streamer-swift/compare/1.2.5...2.0.0-alpha.1
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#github "readium/r2-shared-swift" == 1.4.3
github "readium/r2-shared-swift" "2.0.0-alpha.1"
github "dexman/Minizip" == 1.4.0
github "cezheng/Fuzi" == 3.1.2
github "krzyzanowskim/CryptoSwift" == 1.3.1
Expand Down
1 change: 1 addition & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ github "cezheng/Fuzi" "3.1.2"
github "dexman/Minizip" "1.4.0"
github "edrlab/GCDWebServer" "3.6.2"
github "krzyzanowskim/CryptoSwift" "1.3.1"
github "readium/r2-shared-swift" "c77b663dfed7e8e0d9317c7c01daaccb878bf9fb"
8 changes: 4 additions & 4 deletions R2Streamer.podspec
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
Pod::Spec.new do |s|

s.name = "R2Streamer"
s.version = "1.2.5"
s.version = "2.0.0-alpha.1"
s.license = "BSD 3-Clause License"
s.summary = "R2 Streamer"
s.homepage = "http://readium.github.io"
s.author = { "Aferdita Muriqi" => "[email protected]" }
s.source = { :git => "https://github.com/readium/r2-streamer-swift.git", :tag => "1.2.5" }
s.source = { :git => "https://github.com/readium/r2-streamer-swift.git", :tag => "2.0.0-alpha.1" }
s.exclude_files = ["**/Info*.plist"]
s.requires_arc = true
s.resources = ['r2-streamer-swift/Resources/**']
s.source_files = "r2-streamer-swift/**/*.{m,h,swift}"
s.platform = :ios
s.ios.deployment_target = "10.0"

s.libraries = 'z'
s.libraries = 'z', 'xml2'
s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }

s.dependency 'R2Shared'
s.dependency 'Fuzi'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install R2Streamer with Carthage:
2. Update your Cartfile to include the following:

```ruby
github "readium/r2-streamer-swift" ~> 1.0.7
github "readium/r2-streamer-swift" "develop"
```

3. Run `carthage update` and
Expand Down Expand Up @@ -57,7 +57,7 @@ R2Streamer with CocoaPods:
use_frameworks!
target 'YourAppTargetName' do
pod 'R2Streamer', :git => 'https://github.com/readium/r2-streamer-swift.git', '~> 1.0.7'
pod 'R2Streamer', :git => 'https://github.com/readium/r2-streamer-swift.git', :branch => 'develop'
end
```

Expand Down
1 change: 0 additions & 1 deletion r2-streamer-swift/Parser/CBZ/CBZParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class CbzParser: PublicationParser {
format: .cbz,
positionListFactory: makePositionList(of:),
metadata: Metadata(
identifier: url.lastPathComponent,
title: url.deletingPathExtension()
.lastPathComponent
.replacingOccurrences(of: "_", with: " ")
Expand Down
22 changes: 15 additions & 7 deletions r2-streamer-swift/Parser/EPUB/EPUBMetadataParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,14 @@ final class EPUBMetadataParser: Loggable {

/// Parse and return the Epub unique identifier.
/// https://github.com/readium/architecture/blob/master/streamer/parser/metadata.md#identifier
private lazy var uniqueIdentifier: String? = metadataElement?
.firstChild(xpath:"dc:identifier[@id=/opf:package/@unique-identifier]")?
.stringValue
private lazy var uniqueIdentifier: String? =
dcElement(tag: "identifier[@id=/opf:package/@unique-identifier]")?
.stringValue

/// https://github.com/readium/architecture/blob/master/streamer/parser/metadata.md#publication-date
private lazy var publishedDate = metadataElement?
.firstChild(xpath: "dc:date[not(@opf:event) or @opf:event='publication']")?
.stringValue.dateFromISO8601
private lazy var publishedDate =
dcElement(tag: "date[not(@opf:event) or @opf:event='publication']")?
.stringValue.dateFromISO8601

/// Parse the modifiedDate (date of last modification of the EPUB).
/// https://github.com/readium/architecture/blob/master/streamer/parser/metadata.md#modification-date
Expand All @@ -210,7 +210,7 @@ final class EPUBMetadataParser: Loggable {
.first
}
let epub2Date = {
self.metadataElement?.firstChild(xpath: "dc:date[@opf:event='modification']")?
self.dcElement(tag: "date[@opf:event='modification']")?
.stringValue.dateFromISO8601
}
return epub3Date() ?? epub2Date()
Expand Down Expand Up @@ -479,4 +479,12 @@ final class EPUBMetadataParser: Loggable {
}
}

/// Returns the given `dc:` tag in the `metadata` element.
///
/// This looks under `metadata/dc-metadata` as well, to be compatible with old EPUB 2 files.
private func dcElement(tag: String) -> XMLElement? {
return metadataElement?
.firstChild(xpath:"(.|opf:dc-metadata)/dc:\(tag)")
}

}
5 changes: 3 additions & 2 deletions r2-streamer-swift/Parser/EPUB/OPFMeta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ struct OPFMetaList {
let prefixes = OPFVocabulary.prefixes(in: document)
document.definePrefix("opf", forNamespace: "http://www.idpf.org/2007/opf")
document.definePrefix("dc", forNamespace: "http://purl.org/dc/elements/1.1/")

// Parses `<meta>` and `<dc:x>` tags in order of appearance.
self.metas = document.xpath("/opf:package/opf:metadata/opf:meta|/opf:package/opf:metadata/dc:*")
let root = "/opf:package/opf:metadata"
self.metas = document.xpath("\(root)/opf:meta|\(root)/dc:*|\(root)/opf:dc-metadata/dc:*|\(root)/opf:x-metadata/opf:meta")
.compactMap { meta in
if meta.tag == "meta" {
// EPUB 3
Expand Down
11 changes: 11 additions & 0 deletions r2-streamer-swiftTests/Parser/EPUB/EPUBMetadataParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ class EPUBMetadataParserTests: XCTestCase {
))
}

/// Old EPUB 2 files sometimes contain the `dc` tags under `dc-metadata` and `x-metadata`.
/// See http://idpf.org/epub/20/spec/OPF_2.0_final_spec.html#Section2.2
func testParseUnderDCMetadataElement() throws {
let sut = try parseMetadata("dc-metadata")

XCTAssertEqual(sut.identifier, "urn:uuid:1a16ce38-82bd-4e9b-861e-773c2e787a50")
XCTAssertEqual(sut.title, "Alice's Adventures in Wonderland")
XCTAssertEqual(sut.modified, "2012-04-02T12:47:00Z".dateFromISO8601)
XCTAssertEqual(sut.authors, [Contributor(name: "Lewis Carroll")])
}

func testParseMainTitle() throws {
let sut = try parseMetadata("title-main")
XCTAssertEqual(sut.title, "Main title takes precedence")
Expand Down
25 changes: 25 additions & 0 deletions r2-streamer-swiftTests/Samples/OPF/dc-metadata.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="bookid" version="2.0">
<!--
Old EPUB 2 files sometimes contain the `dc` tags under `dc-metadata` and `x-metadata`.
See http://idpf.org/epub/20/spec/OPF_2.0_final_spec.html#Section2.2
-->
<metadata>
<dc-metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dc:title>Alice's Adventures in Wonderland</dc:title>
<dc:creator>Lewis Carroll</dc:creator>
<dc:identifier id="bookid">urn:uuid:1a16ce38-82bd-4e9b-861e-773c2e787a50</dc:identifier>
</dc-metadata>
<x-metadata>
<meta property="dcterms:modified">2012-04-02T12:47:00Z</meta>
</x-metadata>
</metadata>
<manifest>
<item id="titlepage" href="titlepage.xhtml" media-type="application/xhtml+xml" />
</manifest>
<spine>
<itemref idref="titlepage"/>
</spine>
</package>

0 comments on commit ce1ea65

Please sign in to comment.