Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file. Take a look
#### Streamer

* The EPUB manifest item `id` attribute is no longer exposed in `Link.properties`.
* Removed title inference based on folder names within image and audio archives. Use the archive's filename instead.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Sources/Streamer/Parser/Audio/AudioParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final class AudioParser: PublicationParser {
await makeBuilder(
container: asset.container,
readingOrder: readingOrder,
title: asset.container.guessTitle(ignoring: ignores)
title: nil
)
}
}
Expand Down
10 changes: 1 addition & 9 deletions Sources/Streamer/Parser/Image/ImageParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public final class ImageParser: PublicationParser {
let container = SingleResourceContainer(publication: asset)
return makeBuilder(
container: container,
readingOrder: [(container.entry, asset.format)],
fallbackTitle: nil
readingOrder: [(container.entry, asset.format)]
)
}

Expand All @@ -68,14 +67,12 @@ public final class ImageParser: PublicationParser {

// Parse ComicInfo.xml metadata if present
let comicInfo = await parseComicInfo(from: asset.container, warnings: warnings)
let fallbackTitle = asset.container.guessTitle(ignoring: ignores)

return await makeReadingOrder(for: asset.container)
.flatMap { readingOrder in
makeBuilder(
container: asset.container,
readingOrder: readingOrder,
fallbackTitle: fallbackTitle,
comicInfo: comicInfo
)
}
Expand Down Expand Up @@ -131,7 +128,6 @@ public final class ImageParser: PublicationParser {
private func makeBuilder(
container: Container,
readingOrder: [(AnyURL, Format)],
fallbackTitle: String?,
comicInfo: ComicInfo? = nil
) -> Result<Publication.Builder, PublicationParseError> {
guard !readingOrder.isEmpty else {
Expand Down Expand Up @@ -175,10 +171,6 @@ public final class ImageParser: PublicationParser {
metadata.conformsTo = [.divina]
metadata.layout = .fixed

if metadata.localizedTitle == nil, let fallbackTitle = fallbackTitle {
metadata.localizedTitle = .nonlocalized(fallbackTitle)
}

// Apply center page layout for double-page spreads
if let pages = comicInfo?.pages {
for pageInfo in pages where pageInfo.doublePage == true {
Expand Down
21 changes: 0 additions & 21 deletions Sources/Streamer/Toolkit/Extensions/Container.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,4 @@ extension Container {

return .success(entries)
}

/// Guesses a publication title from a list of resource HREFs.
///
/// If the HREFs contain a single root directory, we assume it is the
/// title. This is often the case for example with CBZ files.
func guessTitle(ignoring: (AnyURL) -> Bool = { _ in false }) -> String? {
var title: String?

for url in entries {
if ignoring(url) {
continue
}
let segments = url.pathSegments
guard segments.count > 1, title == nil || title == segments.first else {
return nil
}
title = segments.first
}

return title
}
}
21 changes: 17 additions & 4 deletions TestApp/Sources/Library/LibraryService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,24 @@ final class LibraryService: Loggable {
}

let (pub, format) = try await openPublication(at: url, allowUserInteraction: false, sender: sender)
let title = pub.metadata.title ?? url.url.deletingPathExtension().lastPathComponent
let coverPath = try await importCover(of: pub)

if let file = url.fileURL {
url = try moveToDocuments(
from: file,
title: pub.metadata.title ?? file.lastPathSegment,
title: title,
format: format
)
}

return try await insertBook(at: url, publication: pub, mediaType: format.mediaType, coverPath: coverPath)
return try await insertBook(
at: url,
publication: pub,
mediaType: format.mediaType,
title: title,
coverPath: coverPath
)
}

/// Fulfills the given `url` if it's a DRM license file.
Expand Down Expand Up @@ -177,13 +184,19 @@ final class LibraryService: Loggable {
}

/// Inserts the given `book` in the bookshelf.
private func insertBook(at url: AbsoluteURL, publication: Publication, mediaType: MediaType?, coverPath: String?) async throws -> Book {
private func insertBook(
at url: AbsoluteURL,
publication: Publication,
mediaType: MediaType?,
title: String,
coverPath: String?
) async throws -> Book {
// Makes the URL relative to the Documents/ folder if possible.
let url: AnyURL = Paths.documents.relativize(url)?.anyURL ?? url.anyURL

let book = Book(
identifier: publication.metadata.identifier,
title: publication.metadata.title ?? url.lastPathSegment ?? "Untitled",
title: title,
authors: publication.metadata.authors
.map(\.name)
.joined(separator: ", "),
Expand Down
5 changes: 0 additions & 5 deletions Tests/StreamerTests/Parser/Audio/AudioParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ class AudioParserTests: XCTestCase {
XCTAssertNil(publication.linkWithRel(.cover))
}

func testComputeTitleFromArchiveRootDirectory() async throws {
let publication = try await parser.parse(asset: zabAsset, warnings: nil).get().build()
XCTAssertEqual(publication.metadata.title, "Test Audiobook")
}

func testHasNoPositions() async throws {
let publication = try await parser.parse(asset: zabAsset, warnings: nil).get().build()
let result = try await publication.positions().get()
Expand Down
5 changes: 0 additions & 5 deletions Tests/StreamerTests/Parser/Image/ImageParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ class ImageParserTests: XCTestCase {
XCTAssertEqual(publication.readingOrder.first, cover)
}

func testComputeTitleFromArchiveRootDirectory() async throws {
let publication = try await parser.parse(asset: cbzAsset, warnings: nil).get().build()
XCTAssertEqual(publication.metadata.title, "Cory Doctorow's Futuristic Tales of the Here and Now")
}

func testPositions() async throws {
let publication = try await parser.parse(asset: cbzAsset, warnings: nil).get().build()

Expand Down
53 changes: 0 additions & 53 deletions Tests/StreamerTests/Toolkit/Extensions/ContainerTests.swift

This file was deleted.

Loading