Fix Update Always metadata in BG logic

This commit is contained in:
Jim Miller 2023-05-08 19:47:46 -05:00
parent a259297092
commit 6f77504ca9
2 changed files with 11 additions and 12 deletions

View file

@ -1535,21 +1535,19 @@ class FanFicFarePlugin(InterfaceAction):
## newer/chaptercount checks are the same for both: ## newer/chaptercount checks are the same for both:
# Update epub, but only if more chapters. # Update epub, but only if more chapters.
if not bgmeta and collision in (UPDATE,UPDATEALWAYS): # collision == UPDATE if not bgmeta and collision in (UPDATE,UPDATEALWAYS):
# 'book' can exist without epub. If there's no existing epub, # 'book' can exist without epub. If there's no existing epub,
# let it go and it will download it. # let it go and it will download it.
if db.has_format(book_id,fileform,index_is_id=True): if db.has_format(book_id,fileform,index_is_id=True):
(epuburl,chaptercount) = \ (epuburl,chaptercount) = \
get_dcsource_chaptercount(BytesIO(db.format(book_id,'EPUB', get_dcsource_chaptercount(BytesIO(db.format(book_id,'EPUB',
index_is_id=True))) index_is_id=True)))
#urlchaptercount = int(story.getMetadata('numChapters').replace(',',''))
# returns int adjusted for start-end range. # returns int adjusted for start-end range.
urlchaptercount = story.getChapterCount() urlchaptercount = story.getChapterCount()
if chaptercount == urlchaptercount: if chaptercount == urlchaptercount and collision == UPDATE:
if collision == UPDATE: raise NotGoingToDownload(_("Already contains %d chapters.")%chaptercount,'edit-undo.png',showerror=False)
raise NotGoingToDownload(_("Already contains %d chapters.")%chaptercount,'edit-undo.png',showerror=False)
elif chaptercount > urlchaptercount and not (collision == UPDATEALWAYS and adapter.getConfig('force_update_epub_always')): elif chaptercount > urlchaptercount and not (collision == UPDATEALWAYS and adapter.getConfig('force_update_epub_always')):
raise NotGoingToDownload(_("Existing epub contains %d chapters, web site only has %d. Use Overwrite to force update.") % (chaptercount,urlchaptercount),'dialog_error.png') raise NotGoingToDownload(_("Existing epub contains %d chapters, web site only has %d. Use Overwrite or force_update_epub_always to force update.") % (chaptercount,urlchaptercount),'dialog_error.png')
elif chaptercount == 0: elif chaptercount == 0:
raise NotGoingToDownload(_("FanFicFare doesn't recognize chapters in existing epub, epub is probably from a different source. Use Overwrite to force update."),'dialog_error.png') raise NotGoingToDownload(_("FanFicFare doesn't recognize chapters in existing epub, epub is probably from a different source. Use Overwrite to force update."),'dialog_error.png')

View file

@ -336,20 +336,21 @@ def do_download_for_worker(book,options,merge,notification=lambda x,y:x):
adapter.oldchaptersmap, adapter.oldchaptersmap,
adapter.oldchaptersdata) = get_update_data(book['epub_for_update'])[0:9] adapter.oldchaptersdata) = get_update_data(book['epub_for_update'])[0:9]
# dup handling from fff_plugin needed for anthology updates. # dup handling from fff_plugin needed for anthology updates & BG metadata.
if book['collision'] == UPDATE: if book['collision'] in (UPDATE,UPDATEALWAYS):
if chaptercount == urlchaptercount: if chaptercount == urlchaptercount and book['collision'] == UPDATE:
if merge: if merge:
## Deliberately pass for UPDATEALWAYS merge.
book['comment']=_("Already contains %d chapters. Reuse as is.")%chaptercount book['comment']=_("Already contains %d chapters. Reuse as is.")%chaptercount
book['all_metadata'] = story.getAllMetadata(removeallentities=True) book['all_metadata'] = story.getAllMetadata(removeallentities=True)
if options['savemetacol'] != '': if options['savemetacol'] != '':
book['savemetacol'] = story.dump_html_metadata() book['savemetacol'] = story.dump_html_metadata()
book['outfile'] = book['epub_for_update'] # for anthology merge ops. book['outfile'] = book['epub_for_update'] # for anthology merge ops.
return book return book
else: # not merge, else:
raise NotGoingToDownload(_("Already contains %d chapters.")%chaptercount,'edit-undo.png',showerror=False) raise NotGoingToDownload(_("Already contains %d chapters.")%chaptercount,'edit-undo.png',showerror=False)
elif chaptercount > urlchaptercount: elif chaptercount > urlchaptercount and not (book['collision'] == UPDATEALWAYS and adapter.getConfig('force_update_epub_always')):
raise NotGoingToDownload(_("Existing epub contains %d chapters, web site only has %d. Use Overwrite to force update.") % (chaptercount,urlchaptercount),'dialog_error.png') raise NotGoingToDownload(_("Existing epub contains %d chapters, web site only has %d. Use Overwrite or force_update_epub_always to force update.") % (chaptercount,urlchaptercount),'dialog_error.png')
elif chaptercount == 0: elif chaptercount == 0:
raise NotGoingToDownload(_("FanFicFare doesn't recognize chapters in existing epub, epub is probably from a different source. Use Overwrite to force update."),'dialog_error.png') raise NotGoingToDownload(_("FanFicFare doesn't recognize chapters in existing epub, epub is probably from a different source. Use Overwrite to force update."),'dialog_error.png')