Skip to content

Instantly share code, notes, and snippets.

@freakhill
Created June 28, 2013 07:03
Show Gist options
  • Save freakhill/5882970 to your computer and use it in GitHub Desktop.
Save freakhill/5882970 to your computer and use it in GitHub Desktop.
working on redownloading my gutenberg epub file to mobi files
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
`find "/Users/freakhill/Dropbox/アプリ/gutenberg" -name "*.epub"`.split("\n").each do |f|
File.basename(f) =~ /^(.*)\.epub$/
title = $1
if File.exists? File.join(File.dirname(f), "#{title}.mobi")
puts "skipping #{$1}"
next
end
puts "process #{$1}? (push enter)"
STDIN.readline
`curl --silent "http://www.gutenberg.org/ebooks/search/?query=#{title}" | grep -E '\"/ebooks/[[:digit:]]+'`.split("\n").each do |l|
l =~ /href="([^"]*)"/
puts "process #{$1}?"
case STDIN.readline
when /n/i # next, go to the next entry
puts "skipping to next entry for that query"
next
when /s/i # skip, go to the next book
puts "skipping to next epub book"
break
end
/href="([^"]*)"/.match(`curl --silent "http://www.gutenberg.org#{$1}" | grep -E "/send/dropbox.+kindle\.images"`) do |m|
`open "http://www.gutenberg.org#{m[1]}"`
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment