From 1de8755d36ebd598a0a5d66e91e8940d31470c91 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Mon, 29 Jun 2015 10:28:53 -0500 Subject: [PATCH] Add more forums tweaks and '(new)' chapter mark option. --- calibre-plugin/plugin-defaults.ini | 22 +++++-------------- .../adapters/adapter_forumsspacebattlescom.py | 8 ++++++- fanficfare/adapters/base_adapter.py | 6 ++++- fanficfare/story.py | 4 +++- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index 5a953a6..d542eed 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -1045,13 +1045,8 @@ cover_exclusion_regexp:/res/css/bir.png cover_exclusion_regexp:/clear.png -add_to_extratags:,ForumFic - strip_chapter_numbers:false -# true, false, threadmarksonly -add_chapter_dates:false - add_to_extra_valid_entries:,titletags # '.NOREPL' tells the system to *not* apply title's # in/exclude/replace_metadata -- Only works on include_in_ lines. @@ -1066,9 +1061,6 @@ include_metadata_pre: titletags=~[\[\(] replace_metadata: -# remove 'Thread' and the next word, usually "Thread 2", "Thread -# four", "Thread iv", etc - title=>[-: ]*[Tt]hread [^ ]+[-: ]*=> # remove anything outside () or [] titletags=>^.*?([\(\[]([^\]\)]+)[\)\]]).*?$=>\1 # remove () [] @@ -1078,6 +1070,9 @@ replace_metadata: titletags=> x =>, # remove [] or () blocks and leading/trailing spaces title=> *[\(\[]([^\]\)]+)[\)\]] *=> +# remove 'Thread' and the next word, usually "Thread 2", "Thread +# four", "Thread iv", etc + title=>[-: ]*[Tt]hread [^ ]+[-: ]*=> extra_titlepage_entries: titletags @@ -1093,11 +1088,6 @@ description_limit:500 cover_exclusion_regexp:/clear.png -add_to_extratags:,ForumFic - -# true, false, threadmarksonly -add_chapter_dates:false - strip_chapter_numbers:false add_to_extra_valid_entries:,titletags @@ -1114,9 +1104,6 @@ include_metadata_pre: titletags=~[\[\(] replace_metadata: -# remove 'Thread' and the next word, usually "Thread 2", "Thread -# four", "Thread iv", etc - title=>[-: ]*[Tt]hread [^ ]+[-: ]*=> # remove anything outside () or [] titletags=>^.*?([\(\[]([^\]\)]+)[\)\]]).*?$=>\1 # remove () [] @@ -1126,6 +1113,9 @@ replace_metadata: titletags=> x =>, # remove [] or () blocks and leading/trailing spaces title=> *[\(\[]([^\]\)]+)[\)\]] *=> +# remove 'Thread' and the next word, usually "Thread 2", "Thread +# four", "Thread iv", etc + title=>[-: ]*[Tt]hread [^ ]+[-: ]*=> extra_titlepage_entries: titletags diff --git a/fanficfare/adapters/adapter_forumsspacebattlescom.py b/fanficfare/adapters/adapter_forumsspacebattlescom.py index 43fd525..839c2cd 100644 --- a/fanficfare/adapters/adapter_forumsspacebattlescom.py +++ b/fanficfare/adapters/adapter_forumsspacebattlescom.py @@ -146,6 +146,9 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter): for iframe in bq.find_all('iframe'): iframe.extract() # calibre book reader & editor don't like iframes to youtube. + for qdiv in bq.find_all('div',{'class':'quoteExpand'}): + qdiv.extract() # Remove
click to expand
+ self.setDescription(useurl,bq) # otherwise, use first post links--include first post since that's @@ -163,7 +166,7 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter): self.chapterUrls.append((name,url)) if url == useurl and 'First Post' == self.chapterUrls[0][0]: # remove "First Post" if included in list. - logger.debug("delete dup chapter: %s %s"%self.chapterUrls[0]) + logger.debug("delete dup 'First Post' chapter: %s %s"%self.chapterUrls[0]) del self.chapterUrls[0] # Didn't use threadmarks, so take created/updated dates @@ -218,4 +221,7 @@ class ForumsSpacebattlesComAdapter(BaseSiteAdapter): for iframe in bq.find_all('iframe'): iframe.extract() # calibre book reader & editor don't like iframes to youtube. + for qdiv in bq.find_all('div',{'class':'quoteExpand'}): + qdiv.extract() # Remove
click to expand
+ return self.utf8FromSoup(url,bq) diff --git a/fanficfare/adapters/base_adapter.py b/fanficfare/adapters/base_adapter.py index a0a0b7f..efc774c 100644 --- a/fanficfare/adapters/base_adapter.py +++ b/fanficfare/adapters/base_adapter.py @@ -361,6 +361,7 @@ class BaseSiteAdapter(Configurable): self.getStoryMetadataOnly(get_cover=True) for index, (title,url) in enumerate(self.chapterUrls): + marknewchap = False if (self.chapterFirst!=None and index < self.chapterFirst) or \ (self.chapterLast!=None and index > self.chapterLast): self.story.addChapter(url, @@ -379,9 +380,12 @@ class BaseSiteAdapter(Configurable): partial(cachedfetch,self._fetchUrlRaw,self.oldimgs)) if not data: data = self.getChapterText(url) + # if configured and has existing chapters + marknewchap = (self.getConfig('mark_new_chapters')=='true' and self.oldchapters or self.oldchaptersmap) self.story.addChapter(url, removeEntities(title), - removeEntities(data)) + removeEntities(data), + marknewchap) self.storyDone = True # include image, but no cover from story, add default_cover_image cover. diff --git a/fanficfare/story.py b/fanficfare/story.py index 2e7c2ae..b9abdd8 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -840,10 +840,12 @@ class Story(Configurable): return list(subjectset | set(self.getConfigList("extratags"))) - def addChapter(self, url, title, html): + def addChapter(self, url, title, html, marknewchap=False): if self.getConfig('strip_chapter_numbers') and \ self.getConfig('chapter_title_strip_pattern'): title = re.sub(self.getConfig('chapter_title_strip_pattern'),"",title) + if marknewchap: + title=u'(new) %s'%title self.chapters.append( (url,title,html) ) def getChapters(self,fortoc=False):