Created
January 29, 2017 12:11
-
-
Save smileart/3e04c151bd48fc8de7ea1fa33756da09 to your computer and use it in GitHub Desktop.
EPUB dirs re-zipping (iBooks → Nook)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'fileutils' | |
require 'shellwords' | |
dir = File.absolute_path ARGV[0] | |
results = "#{dir}/results" | |
Dir.mkdir(results) unless File.exist?(results) | |
puts "Working on: #{dir}" | |
puts "Collecting results in: #{dir}/#{results}" | |
Dir.glob("#{dir}/*.epub").each do |dir_path| | |
if File.directory?(dir_path) | |
filename = File.basename(dir_path) | |
escaped_filename = Shellwords.escape(filename) | |
FileUtils.cd(dir_path, :verbose => true) | |
puts " zip -X #{escaped_filename} mimetype" | |
system "zip -X #{escaped_filename} mimetype" | |
puts " zip -rg #{escaped_filename} META-INF -x \*.DS_Store" if File.exist? 'META-INF' | |
system "zip -rg #{escaped_filename} META-INF -x \*.DS_Store" if File.exist? 'META-INF' | |
puts " zip -rg #{escaped_filename} OEBPS -x \*.DS_Store" if File.exist? 'OEBS' | |
system "zip -rg #{escaped_filename} OEBPS -x \*.DS_Store" if File.exist? 'OEBS' | |
puts " zip -rg #{escaped_filename} . -x \*.DS_Store" | |
system "zip -rg #{escaped_filename} . -x \*.DS_Store" | |
puts " Move '#{filename}' to the '../results/#{filename}'" | |
FileUtils.mv(filename, "../results/#{filename}") | |
# Optional original dir deletion | |
# puts "rm -rf #{dir_path}" | |
# FileUtils.rm_rf(dir_path) | |
FileUtils.cd('..', :verbose => true) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment