Added title and author sort key support to html2lrf

This commit is contained in:
Kovid Goyal 2007-05-10 01:49:25 +00:00
parent 5cb12c364e
commit 0caca9fe4c
2 changed files with 17 additions and 9 deletions

View File

@ -37,7 +37,7 @@ from libprs500.lrf.html.BeautifulSoup import BeautifulSoup, Comment, Tag, \
from libprs500.lrf.pylrs.pylrs import Paragraph, CR, Italic, ImageStream, TextBlock, \
ImageBlock, JumpButton, CharButton, \
Bold, Space, Plot, Image, BlockSpace,\
RuledLine
RuledLine, BookSetting
from libprs500.lrf.pylrs.pylrs import Span as _Span
from libprs500.lrf import ConversionError, option_parser, Book
from libprs500 import extract
@ -934,9 +934,13 @@ def process_file(path, options):
print >>sys.stderr, "WARNING: You don't have PIL installed. ",
'Cover and thumbnails wont work'
pass
args = dict(font_delta=options.font_delta, title=options.title, \
author=options.author, sourceencoding='utf8',\
freetext=options.freetext, category=options.category)
title = (options.title, options.title_sort)
author = (options.author, options.author_sort)
args = dict(font_delta=options.font_delta, title=title, \
author=author, sourceencoding='utf8',\
freetext=options.freetext, category=options.category,
booksetting=BookSetting(dpi=10*options.dpi,screenheight=800,
screenwidth=600))
if tpath:
args['thumbnail'] = tpath
header = None
@ -988,6 +992,10 @@ def main():
parser.add_option('--dpi', action='store', type='int', default=166, dest='dpi',
help='''The DPI of the target device. Default is 166 for the
Sony PRS 500''')
parser.add_option('--title-sort', action='store', default='', dest='title_sort',
help='Sort key for the title')
parser.add_option('--author-sort', action='store', default='', dest='author_sort',
help='Sort key for the author')
options, args = parser.parse_args()
if len(args) != 1:
parser.print_help()

View File

@ -50,7 +50,7 @@ from pylrf import (LrfWriter, LrfObject, LrfTag, LrfToc,
STREAM_FORCE_COMPRESSED)
DEFAULT_SOURCE_ENCODING = "cp1252" # defualt is us-windows character set
DEFAULT_GENREADING = "f" # default is yes to lrf, no to lrs
DEFAULT_GENREADING = "fs" # default is yes to both lrf and lrs
class LrsError(Exception):
@ -90,13 +90,13 @@ def ElementWithReading(tag, text, reading=False):
elif isinstance(text, basestring):
readingText = text
else:
# assumed to be a sequence of (name, sortas)
# assumed to be a sequence of (name, sortas)
readingText = text[1]
text = text[0]
if not reading:
readingText = ""
return ElementWithText(tag, text, reading=readingText)
@ -723,7 +723,7 @@ class BookInfo(object):
bi.append(pi)
def toElement(self, se, reading=False):
def toElement(self, se, reading=True):
bi = Element("BookInfo")
bi.append(ElementWithReading("Title", self.title, reading=reading))
bi.append(ElementWithReading("Author", self.author, reading=reading))
@ -1038,7 +1038,7 @@ class StyleDefault(LrsAttributes):
class BookSetting(LrsAttributes):
def __init__(self, **settings):
defaults = dict(bindingdirection="Lr", dpi="1600",
defaults = dict(bindingdirection="Lr", dpi="1660",
screenheight="800", screenwidth="600", colordepth="24")
LrsAttributes.__init__(self, defaults, **settings)