From 6e68624f2af6ef50ab24a9a390bc4e5baf1f3af4 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Sat, 16 Jan 2021 10:15:06 -0600 Subject: [PATCH] First rough version of reporting continue_on_chapter_error chapters. --- calibre-plugin/fff_plugin.py | 9 ++++++++- calibre-plugin/jobs.py | 20 +++++++++++++++++--- fanficfare/adapters/base_adapter.py | 1 + fanficfare/cli.py | 4 +++- fanficfare/story.py | 2 ++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index 6e76dad44..a61a99d0b 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -1856,6 +1856,7 @@ def download_list_completed(self, job, options={},merge=False): book_list = job.result good_list = [ x for x in book_list if x['good'] ] bad_list = [ x for x in book_list if not x['good'] ] + chapter_error_list = [ x for x in book_list if 'chapter_error_count' in x ] try: good_list = sorted(good_list,key=lambda x : x['reportorder']) bad_list = sorted(bad_list,key=lambda x : x['reportorder']) @@ -1865,9 +1866,15 @@ def download_list_completed(self, job, options={},merge=False): #print("book_list:%s"%book_list) payload = (good_list, bad_list, options) + if chapter_error_list: + info_dialog(self.gui, _('FanFicFare: ')+_('Some Failed Chapters'), + _('Some of the stories downloaded have failed chapters. Click View Log in the next dialog to see which.'), + show=True, + show_copy_button=False) + if merge: if len(good_list) < 1: - info_dialog(self.gui, _('No Good Stories for Anthology'), + info_dialog(self.gui, _('FanFicFare: ')+_('No Good Stories for Anthology'), _('No good stories/updates where downloaded, Anthology creation/update aborted.'), show=True, show_copy_button=False) diff --git a/calibre-plugin/jobs.py b/calibre-plugin/jobs.py index f405dfb6b..48af08bf4 100644 --- a/calibre-plugin/jobs.py +++ b/calibre-plugin/jobs.py @@ -247,7 +247,16 @@ def do_download_for_worker(book,options,merge,notification=lambda x,y:x): inject_cal_cols(book,story,configuration) writer.writeStory(outfilename=outfile, forceOverwrite=True) - book['comment'] = _('Download %s completed, %s chapters.')%(options['fileform'],story.getMetadata("numChapters")) + if adapter.story.chapter_error_count > 0: + book['comment'] = _('Download %(fileform)s completed, %(failed)s failed chapters, %(total)s total chapters.')%\ + {'fileform':options['fileform'], + 'failed':adapter.story.chapter_error_count, + 'total':story.getMetadata("numChapters")} + book['chapter_error_count'] = adapter.story.chapter_error_count + else: + book['comment'] = _('Download %(fileform)s completed, %(total)s chapters.')%\ + {'fileform':options['fileform'], + 'total':story.getMetadata("numChapters")} book['all_metadata'] = story.getAllMetadata(removeallentities=True) if options['savemetacol'] != '': book['savemetacol'] = story.dump_html_metadata() @@ -297,8 +306,13 @@ def do_download_for_worker(book,options,merge,notification=lambda x,y:x): inject_cal_cols(book,story,configuration) writer.writeStory(outfilename=outfile, forceOverwrite=True) - book['comment'] = _('Update %(fileform)s completed, added %(added)s chapters for %(total)s total.')%\ - {'fileform':options['fileform'],'added':(urlchaptercount-chaptercount),'total':urlchaptercount} + if adapter.story.chapter_error_count > 0: + book['comment'] = _('Update %(fileform)s completed, added %(added)s chapters, %(failed)s failed chapters, for %(total)s total.')%\ + {'fileform':options['fileform'],'added':(urlchaptercount-chaptercount),'total':urlchaptercount} + book['chapter_error_count'] = adapter.story.chapter_error_count + else: + book['comment'] = _('Update %(fileform)s completed, added %(added)s chapters for %(total)s total.')%\ + {'fileform':options['fileform'],'added':(urlchaptercount-chaptercount),'total':urlchaptercount} book['all_metadata'] = story.getAllMetadata(removeallentities=True) if options['savemetacol'] != '': book['savemetacol'] = story.dump_html_metadata() diff --git a/fanficfare/adapters/base_adapter.py b/fanficfare/adapters/base_adapter.py index f2115db47..d609533a2 100644 --- a/fanficfare/adapters/base_adapter.py +++ b/fanficfare/adapters/base_adapter.py @@ -255,6 +255,7 @@ def getStory(self): """%(url,traceback.format_exc().replace("&","&").replace(">",">").replace("<","<"))) title = title+self.getConfig("chapter_title_error_mark","(CHAPTER ERROR)") url="chapter url removed due to failure" + self.story.chapter_error_count += 1 else: raise diff --git a/fanficfare/cli.py b/fanficfare/cli.py index 12f2afd29..95e9520fb 100644 --- a/fanficfare/cli.py +++ b/fanficfare/cli.py @@ -521,7 +521,9 @@ def do_download(arg, import json print(json.dumps(metadata, sort_keys=True, indent=2, separators=(',', ':'))) - + if adapter.story.chapter_error_count > 0: + print("%s chapters errored downloading %s"%(adapter.story.chapter_error_count, + url)) del adapter except exceptions.InvalidStoryURL as isu: diff --git a/fanficfare/story.py b/fanficfare/story.py index bafa02001..02285057c 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -476,6 +476,8 @@ def __init__(self, configuration): self.replacements_prepped = False + self.chapter_error_count = 0 + def prepare_replacements(self): if not self.replacements_prepped and not self.is_lightweight(): # logger.debug("prepare_replacements")