MOBI Output: Add option to control setting of PDOC flag

This commit is contained in:
Kovid Goyal 2010-03-28 08:02:09 +05:30
commit 3a73d538bf
7 changed files with 34 additions and 24 deletions

View File

@ -9,7 +9,8 @@ import re
import time
from calibre import entity_to_unicode
from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag, NavigableString, Comment
from calibre.ebooks.BeautifulSoup import BeautifulSoup, Tag, NavigableString, \
Comment, BeautifulStoneSoup
class NYTimes(BasicNewsRecipe):
@ -256,7 +257,6 @@ class NYTimes(BasicNewsRecipe):
# Fetch the outer table
table = soup.find('table')
previousTable = table
contentTable = None
# Find the deepest table containing the stories
while True :

View File

@ -128,7 +128,6 @@ class USAToday(BasicNewsRecipe):
def parse_feeds(self, *args, **kwargs):
parsed_feeds = BasicNewsRecipe.parse_feeds(self, *args, **kwargs)
# Count articles for progress dialog
content_feeds = []
article_count = 0
for feed in parsed_feeds:
article_count += len(feed)
@ -297,7 +296,6 @@ class USAToday(BasicNewsRecipe):
if not headline_found:
# Monolithic <div> - restructure
insert_loc = 0
tag = body.find(True)
while True:
insertLoc += 1

View File

@ -325,8 +325,10 @@ class MetadataUpdater(object):
from calibre.ebooks.conversion.config import load_defaults
prefs = load_defaults('mobi_output')
pas = prefs.get('prefer_author_sort', False)
kindle_pdoc = prefs.get('personal_doc', None)
except:
pas = False
kindle_pdoc = None
if mi.author_sort and pas:
authors = mi.author_sort
update_exth_record((100, authors.encode(self.codec, 'replace')))
@ -350,15 +352,8 @@ class MetadataUpdater(object):
subjects = '; '.join(mi.tags)
update_exth_record((105, subjects.encode(self.codec, 'replace')))
# >>> Begin patch for ticket #4652 <<<
kindle_doc_types = set([u'[kindle_ebok]',u'[kindle_pdoc]'])
doc_type = list(kindle_doc_types.intersection(set(mi.tags)))[0]
if doc_type:
if doc_type == '[kindle_ebok]':
update_exth_record((501,str('EBOK')))
elif doc_type == '[kindle_pdoc]':
if kindle_pdoc and kindle_pdoc in mi.tags:
update_exth_record((501, str('PDOC')))
# >>> End patch
if mi.pubdate:
update_exth_record((106, str(mi.pubdate).encode(self.codec, 'replace')))

View File

@ -83,7 +83,7 @@ class MetadataUpdater(object):
sig = self.data[:4]
if not sig.startswith('TPZ'):
raise ValueError('Not a Topaz file')
raise ValueError("'%s': Not a Topaz file" % getattr(stream, 'name', 'Unnamed stream'))
offset = 4
self.header_records, consumed = self.decode_vwi(self.data[offset:offset+4])
@ -92,13 +92,13 @@ class MetadataUpdater(object):
# First integrity test - metadata header
if not 'metadata' in self.topaz_headers:
raise ValueError('Invalid Topaz format - no metadata record')
raise ValueError("'%s': Invalid Topaz format - no metadata record" % getattr(stream, 'name', 'Unnamed stream'))
# Second integrity test - metadata body
md_offset = self.topaz_headers['metadata']['blocks'][0]['offset']
md_offset += self.base
if self.data[md_offset+1:md_offset+9] != 'metadata':
raise ValueError('Damaged metadata record')
raise ValueError("'%s': Damaged metadata record" % getattr(stream, 'name', 'Unnamed stream'))
def book_length(self):
''' convenience method for retrieving book length '''

View File

@ -36,6 +36,9 @@ class MOBIOutput(OutputFormatPlugin):
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Disable compression of the file contents.')
),
OptionRecommendation(name='personal_doc', recommended_value='[kindle_pdoc]',
help=_('Tag marking book to be filed with Personal Docs')
),
])
def check_for_periodical(self):

View File

@ -24,7 +24,7 @@ class PluginWidget(Widget, Ui_Form):
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent, 'mobi_output',
['prefer_author_sort', 'rescale_images', 'toc_title',
'dont_compress', 'no_inline_toc', 'masthead_font']
'dont_compress', 'no_inline_toc', 'masthead_font','personal_doc']
)
self.db, self.book_id = db, book_id

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>300</height>
<width>521</width>
<height>331</height>
</rect>
</property>
<property name="windowTitle">
@ -64,13 +64,27 @@
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Masthead font:</string>
<string>Periodical masthead font:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="opt_masthead_font"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Personal Doc tag:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="opt_personal_doc"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
@ -79,7 +93,7 @@
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>55</height>
<height>40</height>
</size>
</property>
</spacer>