From c0fcae0076f58c35c8846ecf4493025dee42c01b Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Tue, 13 Sep 2022 13:44:11 +0200 Subject: [PATCH] WIP --- changedetectionio/__init__.py | 31 ++-- changedetectionio/content_fetcher.py | 4 +- changedetectionio/fetch_processor/image.py | 5 + changedetectionio/image_diff.py | 4 +- .../static/images/picture-frame.svg | 149 ++++++++++++++++++ changedetectionio/static/styles/styles.css | 12 ++ changedetectionio/static/styles/styles.scss | 22 ++- changedetectionio/templates/edit.html | 10 +- .../templates/watch-overview.html | 14 +- 9 files changed, 229 insertions(+), 22 deletions(-) create mode 100644 changedetectionio/static/images/picture-frame.svg diff --git a/changedetectionio/__init__.py b/changedetectionio/__init__.py index 060df7ac..f4714c1b 100644 --- a/changedetectionio/__init__.py +++ b/changedetectionio/__init__.py @@ -642,20 +642,23 @@ def changedetection_app(config=None, datastore_o=None): enabled_tabs.append('visual-selector') enabled_tabs.append('text-filters-and-triggers') + if watch.get('fetch_processor') == 'image': + enabled_tabs.append('visual-selector') + output = render_template("edit.html", - uuid=uuid, - watch=watch, - form=form, - enabled_tabs = enabled_tabs, - has_empty_checktime=using_default_check_time, - has_default_notification_urls=True if len(datastore.data['settings']['application']['notification_urls']) else False, - using_global_webdriver_wait=default['webdriver_delay'] is None, current_base_url=datastore.data['settings']['application']['base_url'], emailprefix=os.getenv('NOTIFICATION_MAIL_BUTTON_PREFIX', False), + enabled_tabs = enabled_tabs, + form=form, + has_default_notification_urls=True if len(datastore.data['settings']['application']['notification_urls']) else False, + has_empty_checktime=using_default_check_time, + playwright_enabled=os.getenv('PLAYWRIGHT_DRIVER_URL', False), settings_application=datastore.data['settings']['application'], + using_global_webdriver_wait=default['webdriver_delay'] is None, + uuid=uuid, visualselector_data_is_ready=visualselector_data_is_ready, visualselector_enabled=visualselector_enabled, - playwright_enabled=os.getenv('PLAYWRIGHT_DRIVER_URL', False) + watch=watch, ) return output @@ -809,6 +812,8 @@ def changedetection_app(config=None, datastore_o=None): previous_version = dates[-2] + datastore.set_last_viewed(uuid, time.time()) + output = render_template("diff-image.html", watch=watch, extra_stylesheets=extra_stylesheets, @@ -1074,7 +1079,13 @@ def changedetection_app(config=None, datastore_o=None): new_img = watch.history[watch.newest_history_key] prev_img = watch.history[compare_date] - img = image_diff.render_diff(new_img, prev_img) + try: + img = image_diff.render_diff(new_img, prev_img) + except ValueError as e: + print ("EXCEPTION: Diff image - got exception {} reverting to raw image without rendering difference".format(str(e))) + with open(new_img, 'rb') as f: + img = f.read() + resp = make_response(img) resp.headers['Content-Type'] = 'image/jpeg' @@ -1243,7 +1254,7 @@ def changedetection_app(config=None, datastore_o=None): extras['fetch_processor']=fetch_processor if fetch_processor == 'image': extras['fetch_backend'] = 'html_webdriver' - + new_uuid = datastore.add_watch(url=url, tag=request.form.get('tag').strip(), extras=extras diff --git a/changedetectionio/content_fetcher.py b/changedetectionio/content_fetcher.py index d1c38074..d077081a 100644 --- a/changedetectionio/content_fetcher.py +++ b/changedetectionio/content_fetcher.py @@ -421,9 +421,9 @@ class base_html_playwright(Fetcher): # acceptable screenshot quality here try: # Quality set to 1 because it's not used, just used as a work-around for a bug, no need to change this. - page.screenshot(type='jpeg', clip={'x': 1.0, 'y': 1.0, 'width': 1280, 'height': 1024}, quality=1) + #page.screenshot(type='jpeg', clip={'x': 1.0, 'y': 1.0, 'width': 1280, 'height': 1024}, quality=1) # The actual screenshot - self.screenshot = page.screenshot(type='jpeg', full_page=True, quality=int(os.getenv("PLAYWRIGHT_SCREENSHOT_QUALITY", 72))) + self.screenshot = page.screenshot(type='jpeg', full_page=True, quality=int(os.getenv("PLAYWRIGHT_SCREENSHOT_QUALITY", 82))) except Exception as e: context.close() browser.close() diff --git a/changedetectionio/fetch_processor/image.py b/changedetectionio/fetch_processor/image.py index 8f1f1472..e4dbd1b7 100644 --- a/changedetectionio/fetch_processor/image.py +++ b/changedetectionio/fetch_processor/image.py @@ -89,8 +89,13 @@ class perform_site_check(fetch_processor): if 'image' in fetcher.headers['content-type']: self.contents = fetcher.raw_content else: + # should be element if the filter is set, no? self.contents = fetcher.screenshot + # Used for visual-selector + self.xpath_data = fetcher.xpath_data + self.screenshot = fetcher.screenshot + image = Image.open(io.BytesIO(self.contents)) # @todo different choice? diff --git a/changedetectionio/image_diff.py b/changedetectionio/image_diff.py index 1f033327..77ecb494 100644 --- a/changedetectionio/image_diff.py +++ b/changedetectionio/image_diff.py @@ -33,8 +33,8 @@ def render_diff(fpath_imageA, fpath_imageB): # bounding box on both input images to represent where the two # images differ (x, y, w, h) = cv2.boundingRect(c) - cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 2) - cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 2) + cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 1) + cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 1) #return cv2.imencode('.jpg', imageB)[1].tobytes() return cv2.imencode('.jpg', imageA)[1].tobytes() diff --git a/changedetectionio/static/images/picture-frame.svg b/changedetectionio/static/images/picture-frame.svg new file mode 100644 index 00000000..994de57e --- /dev/null +++ b/changedetectionio/static/images/picture-frame.svg @@ -0,0 +1,149 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/changedetectionio/static/styles/styles.css b/changedetectionio/static/styles/styles.css index 9835c9b0..9376569a 100644 --- a/changedetectionio/static/styles/styles.css +++ b/changedetectionio/static/styles/styles.css @@ -578,3 +578,15 @@ ul { display: inline; height: 26px; vertical-align: middle; } + +#quickwatch-fetch-processor { + color: #fff; + font-size: 80%; } + #quickwatch-fetch-processor ul { + padding: 0px; + list-style-type: none; } + #quickwatch-fetch-processor ul li { + display: inline-block; + margin-right: 1em; } + #quickwatch-fetch-processor ul li label:hover { + cursor: pointer; } diff --git a/changedetectionio/static/styles/styles.scss b/changedetectionio/static/styles/styles.scss index e8b4a6ab..0f5338ab 100644 --- a/changedetectionio/static/styles/styles.scss +++ b/changedetectionio/static/styles/styles.scss @@ -803,4 +803,24 @@ ul { padding: 0.5rem; border-radius: 5px; color: #ff3300; -} \ No newline at end of file +} + +#quickwatch-fetch-processor { + color: #fff; + font-size: 80%; + + ul { + padding: 0px; + list-style-type: none; + li { + display: inline-block; + margin-right: 1em; + label { + &:hover { + cursor: pointer; + } + } + } + } +} + diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index 64f0c5ff..95d59cfa 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -28,9 +28,7 @@ {% if 'visual-selector' in enabled_tabs %}
  • Visual Filter Selector
  • {%endif%} - {% if 'text-filters-and-triggers' in enabled_tabs %}
  • Filters & Triggers
  • - {%endif%}
  • Notifications
  • @@ -158,6 +156,7 @@ User-Agent: wonderbra 1.0") }}
    + {% if 'text-filters-and-triggers' in enabled_tabs %}
    Pro-tips:
      @@ -169,12 +168,14 @@ User-Agent: wonderbra 1.0") }}
    +
    {{ render_checkbox_field(form.check_unique_lines) }} Good for websites that just move the content around, and you want to know when NEW content is added, compares new lines against all history for this watch.
    + {% endif %}
    {% set field = render_field(form.css_filter, placeholder=".class-name or #some-id, or other CSS selector rule.", @@ -201,6 +202,9 @@ User-Agent: wonderbra 1.0") }} href="https://github.com/dgtlmoon/changedetection.io/wiki/CSS-Selector-help">here for more CSS selector help.
    + + {% if 'text-filters-and-triggers' in enabled_tabs %} +
    {{ render_field(form.subtractive_selectors, rows=5, placeholder="header footer @@ -276,6 +280,8 @@ Unavailable") }}
    + + {% endif %}
    diff --git a/changedetectionio/templates/watch-overview.html b/changedetectionio/templates/watch-overview.html index 817f8ff4..cc2629f9 100644 --- a/changedetectionio/templates/watch-overview.html +++ b/changedetectionio/templates/watch-overview.html @@ -15,14 +15,18 @@
    {{ render_simple_field(form.url, placeholder="https://...", required=true) }} {{ render_simple_field(form.tag, value=active_tag if active_tag else '', placeholder="watch group") }} + + {{ render_simple_field(form.watch_submit_button, title="Watch this URL!" ) }} + {{ render_simple_field(form.edit_and_watch_submit_button, title="Edit first then Watch") }} + {% if webdriver_enabled %} -
    - {{ render_field(form.fetch_processor) }} +
    + {{ render_field(form.fetch_processor) }} +
    {% endif %}
    - {{ render_simple_field(form.watch_submit_button, title="Watch this URL!" ) }} - {{ render_simple_field(form.edit_and_watch_submit_button, title="Edit first then Watch") }} +
    @@ -95,7 +99,7 @@ {%if watch.fetch_backend == "html_webdriver" %}{% endif %} - + {%if watch.fetch_processor == "image" %}{% endif %} {% if watch.last_error is defined and watch.last_error != False %}
    {{ watch.last_error }}
    {% endif %}