Esempio n. 1
0
 def youtube(self, src, alt="", title=None):
     youtube_match = YOUTUBE_RE.match(src)
     video_tag = (
         f'<span class="ratio-16-9">'
         f'<iframe src="https://www.youtube.com/embed/{escape_html(youtube_match.group(1))}'
         f'?autoplay=0&amp;controls=1&amp;showinfo=1&amp;vq=hd1080" frameborder="0"></iframe>'
         f"</span>")
     caption = f"<figcaption>{escape_html(title)}</figcaption>" if title else ""
     return f"<figure>{video_tag}{caption}</figure>"
Esempio n. 2
0
    def link(self, link, text=None, title=None):
        if IMAGE_RE.match(link):
            return self.image(link, text or "", title or "")

        if YOUTUBE_RE.match(link):
            return self.youtube(link, text, title)

        if VIDEO_RE.match(link):
            return self.video(link, text, title)

        if TWITTER_RE.match(link):
            return self.tweet(link, text, title)

        return super().link(link, text, title)
Esempio n. 3
0
    def embed(self, src, alt="", title=None):
        if IMAGE_RE.match(src):
            return self.simple_image(src, alt, title)

        if YOUTUBE_RE.match(src):
            return self.youtube(src, alt, title)

        if VIDEO_RE.match(src):
            return self.video(src, alt, title)

        if TWITTER_RE.match(src):
            return self.tweet(src, alt, title)

        return None
Esempio n. 4
0
 def youtube(self, src, alt="", title=None):
     youtube_match = YOUTUBE_RE.match(src)
     playlist = ""
     if youtube_match.group(2):
         playlist = f"list={escape_html(youtube_match.group(2))}&listType=playlist&"
     video_tag = (
         f'<span class="ratio-16-9">'
         f'<iframe loading="lazy" src="https://www.youtube.com/embed/{escape_html(youtube_match.group(1) or "")}'
         f'?{playlist}autoplay=0&amp;controls=1&amp;showinfo=1&amp;vq=hd1080"'
         f'allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; fullscreen"'
         f'allowfullscreen></iframe>'
         f"</span>")
     caption = f"<figcaption>{escape_html(title)}</figcaption>" if title else ""
     return f"<figure>{video_tag}{caption}</figure>"
Esempio n. 5
0
    def image(self, src, alt="", title=None):
        if IMAGE_RE.match(src):
            return self.just_img(src, alt, title)

        if YOUTUBE_RE.match(src):
            return self.youtube(src, alt, title)

        if VIDEO_RE.match(src):
            return self.video(src, alt, title)

        if TWITTER_RE.match(src):
            return self.tweet(src, alt, title)

        # if its not an image or video, display as a link
        return f'<a href="{src}">{src}</a>'
Esempio n. 6
0
def youtube_id(value):
    youtube_match = YOUTUBE_RE.match(value)
    if youtube_match:
        return youtube_match.group(1)
    return ""
Esempio n. 7
0
 def youtube(self, src, alt="", title=None):
     youtube_match = YOUTUBE_RE.match(src)
     youtube_id = escape_html(youtube_match.group(1) or "")
     return f'<a href="{escape_html(src)}"><span class="ratio-16-9 video-preview" ' \
            f'style="background-image: url(\'https://img.youtube.com/vi/{escape_html(youtube_id)}/0.jpg\');">' \
            f'</span></a><br>{escape_html(title or "")}'
Esempio n. 8
0
    "youtube.com": """<i class="fab fa-youtube"></i>""",
    "youtu.be": """<i class="fab fa-youtube"></i>""",
    "github.com": """<i class="fab fa-github"></i>""",
    "twitter.com": """<i class="fab fa-twitter"></i>""",
    "facebook.com": """<i class="fab fa-facebook"></i>""",
    "www.patreon.com": """<i class="fab fa-patreon"></i>""",
    "apple.com": """<i class="fab fa-apple"></i>""",
    "vk.com": """<i class="fab fa-vk"></i>""",
    "medium.com": """<i class="fab fa-medium"></i>""",
}

CUSTOM_PARSERS = {
    "www.youtube.com": {
        "template": loader.get_template("posts/embeds/youtube.html"),
        "data": lambda post: {
            "src":
            YOUTUBE_RE.match(post.url).group(1)
            if YOUTUBE_RE.match(post.url) else None
        }
    },
    "github.com": {
        "template": loader.get_template("posts/embeds/github.html"),
        "data": lambda post: {
            "metadata": post.metadata
        }
    },
    "www.patreon.com": {
        "do_not_parse": True
    },
}
Esempio n. 9
0
CUSTOM_ICONS = {
    "www.youtube.com": """<i class="fab fa-youtube"></i>""",
    "youtube.com": """<i class="fab fa-youtube"></i>""",
    "youtu.be": """<i class="fab fa-youtube"></i>""",
    "github.com": """<i class="fab fa-github"></i>""",
    "twitter.com": """<i class="fab fa-twitter"></i>""",
    "facebook.com": """<i class="fab fa-facebook"></i>""",
    "www.patreon.com": """<i class="fab fa-patreon"></i>""",
    "apple.com": """<i class="fab fa-apple"></i>""",
    "vk.com": """<i class="fab fa-vk"></i>""",
    "medium.com": """<i class="fab fa-medium"></i>""",
}

CUSTOM_PARSERS = {
    "www.youtube.com": {
        "template": loader.get_template("posts/embeds/youtube.html"),
        "data": lambda post: {
            "src": YOUTUBE_RE.match(post.url).group(1)
        }
    },
    "github.com": {
        "template": loader.get_template("posts/embeds/github.html"),
        "data": lambda post: {
            "metadata": post.metadata
        }
    },
    "www.patreon.com": {
        "do_not_parse": True
    },
}