diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index b962d9e2..de8e017e 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -193,7 +193,8 @@ def do_download_for_worker(book,options,notification=lambda x,y:x): adapter.oldcover, adapter.calibrebookmark, adapter.logfile, - adapter.oldchaptersmap) = get_update_data(book['epub_for_update'])[0:8] + adapter.oldchaptersmap, + adapter.oldchaptersdata) = get_update_data(book['epub_for_update'])[0:9] # dup handling from fff_plugin needed for anthology updates. if options['collision'] == UPDATE: diff --git a/fanficfare/adapters/base_adapter.py b/fanficfare/adapters/base_adapter.py index aebf330e..9375aca1 100644 --- a/fanficfare/adapters/base_adapter.py +++ b/fanficfare/adapters/base_adapter.py @@ -105,6 +105,7 @@ class BaseSiteAdapter(Configurable): self.chapterLast = None self.oldchapters = None self.oldchaptersmap = None + self.oldchaptersdata = None self.oldimgs = None self.oldcover = None # (data of existing cover html, data of existing cover image) self.calibrebookmark = None @@ -361,7 +362,7 @@ class BaseSiteAdapter(Configurable): self.getStoryMetadataOnly(get_cover=True) for index, (title,url) in enumerate(self.chapterUrls): - marknewchap = False + newchap = False if (self.chapterFirst!=None and index < self.chapterFirst) or \ (self.chapterLast!=None and index > self.chapterLast): self.story.addChapter(url, @@ -378,14 +379,21 @@ class BaseSiteAdapter(Configurable): data = self.utf8FromSoup(None, self.oldchapters[index], partial(cachedfetch,self._fetchUrlRaw,self.oldimgs)) + + newchap = (self.oldchaptersdata and + url in self.oldchaptersdata and ( + self.oldchaptersdata[url]['chapterorigtitle'] != + self.oldchaptersdata[url]['chaptertitle']) ) + 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) + newchap = (self.oldchapters or self.oldchaptersmap) + self.story.addChapter(url, removeEntities(title), removeEntities(data), - marknewchap) + newchap) self.storyDone = True # include image, but no cover from story, add default_cover_image cover. diff --git a/fanficfare/cli.py b/fanficfare/cli.py index f9ab6d3e..d1ecefd4 100644 --- a/fanficfare/cli.py +++ b/fanficfare/cli.py @@ -339,7 +339,8 @@ def do_download(arg, adapter.oldcover, adapter.calibrebookmark, adapter.logfile, - adapter.oldchaptersmap) = (get_update_data(output_filename))[0:8] + adapter.oldchaptersmap, + adapter.oldchaptersdata) = (get_update_data(output_filename))[0:9] print 'Do update - epub(%d) vs url(%d)' % (chaptercount, urlchaptercount) diff --git a/fanficfare/epubutils.py b/fanficfare/epubutils.py index 5f021113..45fb65de 100644 --- a/fanficfare/epubutils.py +++ b/fanficfare/epubutils.py @@ -267,8 +267,8 @@ def reset_orig_chapters_epub(inputio,outfile): origtocncx = tocncx # print("\n%s\n%s\n"%(chapterorigtitle,chaptertitle)) # changed = True - # data = data.replace(u'', - # u''+chapterorigtitle+u'') + data = data.replace(u'', + u'') data = data.replace(u''+chaptertitle+u'',u''+chapterorigtitle+u'') data = data.replace(u'

'+chaptertitle+u'

',u'

'+chapterorigtitle+u'

') tocncx = tocncx.replace(u''+chaptertitle+u'',u''+chapterorigtitle+u'') diff --git a/fanficfare/story.py b/fanficfare/story.py index 017a4697..a39fd948 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -33,7 +33,7 @@ import exceptions from htmlcleanup import conditionalRemoveEntities, removeAllEntities from configurable import Configurable, re_compile -Chapter = namedtuple('Chapter', 'url title html origtitle') +Chapter = namedtuple('Chapter', 'url title html origtitle new') SPACE_REPLACE=u'\s' SPLIT_META=u'\,' @@ -843,19 +843,19 @@ class Story(Configurable): return list(subjectset | set(self.getConfigList("extratags"))) - def addChapter(self, url, title, html, marknewchap=False): + def addChapter(self, url, title, html, newchap=False): if self.getConfig('strip_chapter_numbers') and \ self.getConfig('chapter_title_strip_pattern'): title = re.sub(self.getConfig('chapter_title_strip_pattern'),"",title) newtitle=title - if marknewchap: + if newchap and self.getConfig('mark_new_chapters')=='true': newtitle=u'(new) %s'%title - self.chapters.append( Chapter(url,newtitle,html,title) ) + self.chapters.append( Chapter(url,newtitle,html,title,newchap) ) def getChapters(self,fortoc=False): - "Chapters will be Chapter namedtuples of (url,title,html,new)" + "Chapters will be Chapter namedtuples" retval = [] - ## only add numbers if more than one chapter. + ## only add numbers if more than one chapter. Ditto (new) marks. if len(self.chapters) > 1 and \ (self.getConfig('add_chapter_numbers') == "true" \ or (self.getConfig('add_chapter_numbers') == "toconly" and fortoc)) \ @@ -864,7 +864,8 @@ class Story(Configurable): retval.append( Chapter(chap.url, string.Template(self.getConfig('chapter_title_add_pattern')).substitute({'index':index+1,'title':chap.title}), chap.html, - string.Template(self.getConfig('chapter_title_add_pattern')).substitute({'index':index+1,'title':chap.origtitle})) ) + string.Template(self.getConfig('chapter_title_add_pattern')).substitute({'index':index+1,'title':chap.origtitle}), + chap.new) ) else: retval = self.chapters