From d06275a6b092d61ad32ca11027abb9a1cc447db2 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 12 Jul 2024 18:43:25 +0200 Subject: [PATCH] Extract as title should work on all processors --- .../processors/text_json_diff/processor.py | 6 ------ changedetectionio/update_worker.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/changedetectionio/processors/text_json_diff/processor.py b/changedetectionio/processors/text_json_diff/processor.py index 1dc501a2..1de5bafb 100644 --- a/changedetectionio/processors/text_json_diff/processor.py +++ b/changedetectionio/processors/text_json_diff/processor.py @@ -338,12 +338,6 @@ class perform_site_check(difference_detection_processor): if blocked: changed_detected = False - # Extract title as title - if is_html: - if self.datastore.data['settings']['application'].get('extract_title_as_title') or watch['extract_title_as_title']: - if not watch['title'] or not len(watch['title']): - update_obj['title'] = html_tools.extract_element(find='title', html_content=self.fetcher.content) - logger.debug(f"Watch UUID {watch.get('uuid')} content check - Previous MD5: {watch.get('previous_md5')}, Fetched MD5 {fetched_md5}") if changed_detected: diff --git a/changedetectionio/update_worker.py b/changedetectionio/update_worker.py index a5af5c2b..fee09c5d 100644 --- a/changedetectionio/update_worker.py +++ b/changedetectionio/update_worker.py @@ -505,6 +505,16 @@ class update_worker(threading.Thread): if update_handler.xpath_data: watch.save_xpath_data(data=update_handler.xpath_data) + # Extract <title> as title if possible/requested. + if self.datastore.data['settings']['application'].get('extract_title_as_title') or watch['extract_title_as_title']: + if not watch['title'] or not len(watch['title']): + try: + update_obj['title'] = html_tools.extract_element(find='title', html_content=update_handler.fetcher.content) + logger.info(f"UUID: {uuid} Extract <title> updated title to '{update_obj['title']}") + except Exception as e: + logger.warning(f"UUID: {uuid} Extract <title> as watch title was enabled, but couldn't find a <title>.") + + # Now update after running everything try: self.datastore.update_watch(uuid=uuid, update_obj=update_obj)