master
Aevann1 2021-10-13 15:10:07 +02:00
parent 241ef545a0
commit d8cfae2402
3 changed files with 10 additions and 10 deletions

View File

@ -121,7 +121,7 @@ def sanitize(sanitized, noimages=False):
tag["class"] = "in-comment-image"
tag["loading"] = "lazy"
tag["data-src"] = tag["src"]
tag["src"] = ""
tag["src"] = "/assets/images/default_thumb_link.webp"
link = soup.new_tag("a")
link["href"] = tag["data-src"]
@ -201,22 +201,22 @@ def sanitize(sanitized, noimages=False):
for i in re.finditer('" target="_blank">(https://youtube.com/watch\?v\=.*?)</a>', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
htmlsource = f'<iframe class="embedvid" loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
htmlsource = f'<iframe class="embedvid" loading="lazy" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
sanitized = sanitized.replace(replacing, htmlsource.replace("watch?v=", "embed/"))
for i in re.finditer('<a href="(https://streamable.com/e/.*?)"', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
htmlsource = f'<iframe class="embedvid" loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
htmlsource = f'<iframe class="embedvid" loading="lazy" data-src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
sanitized = sanitized.replace(replacing, htmlsource)
for i in re.finditer('<p>(https:.*?\.mp4)</p>', sanitized):
sanitized = sanitized.replace(i.group(0), f'<p><video controls loop preload="metadata" class="embedvid"><source src="/assets/images/default_thumb_link.webp" data-src="{i.group(1)}" type="video/mp4"></video>')
sanitized = sanitized.replace(i.group(0), f'<p><video controls loop preload="metadata" class="embedvid"><source data-src="{i.group(1)}" type="video/mp4"></video>')
for i in re.finditer('<a href="(https://open.spotify.com/embed/.*?)"', sanitized):
url = i.group(1)
replacing = f'<a href="{url}" rel="nofollow noopener noreferrer" target="_blank">{url}</a>'
htmlsource = f'<iframe src="/assets/images/default_thumb_link.webp" data-src="{url}" class="spotify" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
htmlsource = f'<iframe data-src="{url}" class="spotify" frameBorder="0" allowtransparency="true" allow="encrypted-media"></iframe>'
sanitized = sanitized.replace(replacing, htmlsource)
for rd in ["https://reddit.com/", "https://new.reddit.com/", "https://www.reddit.com/", "https://redd.it/"]:

View File

@ -6,7 +6,7 @@
{% endblock %}
{% block content %}
<img class="in-comment-image rounded-sm my-2" src="/assets/images/default_thumb_link.webp" data-src="https://media.giphy.com/media/c6Wwc9cT05vMdhyTcM/giphy.webp" loading="lazy" height="100px" rel="nofollow noopener noreferrer" data-placeholder-background="red" style="max-height: 100px; max-width: 100%;">
<img class="in-comment-image rounded-sm my-2" data-src="https://media.giphy.com/media/c6Wwc9cT05vMdhyTcM/giphy.webp" loading="lazy" height="100px" rel="nofollow noopener noreferrer" data-placeholder-background="red" style="max-height: 100px; max-width: 100%;">
<pre>

View File

@ -436,7 +436,7 @@
{% if p.is_image and not p.over_18 and ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}
<div style="text-align: center" class="mt-3 mb-4">
<a target="_blank" rel="nofollow noopener noreferrer" href="{{p.url}}">
<img loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{{p.url}}" class="img-fluid" style="max-height:500px;" alt="Unable to load image">
<img loading="lazy" data-src="{{p.url}}" class="img-fluid" style="max-height:500px;" alt="Unable to load image">
</a>
</div>
{% endif %}
@ -444,16 +444,16 @@
{% if p.url and p.url.lower().endswith('.mp4') %}
<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}d-none{% endif %} mt-4">
<video controls loop preload="metadata" style="max-width: 100%">
<source src="/assets/images/default_thumb_link.webp" data-src="{{p.realurl(v)}}" type="video/mp4">
<source data-src="{{p.realurl(v)}}" type="video/mp4">
</video>
</div>
{% elif p.embed_url and "youtu" in p.domain %}
<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}d-none{% endif %} mt-3 mb-4">
<iframe loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{{p.embed_url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
<iframe loading="lazy" data-src="{{p.embed_url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
</div>
{% elif p.url and "streamable.com/e/" in p.url %}
<div id="video-{{p.id}}" style="text-align: center" class="{% if p.over_18 or not ((v and v.cardview) or (not v and environ.get('CARD_VIEW') == '1')) %}d-none{% endif %} mt-3 mb-4">
<iframe loading="lazy" src="/assets/images/default_thumb_link.webp" data-src="{{p.url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
<iframe loading="lazy" data-src="{{p.url}}" frameborder="0" style="max-width: 100%" width="600" height="337" allow="fullscreen"></iframe>
</div>
{% endif %}
{% endif %}