Skip to content

Instantly share code, notes, and snippets.

@makenai
Created June 1, 2010 05:29
Show Gist options
  • Save makenai/420606 to your computer and use it in GitHub Desktop.
Save makenai/420606 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'tmpdir'
tmpdir = File.join( Dir.tmpdir, 'ipaToEpub' )
Dir.mkdir( tmpdir ) unless File.directory?( tmpdir )
if !File.directory?( tmpdir )
puts "Error - cannot create temporary directory '#{tmpdir}'!"
exit
end
Dir.glob( File.expand_path('~/Music/iTunes/iTunes\ Media/Mobile\ Applications') + '/*.ipa' ).each do |file|
if `unzip -l "#{file}"`.match(%r{(Payload/[^/]+?/book)/OEBPS})
puts "Extracting contents of #{File.basename(file)} to #{tmpdir}.."
ebookPath = $1
`unzip -o "#{file}" "#{ebookPath}/*" -d "#{tmpdir}"`
zipfileName = File.join( `pwd`.strip, File.basename( file ).gsub('ipa', 'epub') )
puts "Creating #{zipfileName}";
`(cd "#{tmpdir}/#{ebookPath}"; zip -r "#{zipfileName}" *)`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment