pull/72/head
msramalho 2023-01-22 00:48:09 +00:00
rodzic 746f6a333e
commit 092ffdb6d8
5 zmienionych plików z 36 dodań i 26 usunięć

Wyświetl plik

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

Wyświetl plik

@ -14,7 +14,8 @@ class CLIFeeder(Feeder):
def __init__(self, config: dict) -> None:
# without this STEP.__init__ is not called
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
def configs() -> dict:

Wyświetl plik

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

Wyświetl plik

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

Wyświetl plik

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