0.0.1
This commit is contained in:
34
providers/base.py
Normal file
34
providers/base.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import re
|
||||
|
||||
class EmbedProvider:
|
||||
name = "base"
|
||||
pattern = None
|
||||
|
||||
def __init__(self, config=None):
|
||||
self.config = config or {}
|
||||
|
||||
def match(self, content):
|
||||
if not self.pattern:
|
||||
return content
|
||||
return re.sub(self.pattern, self.replace, content)
|
||||
|
||||
def replace(self, match):
|
||||
raise NotImplementedError("Provider replace() missing!")
|
||||
|
||||
def wrap_template(self, provider, embed_html):
|
||||
return f'''
|
||||
<div class="embed-consent" data-provider="{provider}">
|
||||
<div class="embed-overlay">
|
||||
<div class="embed-box">
|
||||
<h3>External Content</h3>
|
||||
<p>This content is provided by <strong>{provider}</strong> and may set cookies.</p>
|
||||
<button class="embed-accept" onclick="acceptProvider('{provider}')">
|
||||
Load Content
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<template class="embed-template">
|
||||
{embed_html}
|
||||
</template>
|
||||
</div>
|
||||
'''
|
||||
18
providers/coub.py
Normal file
18
providers/coub.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from .base import EmbedProvider
|
||||
|
||||
class CoubProvider(EmbedProvider):
|
||||
name = "coub"
|
||||
pattern = r"\{\{COUB:([A-Za-z0-9]+)\}\}"
|
||||
|
||||
def replace(self, match):
|
||||
coub_id = match.group(1)
|
||||
|
||||
embed_html = f'''
|
||||
<iframe src="https://coub.com/embed/{coub_id}"
|
||||
width="640"
|
||||
height="480"
|
||||
frameborder="0"
|
||||
allowfullscreen>
|
||||
</iframe>
|
||||
'''
|
||||
return self.wrap_template("coub", embed_html)
|
||||
15
providers/reddit.py
Normal file
15
providers/reddit.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from .base import EmbedProvider
|
||||
|
||||
class RedditProvider(EmbedProvider):
|
||||
name = "reddit"
|
||||
pattern = r"\{\{REDDIT:(https?://[^\}]+)\}\}"
|
||||
|
||||
def replace(self, match):
|
||||
url = match.group(1)
|
||||
|
||||
embed_html = f'''
|
||||
<blockquote class="reddit-embed-bq" data-embed-locale="en-EN" data-embed-theme="dark" data-embed-showedits="false" data-embed-created="2026-02-25T21:30:20.003Z" data-embed-showusername="false" style="height:500px" data-embed-height="546" >
|
||||
<a href="{url}"></a>
|
||||
</blockquote><script async="" src="https://embed.reddit.com/widgets.js" charset="UTF-8"></script>
|
||||
'''
|
||||
return self.wrap_template("reddit", embed_html)
|
||||
19
providers/youtube.py
Normal file
19
providers/youtube.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from .base import EmbedProvider
|
||||
|
||||
class YouTubeProvider(EmbedProvider):
|
||||
name = "youtube"
|
||||
pattern = r"\{\{YOUTUBE:([A-Za-z0-9_-]+)\}\}"
|
||||
|
||||
def replace(self, match):
|
||||
video_id = match.group(1)
|
||||
nocookie = self.config.get("nocookie", True)
|
||||
domain = "www.youtube-nocookie.com" if nocookie else "www.youtube.com"
|
||||
|
||||
embed_html = f'''
|
||||
<iframe width="560" height="315"
|
||||
src="https://{domain}/embed/{video_id}"
|
||||
frameborder="0"
|
||||
allowfullscreen>
|
||||
</iframe>
|
||||
'''
|
||||
return self.wrap_template("youtube", embed_html)
|
||||
Reference in New Issue
Block a user