cbr2cbz 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'cbr2cbz'
4
+
5
+ Cbr2cbz::CLI.start
@@ -0,0 +1,2 @@
1
+ require 'cbr2cbz/cli'
2
+ require 'cbr2cbz/converter'
@@ -0,0 +1,27 @@
1
+ require 'optparse'
2
+
3
+ module Cbr2cbz
4
+ class CLI
5
+ def self.start
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: cbr2cbz [options] file ..."
9
+
10
+ opts.on("-k", "--keep", "Keep original file") do |k|
11
+ options[:keep] = k
12
+ end
13
+
14
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
15
+ options[:verbose] = v
16
+ end
17
+
18
+ opts.on_tail("-h", "--help", "Show this message") do
19
+ puts opts
20
+ exit
21
+ end
22
+ end.parse!
23
+
24
+ Converter.new(options).convert(ARGV)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'fileutils'
3
+ require 'zip/zip'
4
+ require 'zip/zipfilesystem'
5
+
6
+ module Cbr2cbz
7
+ class Converter
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def convert(entries = [])
13
+ entries.each do |entry|
14
+ if File.exists?(entry)
15
+ if File.directory?(entry)
16
+ convert_dir(entry)
17
+ else
18
+ convert_file(entry)
19
+ end
20
+ else
21
+ $stderr.puts "Warning -- #{arg} does not exist!"
22
+ end
23
+ end
24
+ end
25
+
26
+ def convert_dir(dirname)
27
+ puts "Processing directory #{dirname}" if @options[:verbose]
28
+ Dir.glob(dirname + '/**').each do |filename|
29
+ convert_file(filename)
30
+ end
31
+ end
32
+
33
+ def convert_file(filename)
34
+ if File.extname(filename).downcase == '.cbr'
35
+ puts "Processing file #{File.basename(filename)}" if @options[:verbose]
36
+ FileUtils.cd(File.dirname(filename)) do
37
+
38
+ filename_without_ext = File.basename(filename, '.*')
39
+ new_filename = filename_without_ext + '.cbz'
40
+
41
+ if File.exists?(new_filename)
42
+ $stderr.puts "Warning -- #{new_filename} already exists! Skipping."
43
+ else
44
+ # Unrar CBR
45
+ `unrar e "#{filename}" "#{filename_without_ext}"/`
46
+
47
+ # Create CBZ
48
+ Zip::ZipFile.open(new_filename, 'w') do |zipfile|
49
+ Dir[filename_without_ext + "/*"].each do |file|
50
+ zipfile.add(File.basename(file),file)
51
+ end
52
+ end
53
+
54
+ # Clean up
55
+ FileUtils.rm_rf(filename_without_ext)
56
+ FileUtils.rm(filename) unless @options[:keep]
57
+
58
+ puts "Created new file #{new_filename}" if @options[:verbose]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cbr2cbz
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - François Klingler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rubyzip
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ - - ! '>='
23
+ - !ruby/object:Gem::Version
24
+ version: 0.9.8
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.8
36
+ description: Utility to convert Comic Book Rar archives to Zip equivalent
37
+ email: francois@fklingler.com
38
+ executables:
39
+ - cbr2cbz
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - lib/cbr2cbz/cli.rb
44
+ - lib/cbr2cbz/converter.rb
45
+ - lib/cbr2cbz.rb
46
+ - bin/cbr2cbz
47
+ homepage: http://github.com/fklingler/cbr2cbz
48
+ licenses:
49
+ - MIT
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.23
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: CBR to CBZ converter
72
+ test_files: []