replaywebpage

This commit is contained in:
msramalho
2023-01-22 00:48:09 +00:00
parent 746f6a333e
commit 092ffdb6d8
5 changed files with 36 additions and 26 deletions

View File

@@ -18,7 +18,7 @@ class Step(ABC):
self.__setattr__(k, v) self.__setattr__(k, v)
@staticmethod @staticmethod
def configs() -> dict: {} def configs() -> dict: return {}
def init(name: str, config: dict, child: Type[Step]) -> Step: def init(name: str, config: dict, child: Type[Step]) -> Step:
""" """

View File

@@ -14,7 +14,8 @@ class CLIFeeder(Feeder):
def __init__(self, config: dict) -> None: def __init__(self, config: dict) -> None:
# without this STEP.__init__ is not called # without this STEP.__init__ is not called
super().__init__(config) super().__init__(config)
assert type(self.urls) == list and len(self.urls) > 0, "Please provide a CSV list of URL(s) to process, with --cli_feeder.urls='url1,url2,url3'" if type(self.urls) != list or len(self.urls) == 0:
logger.info(f"CLI Feeder did not receive any URL to process")
@staticmethod @staticmethod
def configs() -> dict: def configs() -> dict:

View File

@@ -4,6 +4,7 @@ from abc import abstractmethod
import mimetypes import mimetypes
from jinja2 import Environment, FileSystemLoader from jinja2 import Environment, FileSystemLoader
import uuid, os, pathlib import uuid, os, pathlib
from urllib.parse import quote
from ..core import Metadata from ..core import Metadata
from ..core import Media from ..core import Media
@@ -18,12 +19,9 @@ class HtmlFormatter(Formatter):
# without this STEP.__init__ is not called # without this STEP.__init__ is not called
super().__init__(config) super().__init__(config)
self.environment = Environment(loader=FileSystemLoader(os.path.join(pathlib.Path(__file__).parent.resolve(), "templates/"))) self.environment = Environment(loader=FileSystemLoader(os.path.join(pathlib.Path(__file__).parent.resolve(), "templates/")))
# JinjaHelper class static methods are added as filters
self.environment.filters.update({ self.environment.filters.update({
'is_list': is_list_jinja, k: v for k, v in JinjaHelpers.__dict__.items() if isinstance(v, staticmethod)
'is_video': is_video_jinja,
'is_image': is_image_jinja,
'is_audio': is_audio_jinja,
'is_media': is_media_jinja,
}) })
self.template = self.environment.get_template("html_template.html") self.template = self.environment.get_template("html_template.html")
@@ -49,25 +47,34 @@ class HtmlFormatter(Formatter):
# JINJA helper filters # JINJA helper filters
class JinjaHelpers:
@staticmethod
def is_list(v) -> bool:
return isinstance(v, list)
def is_list_jinja(v) -> bool: @staticmethod
return isinstance(v, list) def is_video(s: str) -> bool:
m = mimetypes.guess_type(s)[0]
return "video" in (m or "")
@staticmethod
def is_image(s: str) -> bool:
m = mimetypes.guess_type(s)[0]
return "image" in (m or "")
def is_video_jinja(s: str) -> bool: @staticmethod
m = mimetypes.guess_type(s)[0] def is_audio(s: str) -> bool:
return "video" in (m or "") m = mimetypes.guess_type(s)[0]
return "audio" in (m or "")
@staticmethod
def is_media(v) -> bool:
return isinstance(v, Media)
def is_image_jinja(s: str) -> bool: @staticmethod
m = mimetypes.guess_type(s)[0] def get_extension(filename: str) -> str:
return "image" in (m or "") return os.path.splitext(filename)[1]
@staticmethod
def is_audio_jinja(s: str) -> bool: def quote(s: str) -> str:
m = mimetypes.guess_type(s)[0] return quote(s)
return "audio" in (m or "")
def is_media_jinja(v) -> bool:
return isinstance(v, Media)

View File

@@ -125,7 +125,7 @@
<div class="collapsible-content"> <div class="collapsible-content">
{% for subprop in m.properties[prop] %} {% for subprop in m.properties[prop] %}
{% if subprop | is_media %} {% if subprop | is_media %}
{{ macros.display_media(subprop) }} {{ macros.display_media(subprop, false, url) }}
{% else %} {% else %}
{{ subprop }} {{ subprop }}
{% endif %} {% endif %}
@@ -141,7 +141,7 @@
</ul> </ul>
</td> </td>
<td> <td>
{{ macros.display_media(m, true) }} {{ macros.display_media(m, true, url) }}
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}

View File

@@ -1,4 +1,4 @@
{% macro display_media(m, links) -%} {% macro display_media(m, links, main_url) -%}
{% for url in m.urls %} {% for url in m.urls %}
{% if url | length == 0 %} {% if url | length == 0 %}
@@ -17,6 +17,8 @@ No URL available for {{ m.key }}.
<source src="{{ url }}" type="{{ m.mimetype }}"> <source src="{{ url }}" type="{{ m.mimetype }}">
Your browser does not support the audio element. Your browser does not support the audio element.
</audio> </audio>
{% elif m.filename | get_extension == ".wacz" %}
<a href="https://replayweb.page/?source={{ url | quote }}#view=pages&url={{ main_url }}">replayweb</a>
{% else %} {% else %}
No preview available for {{ m.key }}. No preview available for {{ m.key }}.
{% endif %} {% endif %}