From f207e31b3b097f89146aa795ad2cdb0952fcc39b Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 28 Nov 2025 12:48:25 -0600 Subject: [PATCH] Add standard metadata entry marked_new_chapters for epub updated '(new)' chapters count --- calibre-plugin/plugin-defaults.ini | 7 +++++++ fanficfare/configurable.py | 2 ++ fanficfare/defaults.ini | 7 +++++++ fanficfare/story.py | 4 ++++ 4 files changed, 20 insertions(+) diff --git a/calibre-plugin/plugin-defaults.ini b/calibre-plugin/plugin-defaults.ini index aabf6f43..15098c7e 100644 --- a/calibre-plugin/plugin-defaults.ini +++ b/calibre-plugin/plugin-defaults.ini @@ -513,6 +513,13 @@ mark_new_chapters:false ## (new) marks in TOC when mark_new_chapters:true #anthology_merge_keepsingletocs:false +## The count of how many chapters are marked '(new)' will be in +## metadata entry marked_new_chapters +marked_new_chapters_label:Chapters Marked New + +# Add comma separators for numeric reads. Eg 10000 becomes 10,000 +add_to_comma_entries:,marked_new_chapters + ## chapter title patterns use python template substitution. The ## ${number} is the 'chapter' number and ${title} is the chapter ## title, after applying chapter_title_strip_pattern. ${index04} is diff --git a/fanficfare/configurable.py b/fanficfare/configurable.py index 3411b764..e81a4585 100644 --- a/fanficfare/configurable.py +++ b/fanficfare/configurable.py @@ -95,6 +95,7 @@ titleLabels = { 'numChapters':'Chapters', 'numWords':'Words', 'words_added':'Words Added', # logpage only + 'marked_new_chapters':'Chapters Marked New', 'site':'Site', 'publisher':'Publisher', 'storyId':'Story ID', @@ -347,6 +348,7 @@ def get_valid_scalar_entries(): 'numChapters', 'numWords', 'words_added', # logpage only. + 'marked_new_chapters', 'site', 'publisher', 'storyId', diff --git a/fanficfare/defaults.ini b/fanficfare/defaults.ini index 118841e4..df9d95b7 100644 --- a/fanficfare/defaults.ini +++ b/fanficfare/defaults.ini @@ -483,6 +483,13 @@ chapter_title_strip_pattern:^[0-9]+[\.: -]+(?=[^0-9]|$) ## mark_new_chapters can be true, false or latestonly mark_new_chapters:false +## The count of how many chapters are marked '(new)' will be in +## metadata entry marked_new_chapters +marked_new_chapters_label:Chapters Marked New + +# Add comma separators for numeric reads. Eg 10000 becomes 10,000 +add_to_comma_entries:,marked_new_chapters + ## chapter title patterns use python template substitution. The ## ${number} is the 'chapter' number and ${title} is the chapter ## title, after applying chapter_title_strip_pattern. ${index04} is diff --git a/fanficfare/story.py b/fanficfare/story.py index dc2d069c..fc313583 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -1483,9 +1483,11 @@ class Story(Requestable): newtempl = string.Template(newpattern) toctempl = string.Template(tocpattern) + marked_new_chapters = 0 for index, chap in enumerate(self.chapters): if chap['new'] or self.getMetadata('newforanthology'): usetempl = newtempl + marked_new_chapters += 1 else: usetempl = templ # logger.debug("chap(%s)"%chap) @@ -1505,6 +1507,8 @@ class Story(Requestable): ## chapter['html'] is a string. chapter['html'] = self.do_chapter_text_replacements(chapter['html']) retval.append(chapter) + if marked_new_chapters: + self.setMetadata('marked_new_chapters',marked_new_chapters) return retval def do_chapter_text_replacements(self,data):