Calculate number of chapters using start-end range when doing updates.

This commit is contained in:
Jim Miller 2018-02-26 09:25:38 -06:00
parent 51db9d2f48
commit 1dde324b51
4 changed files with 17 additions and 3 deletions

View file

@ -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)

View file

@ -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,

View file

@ -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)

View file

@ -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")