[Sync] Added Marker (refactored Kazimir)
This commit is contained in:
1 parent
f9f7203b1e
commit
46968ef0cf
5 files changed
+604
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import re
|
||||
from urllib.parse import urlparse
|
||||
from kazimir.Token import UrlToken, is_url
|
||||
|
||||
pattr = re.compile(r'([^(]|^)https?://www\.youtube\.com/watch\?\S*v=(?P<youtubeargs>[A-Za-z0-9_&=-]+)\S*')
|
||||
|
||||
|
||||
class YoutubeToken(UrlToken):
|
||||
@staticmethod
|
||||
def test(data: str):
|
||||
if not is_url(data):
|
||||
return False
|
||||
|
||||
url = urlparse(data)
|
||||
return url.netloc in ['www.youtube.com', 'youtube.com']
|
||||
|
||||
async def compile(self):
|
||||
"""
|
||||
<div class="kazimir__video">
|
||||
<iframe src="http://www.youtube.com/embed/9otNWTHOJi8" frameborder="0" allowfullscreen></iframe>
|
||||
</div>
|
||||
"""
|
||||
|
||||
match = pattr.match(self.data)
|
||||
if match:
|
||||
video_id = match.group(2)
|
||||
url = f'//www.youtube.com/embed/{video_id}'
|
||||
return f'''
|
||||
<div class="kazimir__video"><iframe src="{url}" frameborder="0" allowfullscreen></iframe></div>
|
||||
'''.strip()
|
||||
else:
|
||||
return ''
|
||||
Reference in new issue
Block a user