From 7a8c16847c9d2250006038af2400c7f8d28b14aa Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Wed, 22 Aug 2018 15:45:46 -0500 Subject: [PATCH] Add latestonly option to mark_new_chapters feature to remove pre-existing (new) chpater marks on update and only mark chapters that are new in this update. Closes #330 --- calibre-plugin/plugin-defaults.ini | 7 ++++++- fanficfare/adapters/base_adapter.py | 13 +++++++------ fanficfare/configurable.py | 2 +- fanficfare/defaults.ini | 7 ++++++- fanficfare/story.py | 2 +- 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index cf000204..c2e312a7 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -396,7 +396,12 @@ chapter_title_strip_pattern:^[0-9]+[\.: -]+(?=[^0-9]|$) ## If true, when updating an epub that already has old chapters, new ## chapters will be marked in the TOC and chapter header by using -## chapter_title_new_pattern and chapter_title_addnew_pattern to set the chapter. +## chapter_title_new_pattern and chapter_title_addnew_pattern to set +## the chapter title. +## If set to latestonly, only new chapters downloaded this time will +## be marked (new) and existing chapters will have any (new) marks +## removed. +## mark_new_chapters can be true, false or latestonly mark_new_chapters:false ## chapter title patterns use python template substitution. The diff --git a/fanficfare/adapters/base_adapter.py b/fanficfare/adapters/base_adapter.py index 6a0a9de6..afbcdc17 100644 --- a/fanficfare/adapters/base_adapter.py +++ b/fanficfare/adapters/base_adapter.py @@ -209,12 +209,13 @@ class BaseSiteAdapter(Configurable): self.oldchapters[index], partial(cachedfetch,self._fetchUrlRaw,self.oldimgs)) - # if already marked new -- ie, origtitle and title don't match - # logger.debug("self.oldchaptersdata[url]:%s"%(self.oldchaptersdata[url])) - newchap = (self.oldchaptersdata is not None and - url in self.oldchaptersdata and ( - self.oldchaptersdata[url]['chapterorigtitle'] != - self.oldchaptersdata[url]['chaptertitle']) ) + if self.getConfig('mark_new_chapters') == 'true': + # if already marked new -- ie, origtitle and title don't match + # logger.debug("self.oldchaptersdata[url]:%s"%(self.oldchaptersdata[url])) + newchap = (self.oldchaptersdata is not None and + url in self.oldchaptersdata and ( + self.oldchaptersdata[url]['chapterorigtitle'] != + self.oldchaptersdata[url]['chaptertitle']) ) try: if not data: diff --git a/fanficfare/configurable.py b/fanficfare/configurable.py index fb9425ac..038afdb9 100644 --- a/fanficfare/configurable.py +++ b/fanficfare/configurable.py @@ -204,7 +204,7 @@ def get_valid_set_options(): 'replace_hr':(None,None,boollist), 'sort_ships':(None,None,boollist), 'strip_chapter_numbers':(None,None,boollist), - 'mark_new_chapters':(None,None,boollist), + 'mark_new_chapters':(None,None,boollist+['latestonly']), 'titlepage_use_table':(None,None,boollist), 'use_ssl_unverified_context':(None,None,boollist), diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 48f8edc6..8d3ee7cf 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -399,7 +399,12 @@ chapter_title_strip_pattern:^[0-9]+[\.: -]+(?=[^0-9]|$) ## If true, when updating an epub that already has old chapters, new ## chapters will be marked in the TOC and chapter header by using -## chapter_title_new_pattern and chapter_title_addnew_pattern to set the chapter. +## chapter_title_new_pattern and chapter_title_addnew_pattern to set +## the chapter title. +## If set to latestonly, only new chapters downloaded this time will +## be marked (new) and existing chapters will have any (new) marks +## removed. +## mark_new_chapters can be true, false or latestonly mark_new_chapters:false ## chapter title patterns use python template substitution. The diff --git a/fanficfare/story.py b/fanficfare/story.py index 2dc6c33b..e8d5a203 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -1046,7 +1046,7 @@ class Story(Configurable): addnums = ( self.getConfig('add_chapter_numbers') == "true" or (self.getConfig('add_chapter_numbers') == "toconly" and fortoc) ) - marknew = self.getConfig('mark_new_chapters')=='true' + marknew = self.getConfig('mark_new_chapters') # true or latestonly defpattern = self.getConfig('chapter_title_def_pattern','${title}') # default val in case of missing defaults.ini if addnums and marknew: