From 0e7ddd4c53ece663e9aa18047ec3c279a770e76b Mon Sep 17 00:00:00 2001 From: Faraphel Date: Mon, 22 Jan 2024 22:18:27 +0100 Subject: [PATCH] stabilised a bit the replay by using the live page instead of the archive when not found --- setup.py | 21 +++++++++---- tools/__init__.py | 0 tools/web_replay/__init__.py | 0 tools/web_replay/main.py | 6 ++-- tools/web_replay/ui/ReplayEngine.py | 4 +-- tools/web_replay/ui/ReplayWebEngineView.py | 35 +++++++++++++--------- 6 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 tools/__init__.py create mode 100644 tools/web_replay/__init__.py diff --git a/setup.py b/setup.py index ceb3b19..5c692b2 100644 --- a/setup.py +++ b/setup.py @@ -22,16 +22,25 @@ setup( "build_exe": { "include_msvcr": True, "include_files": [ + ("./tools/", "./tools/"), ("./assets/", "./assets/"), ("./README.md", "./README.md"), ] } }, - executables=[Executable( - "main.py", - base=base, - target_name=__appname__, - icon=__icon_ico__ - )] + executables=[ + Executable( + "main.py", + base=base, + target_name=__appname__, + icon=__icon_ico__ + ), + Executable( + "tools/web_replay/main.py", + base=base, + target_name="tools/web_replay/main", + icon=__icon_ico__ + ), + ] ) diff --git a/tools/__init__.py b/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/web_replay/__init__.py b/tools/web_replay/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/web_replay/main.py b/tools/web_replay/main.py index 368cc5a..9c884f9 100644 --- a/tools/web_replay/main.py +++ b/tools/web_replay/main.py @@ -1,10 +1,8 @@ -import json import sys -from datetime import datetime -from PyQt6.QtWidgets import QApplication, QFileDialog +from PyQt6.QtWidgets import QApplication -from tools.web_replay.ui import ReplayWindow +from ui import ReplayWindow if __name__ == "__main__": diff --git a/tools/web_replay/ui/ReplayEngine.py b/tools/web_replay/ui/ReplayEngine.py index d5e4149..1fa6f1c 100644 --- a/tools/web_replay/ui/ReplayEngine.py +++ b/tools/web_replay/ui/ReplayEngine.py @@ -7,7 +7,7 @@ from PyQt6.QtGui import QKeyEvent, QMouseEvent from PyQt6.QtWidgets import QWidget, QVBoxLayout, QApplication, QLabel from source.utils import compress -from tools.web_replay.ui import ReplayWebEngineView, ReplayNavigation +from . import ReplayWebEngineView, ReplayNavigation class ReplayEngine(QWidget): @@ -186,6 +186,6 @@ class ReplayEngine(QWidget): # prepare the timer to play the event at the corresponding time self.timer.singleShot( - round((next_time - self.replay_time) / 1000), + round((next_time - self.replay_time) / 200), self.next ) diff --git a/tools/web_replay/ui/ReplayWebEngineView.py b/tools/web_replay/ui/ReplayWebEngineView.py index c53065f..6c8eba4 100644 --- a/tools/web_replay/ui/ReplayWebEngineView.py +++ b/tools/web_replay/ui/ReplayWebEngineView.py @@ -1,4 +1,5 @@ from datetime import datetime +from typing import Optional from PyQt6.QtCore import QObject, QEvent, QUrl from PyQt6.QtWebEngineWidgets import QWebEngineView @@ -9,21 +10,25 @@ class ReplayWebEngineView(QWebEngineView): super().__init__() self.start_time = start_time + self._last_url: Optional[QUrl] = None self.loadFinished.connect(self._initialize_proxy_event) # NOQA: connect exist # event filter - def setUrl(self, url: QUrl) -> None: - # get the archive.org link corresponding to that time - archive_time: str = self.start_time.strftime("%Y%m%d%H%M%S") - archive_url = f"https://web.archive.org/web/{archive_time}/{url.toString()}" + def setUrl(self, url: QUrl, archive: bool = True) -> None: + if archive: + # get the archive.org link corresponding to that time + archive_time: str = self.start_time.strftime("%Y%m%d%H%M%S") + url = QUrl(f"https://web.archive.org/web/{archive_time}/{url.toString()}") + + self._last_url = url # call the super function with the archive url instead - super().setUrl(QUrl(archive_url)) + super().setUrl(url) # clean the archive header popup that will appear - self.loadFinished.connect(self._clean_archive_header) # NOQA: connect exist + self.loadFinished.connect(self._on_load_finished) # NOQA: connect exist def eventFilter(self, obj: QObject, event: QEvent) -> bool: match event.type(): @@ -44,16 +49,18 @@ class ReplayWebEngineView(QWebEngineView): # events - def _initialize_proxy_event(self, ok: bool): - # prevent the event from being enabled another time - self.loadFinished.disconnect(self._initialize_proxy_event) # NOQA: disconnect exist - + def _initialize_proxy_event(self): # make self.eventFilter intercept all focusProxy events self.focusProxy().installEventFilter(self) - def _clean_archive_header(self, ok: bool): + def _on_load_finished(self, ok: bool): # prevent the event from being enabled another time - self.loadFinished.disconnect(self._clean_archive_header) # NOQA: disconnect exist + self.loadFinished.disconnect(self._on_load_finished) # NOQA: disconnect exist - # hide archive.org header to avoid mouse movement being shifted - self.page().runJavaScript("document.getElementById('wm-ipp-base').style.display = 'none';") + if ok: + # hide archive.org header to avoid mouse movement being shifted + self.page().runJavaScript("document.getElementById('wm-ipp-base').style.display = 'none';") + self._initialize_proxy_event() + + else: + self.setUrl(self._last_url, archive=False)