mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
MOBI Output: Add option to control setting of PDOC flag
This commit is contained in:
commit
3a73d538bf
@ -9,7 +9,8 @@ import re
|
|||||||
import time
|
import time
|
||||||
from calibre import entity_to_unicode
|
from calibre import entity_to_unicode
|
||||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
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):
|
class NYTimes(BasicNewsRecipe):
|
||||||
|
|
||||||
@ -256,7 +257,6 @@ class NYTimes(BasicNewsRecipe):
|
|||||||
# Fetch the outer table
|
# Fetch the outer table
|
||||||
table = soup.find('table')
|
table = soup.find('table')
|
||||||
previousTable = table
|
previousTable = table
|
||||||
contentTable = None
|
|
||||||
|
|
||||||
# Find the deepest table containing the stories
|
# Find the deepest table containing the stories
|
||||||
while True :
|
while True :
|
||||||
|
@ -128,7 +128,6 @@ class USAToday(BasicNewsRecipe):
|
|||||||
def parse_feeds(self, *args, **kwargs):
|
def parse_feeds(self, *args, **kwargs):
|
||||||
parsed_feeds = BasicNewsRecipe.parse_feeds(self, *args, **kwargs)
|
parsed_feeds = BasicNewsRecipe.parse_feeds(self, *args, **kwargs)
|
||||||
# Count articles for progress dialog
|
# Count articles for progress dialog
|
||||||
content_feeds = []
|
|
||||||
article_count = 0
|
article_count = 0
|
||||||
for feed in parsed_feeds:
|
for feed in parsed_feeds:
|
||||||
article_count += len(feed)
|
article_count += len(feed)
|
||||||
@ -297,7 +296,6 @@ class USAToday(BasicNewsRecipe):
|
|||||||
|
|
||||||
if not headline_found:
|
if not headline_found:
|
||||||
# Monolithic <div> - restructure
|
# Monolithic <div> - restructure
|
||||||
insert_loc = 0
|
|
||||||
tag = body.find(True)
|
tag = body.find(True)
|
||||||
while True:
|
while True:
|
||||||
insertLoc += 1
|
insertLoc += 1
|
||||||
|
@ -322,11 +322,13 @@ class MetadataUpdater(object):
|
|||||||
|
|
||||||
recs = []
|
recs = []
|
||||||
try:
|
try:
|
||||||
from calibre.ebooks.conversion.config import load_defaults
|
from calibre.ebooks.conversion.config import load_defaults
|
||||||
prefs = load_defaults('mobi_output')
|
prefs = load_defaults('mobi_output')
|
||||||
pas = prefs.get('prefer_author_sort', False)
|
pas = prefs.get('prefer_author_sort', False)
|
||||||
|
kindle_pdoc = prefs.get('personal_doc', None)
|
||||||
except:
|
except:
|
||||||
pas = False
|
pas = False
|
||||||
|
kindle_pdoc = None
|
||||||
if mi.author_sort and pas:
|
if mi.author_sort and pas:
|
||||||
authors = mi.author_sort
|
authors = mi.author_sort
|
||||||
update_exth_record((100, authors.encode(self.codec, 'replace')))
|
update_exth_record((100, authors.encode(self.codec, 'replace')))
|
||||||
@ -350,15 +352,8 @@ class MetadataUpdater(object):
|
|||||||
subjects = '; '.join(mi.tags)
|
subjects = '; '.join(mi.tags)
|
||||||
update_exth_record((105, subjects.encode(self.codec, 'replace')))
|
update_exth_record((105, subjects.encode(self.codec, 'replace')))
|
||||||
|
|
||||||
# >>> Begin patch for ticket #4652 <<<
|
if kindle_pdoc and kindle_pdoc in mi.tags:
|
||||||
kindle_doc_types = set([u'[kindle_ebok]',u'[kindle_pdoc]'])
|
update_exth_record((501, str('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]':
|
|
||||||
update_exth_record((501, str('PDOC')))
|
|
||||||
# >>> End patch
|
|
||||||
|
|
||||||
if mi.pubdate:
|
if mi.pubdate:
|
||||||
update_exth_record((106, str(mi.pubdate).encode(self.codec, 'replace')))
|
update_exth_record((106, str(mi.pubdate).encode(self.codec, 'replace')))
|
||||||
|
@ -83,7 +83,7 @@ class MetadataUpdater(object):
|
|||||||
|
|
||||||
sig = self.data[:4]
|
sig = self.data[:4]
|
||||||
if not sig.startswith('TPZ'):
|
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
|
offset = 4
|
||||||
|
|
||||||
self.header_records, consumed = self.decode_vwi(self.data[offset: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
|
# First integrity test - metadata header
|
||||||
if not 'metadata' in self.topaz_headers:
|
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
|
# Second integrity test - metadata body
|
||||||
md_offset = self.topaz_headers['metadata']['blocks'][0]['offset']
|
md_offset = self.topaz_headers['metadata']['blocks'][0]['offset']
|
||||||
md_offset += self.base
|
md_offset += self.base
|
||||||
if self.data[md_offset+1:md_offset+9] != 'metadata':
|
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):
|
def book_length(self):
|
||||||
''' convenience method for retrieving book length '''
|
''' convenience method for retrieving book length '''
|
||||||
|
@ -36,6 +36,9 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
help=_('Disable compression of the file contents.')
|
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):
|
def check_for_periodical(self):
|
||||||
|
@ -24,7 +24,7 @@ class PluginWidget(Widget, Ui_Form):
|
|||||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||||
Widget.__init__(self, parent, 'mobi_output',
|
Widget.__init__(self, parent, 'mobi_output',
|
||||||
['prefer_author_sort', 'rescale_images', 'toc_title',
|
['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
|
self.db, self.book_id = db, book_id
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>421</width>
|
<width>521</width>
|
||||||
<height>300</height>
|
<height>331</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -64,13 +64,27 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Masthead font:</string>
|
<string>Periodical masthead font:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QComboBox" name="opt_masthead_font"/>
|
<widget class="QComboBox" name="opt_masthead_font"/>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
@ -79,7 +93,7 @@
|
|||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>20</width>
|
<width>20</width>
|
||||||
<height>55</height>
|
<height>40</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user