Skip to content

A Kotlin library for reading and writing ComicBook archives (CBZ) with ComicInfo.xml metadata.

License

Notifications You must be signed in to change notification settings

broot5/komicinfo

Repository files navigation

komicinfo

A Kotlin library for reading and writing ComicBook archives (CBZ) with ComicInfo.xml metadata.

Features

  • Read CBZ files - Parse ComicInfo.xml metadata from CBZ archives
  • Write CBZ files - Create CBZ archives with embedded ComicInfo.xml

Example

Reading a CBZ file

val result = ComicBookReader.read(File("comic.cbz"))

result
  .onSuccess { comicInfo ->
    println("Title: ${comicInfo.title}")
    println("Series: ${comicInfo.series}")
    println("Pages: ${comicInfo.pageCount}")
  }
  .onFailure { exception -> println("Failed to read: ${exception.message}") }

Writing a CBZ file

// Create metadata
val info = ComicInfo(
  title = "My Comic",
  series = "My Series",
  number = "1",
  writer = listOf("A", "B"),
  publisher = "My Publisher",
  languageISO = "en",
)

// List of image files in page order
val imageFiles = listOf(
  File("page01.jpg"),
  File("page02.jpg"),
  File("page03.jpg"),
)

// Create ComicBook
val comicBook = ComicBook.create(info, imageFiles)

// Write to CBZ
val result = ComicBookWriter.write(comicBook, File("output.cbz"))

result
  .onSuccess { file -> println("Successfully created: ${file.absolutePath}") }
  .onFailure { exception -> println("Failed to write: ${exception.message}") }

Customizing page information

val comicBook = ComicBook.create(info, imageFiles) { page, file ->
  when {
    file.name.contains("cover") -> page.copy(type = ComicPageType.FRONT_COVER)
    file.name.contains("credits") -> page.copy(bookmark = "Credits")
    else -> page
  }
}

Building from Source

# Clone the repository
git clone https://github.com/broot5/komicinfo.git
cd komicinfo

# Build the project
./gradlew build

# Generate JAR
./gradlew jar

About

A Kotlin library for reading and writing ComicBook archives (CBZ) with ComicInfo.xml metadata.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages