CbzTools
Tools for working with CBZ comic book archives: reading and extracting their contents, reading and updating their embedded metadata, and converting CBR archives to CBZ.
Installation
Install the gem and add to the application's Gemfile by executing:
bundle add cbz_tools
If bundler is not being used to manage dependencies, install the gem by executing:
gem install cbz_tools
Usage
Reading a CBZ archive
CbzTools::Reader.open("path/to/comic.cbz") do |reader|
reader.image_names # => ["page_001.jpg", "page_002.jpg", ...]
reader.first_image # => "<image bytes>"
reader.comic_info # => {title: "...", page_count: "32", ...}
end
Editing ComicInfo.xml inside a CBZ
CbzTools::Reader.open("path/to/comic.cbz") do |reader|
reader.update_comic_info(title: "New Title", page_count: "32")
end
Converting CBR to CBZ
CbzTools::CbrConverter orchestrates the extract → repack → CBZ step,
but it does not ship an extractor. Pass anything responding to
call(cbr_path, destination_dir) (and that raises ExtractionError
on failure):
extractor = MyApp::UnrarExtractor.new
CbzTools::CbrConverter.convert("path/to/comic.cbr",
to: "path/to/comic.cbz",
extractor: extractor)
Reuse one extractor across many conversions with work_in: to pool
the tmpdir:
extractor = MyApp::UnrarExtractor.new
work_in = Dir.mktmpdir("batch")
converter = CbzTools::CbrConverter.new(extractor: extractor)
paths.each do |cbr|
converter.convert(cbr, to: cbr.sub(/\.cbr\z/i, ".cbz"), work_in: work_in)
end
Errors inherit from CbzTools::Error:
CbzTools::CbrConverter::ExtractionError— the extractor failed.CbzTools::CbrConverter::ArchiveError— no extractor supplied, the destination couldn't be written, oroverwrite: falseand the destination already exists.
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/dmfigueroa/cbz_tools.
License
The gem is available as open source under the terms of the MIT License.