diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index 5de42667..5f97f136 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -1333,7 +1333,9 @@ class FanFicFarePlugin(InterfaceAction): (epuburl,chaptercount) = \ get_dcsource_chaptercount(StringIO(db.format(book_id,'EPUB', index_is_id=True))) - urlchaptercount = int(story.getMetadata('numChapters').replace(',','')) + #urlchaptercount = int(story.getMetadata('numChapters').replace(',','')) + # returns int adjusted for start-end range. + urlchaptercount = story.getChapterCount() if chaptercount == urlchaptercount: if collision == UPDATE: raise NotGoingToDownload(_("Already contains %d chapters.")%chaptercount,'edit-undo.png',showerror=False) diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index bd197be0..b7289258 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -233,7 +233,9 @@ def do_download_for_worker(book,options,merge,notification=lambda x,y:x): # update now handled by pre-populating the old images and # chapters in the adapter rather than merging epubs. - urlchaptercount = int(story.getMetadata('numChapters').replace(',','')) + #urlchaptercount = int(story.getMetadata('numChapters').replace(',','')) + # returns int adjusted for start-end range. + urlchaptercount = story.getChapterCount() (url, chaptercount, adapter.oldchapters, diff --git a/fanficfare/cli.py b/fanficfare/cli.py index ded05e75..ee1bc6b7 100644 --- a/fanficfare/cli.py +++ b/fanficfare/cli.py @@ -385,6 +385,8 @@ def do_download(arg, if options.update and not options.force: urlchaptercount = int(adapter.getStoryMetadataOnly().getMetadata('numChapters').replace(',','')) + # returns int adjusted for start-end range. + urlchaptercount = adapter.getStoryMetadataOnly().getChapterCount() if chaptercount == urlchaptercount and not options.metaonly: print '%s already contains %d chapters.' % (output_filename, chaptercount) diff --git a/fanficfare/story.py b/fanficfare/story.py index 98724e0c..a3bae5ca 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -679,6 +679,15 @@ class Story(Configurable): # self.metadata = json.loads(s, object_hook=datetime_decoder) + def getChapterCount(self): + ## returns chapter count adjusted for start-end range. + url_chapters = value = int(self.getMetadata("numChapters").replace(',','')) + if self.chapter_first: + value = url_chapters - (int(self.chapter_first) - 1) + if self.chapter_last: + value = value - (url_chapters - int(self.chapter_last)) + return value + def getMetadataRaw(self,key): if self.isValidMetaEntry(key) and self.metadata.has_key(key): return self.metadata[key] @@ -717,7 +726,6 @@ class Story(Configurable): if isinstance(value, (datetime.date, datetime.datetime, datetime.time)) and self.hasConfig(key+"_format"): # logger.info("DATE: %s"%key) value = value.strftime(self.getConfig(key+"_format")) - if key == "title" and (self.chapter_first or self.chapter_last) and self.getConfig("title_chapter_range_pattern"): first = self.chapter_first or "1" last = self.chapter_last or self.getMetadata("numChapters")