require 'nokogiri'
require 'zip'
-require './author'
-require './cover'
+require 'author'
+require 'cover'
class Book
def initialize(fileName)
return false
end
+ def cover
+ return @cover
+ end
+
+ def describe
+ result = []
+
+ if nil != @title
+ result.push('<b>' + @title + '</b>')
+ else
+ result.push('<i>(Unknown title)</i>')
+ end
+ if nil != @author
+ result.push(@author.to_s())
+ end
+
+ seriesInfo = []
+ if nil != @series
+ seriesInfo.push(@series.to_s)
+ end
+ if nil != @volume
+ seriesInfo.push(@volume.to_s)
+ end
+ if seriesInfo.length > 0
+ result.push(seriesInfo.join(' '))
+ end
+
+ return result.join('<br/>')
+ end
+
def inspect
data = []
if nil != @author
protected
def scanEpub!(fileName)
+ puts 'Scanning "' + fileName.to_s + '"...'
Zip::File.open(fileName) do |zipfile|
contXml = zipfile.read('META-INF/container.xml')
contDoc = Nokogiri::XML(contXml)
--- /dev/null
+
+class Cover
+ def initialize(inputStream, path, mimeType)
+ @data = inputStream.read
+ @path = path
+ @mimeType = mimeType
+ end
+
+ def inspect
+ info = []
+ if nil != @data
+ info.push('size=' + @data.length.to_s)
+ else
+ info.push('empty')
+ end
+ if nil != @path
+ info.push('path="' + @path + '"')
+ end
+ if nil != @mimeType
+ info.push('mimeType="' + @mimeType + '"')
+ end
+ return '(Cover:' + info.join(',') + ')'
+ end
+
+ def to_s
+ return inspect
+ end
+
+ def writeImage(outputDir, baseName)
+ filename = baseName + getExt()
+ open(outputDir + '/' + filename, 'wb') do |fd|
+ fd.write(@data)
+ end
+ return filename, @mimeType
+ end
+
+ protected
+ def getExt
+ pos = @path.rindex('.')
+ if nil == pos
+ return '.img'
+ end
+ return @path.slice(pos, @path.length)
+ end
+end
+
-require './walkdir'
+require 'walkdir'
+
+outputDir = 'output'
books = []
+imageCount = 0
for arg in ARGV
w = WalkDir.new(arg)
- books.push(w.books)
+ books += (w.books)
+end
+
+if ! Dir.exist?(outputDir)
+ Dir.mkdir(outputDir)
+end
+
+open(outputDir + '/index.html', 'w') do |fd|
+ fd.puts "<html>"
+ fd.puts " <head><title>Books</title></head>"
+ fd.puts " <body>"
+ fd.puts " <table>"
+
+ for book in books
+ image = nil
+ if nil != book.cover
+ imageCount += 1
+ (path, mimeType) = book.cover.writeImage(outputDir, 'image' + imageCount.to_s)
+ image = '<img src="' + path + '"/>'
+ else
+ image = '(No cover image)'
+ end
+
+ fd.puts " <tr><td>" + image + "</td><td>" + book.describe() + "</td></tr>"
+ end
+
+ fd.puts " </table>"
+ fd.puts " </body>"
+ fd.puts "</html>"
end
-puts books
# and Mrs. Pollifax volume 6, On the China Station, is
# .../DorothyGilman/P06_On_the_China_Station.epub.
-require './book'
+require 'book'
class WalkDir
def initialize(root)