@volume = nil
end
- def loadFromFile(fileName)
+ def load_from_file(fileName)
@path = fileName
- parseFileName!(fileName)
+ parse_file_name!(fileName)
end
- def self.canHandle?(fileName)
+ def self.can_handle?(fileName)
if nil == fileName
return false
end
return true
end
+ if lowerName.end_with?(".pdf")
+ return true
+ end
+
return false
end
end
protected
- def parseFileName!(fileName)
- parts = fileName.split('/')
+ def parse_file_name!(file_name)
+ parts = file_name.split('/')
(series_code, @volume, @title) = processTitle(parts[-1])
if parts.length > 1
grouping = parts[-2]
@series_id = @store.get_series(grouping, series_code)
end
- if fileName.downcase.end_with?(".epub")
- scanEpub!(fileName)
+ lc_file_name = file_name.downcase
+ if lc_file_name.end_with?(".epub")
+ scanEpub!(file_name)
+ elsif lc_file_name.end_with?(".pdf")
+ scan_pdf!(file_name)
end
end
end
end
+ protected
+ def scan_pdf!(file_name)
+ #puts 'Scanning "' + file_name.to_s + '"...'
+
+ pdf_path = File.expand_path(file_name).to_s
+ if ! pdf_path.end_with?('.pdf')
+ puts 'Unexpected internal error: path "' + file_name.to_s + '" does not end with ".pdf".'
+ return
+ end
+
+ jpeg_path = pdf_path[0..-5] + '.jpeg'
+ if File.file?(jpeg_path)
+ File.open(jpeg_path, 'r') do |is|
+ @cover = Cover.new(is, jpeg_path, 'image/jpeg')
+ end
+ end
+ end
+
+
protected
def scanOpf!(zipfile, opfPath)
coverId = nil
--- /dev/null
+require 'page'
+require 'store'
+
+class Navigator
+ def initialize(store)
+ @store = store
+ end
+
+ def write_atoz_pages
+ atoz_counts = {}
+
+ ('A'..'Z').each do |letter|
+ atoz_counts[letter] = write_authors_starting_with(letter)
+ end
+
+ content = '<table><tr><th>Author</th><th>Books</th></tr>'
+ ('A'..'Z').each do |letter|
+ content += ' <tr><td><a href="../atoz/output_' + letter + '.html">Starting with ' + letter + '</a></td><td>' + atoz_counts[letter].to_s + '</td></tr>'
+ end
+ page = Page.new(@store)
+ page.output_dir = 'atoz'
+ page.special = content
+ page.up = ['../output/index.html', 'Up']
+
+ page.write_html( [] )
+ end
+
+ def write_authors_starting_with(letter)
+ book_ids = @store.query_books_by_author(letter + '%')
+ puts 'Authors starting with "' + letter + '": ' + book_ids.length.to_s() + ' books.'
+
+ page = Page.new(@store)
+ if 'A' != letter
+ page.back = ['../atoz/output_' + (letter.ord - 1).chr + '.html', 'Prev']
+ end
+ if 'Z' != letter
+ page.forward = ['../atoz/output_' + (letter.ord + 1).chr + '.html', 'Next']
+ end
+ page.output_dir = 'atoz'
+ page.index_file = 'output_' + letter + '.html'
+ page.title = "Authors starting with '" + letter + "'"
+ page.up = ['../atoz/index.html', 'Up']
+
+ page.write_html(book_ids)
+ return book_ids.length
+ end
+
+ def write_series_for_age(age)
+ series_infos = []
+
+ series_ids = @store.query_series_by_age(age)
+
+ series_ids.each do |id|
+ series = @store.load_series(id)
+ book_ids = @store.query_books_by_series_id(id)
+ if nil != book_ids and book_ids.length > 0
+ series_infos.push( [series, book_ids] )
+ end
+ end
+
+ for idx in 0 .. (series_infos.length - 1) do
+ #puts series.descr + ': ' + book_ids.length.to_s + ' books.'
+
+ back = nil
+ fwd = nil
+
+ if idx > 0
+ back = series_infos[idx-1]
+ end
+ if (idx + 1) < series_infos.length
+ fwd = series_infos[idx+1]
+ end
+
+ cur = series_infos[idx]
+ series = cur[0]
+ book_ids = cur[1]
+
+ page = Page.new(@store)
+ if nil != back
+ page.back = [back[0].key + '.html', 'Back']
+ end
+ if nil != fwd
+ page.forward = [fwd[0].key + '.html', 'Forward']
+ end
+ page.output_dir = 'series/series_' + age
+ page.index_file = series.key + '.html'
+ page.title = 'Series “' + series.descr + '” (' + book_ids.length.to_s + ' books)'
+ page.up = ['index.html', 'Up']
+
+ page.write_html(book_ids)
+ end
+
+ content = '<h1>“' + age + '” Series</h1>'
+ content += '<p><table><tr><th>Author</th><th>Series</th><th>Genre</th><th>Books</th></tr>'
+ series_infos.each do |cur|
+ series = cur[0]
+ book_ids = cur[1]
+
+ author = series.grouping
+ letter = author[0]
+
+ content += ' <tr>'
+ content += '<td><a href="../../atoz/output_' + letter + '.html">' + author + '</a></td>'
+ content += '<td><a href="' + series.key + '.html">' + series.descr + '</a></td>'
+ content += '<td>' + series.genre + '</td>'
+ content += '<td>' + book_ids.length.to_s + '</td>'
+ content += '</tr>'
+ end
+ content += '</table></p>'
+ page = Page.new(@store)
+ page.output_dir = 'series/series_' + age
+ page.special = content
+ page.up = ['../index.html', 'Up']
+ page.write_html( [] )
+
+ return series_infos.length
+ end
+
+ def write_series_listing
+ ages = ['beginner', 'junior', 'ya', 'adult']
+ series_counts = {}
+
+ ages.each do |age|
+ puts 'Series for "' + age + '" readers...'
+
+ series_counts[age] = write_series_for_age(age)
+ end
+
+ content = '<h1>Browse Books By Series</h1>'
+ content += '<p>'
+ content += '<table><tr><th>Age</th><th>Number of Series</th></tr>'
+ ages.each do |age|
+ content += '<tr><td><a href="series_' + age + '/index.html">' + age + '</a></td><td>' + series_counts[age].to_s + '</td></tr>'
+ end
+ content += '</table></p>'
+ page = Page.new(@store)
+ page.output_dir = 'series'
+ page.special = content
+ page.up = ['../output/index.html', 'Up']
+ page.write_html( [] )
+ end
+end
def books
result = []
for file in @files.sort
- if Book.canHandle?(file)
+ if Book.can_handle?(file) && (!is_duplicate?(file))
book = Book.new(@store)
- book.loadFromFile(file)
+ book.load_from_file(file)
id = @store.store_book(book)
result.push(id)
end
return result
end
+ # Duplicate versions of a text are named
+ # xxx_suffix.ext
+ # Where suffix is one of bis, ter, quater, quinquies
+ # for the 2nd, 3rd, 4th or 5th variant respectively.
+ def is_duplicate?(file)
+ s = file.to_s
+ suffix = ['_bis.', '_ter.', '_quater.', '_quinquies.']
+ suffix.each do |pat|
+ if s.include?(pat)
+ return true
+ end
+ end
+
+ return false
+ end
+
def walk(path)
result = []
children = Dir.entries(path)