comicbox/bin/cbr2cbz

35 lines
618 B
Ruby
Executable file

#!/usr/bin/env ruby
require 'fileutils'
class UnrarError < RuntimeError ; end
class ZipError < RuntimeError ; end
where = Dir.pwd
ARGV.each do |arg|
Dir.chdir where
cbr_path = File.expand_path arg
cbz_path = cbr_path.gsub(/.cbr$/,'.cbz')
name = File.basename(arg).dup
name.gsub!(/\.cbr/i,'')
if File.exists? name then
FileUtils.rm_rf name
end
FileUtils.mkdir_p name
Dir.chdir name
system "unrar e \"#{cbr_path}\""
if not $?.success? then
raise UnrarError
end
Dir.chdir where
system "zip -r \"#{cbz_path}\" \"#{name}\""
if not $?.success? then
raise ZipError
end
FileUtils.rm_rf name
end