[Sync] youtube token urlparse based instead of re based
This commit is contained in:
1 parent
73865fcea2
commit
ec73ad0ef2
1 file changed
+12
-12
@@ -1,9 +1,6 @@
|
|||||||
import re
|
from urllib.parse import urlparse, parse_qs
|
||||||
from urllib.parse import urlparse
|
|
||||||
from kazimir.Token import UrlToken, is_url
|
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):
|
class YoutubeToken(UrlToken):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -21,12 +18,15 @@ class YoutubeToken(UrlToken):
|
|||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
match = pattr.match(self.data)
|
url = urlparse(self.data)
|
||||||
if match:
|
query = parse_qs(url.query)
|
||||||
video_id = match.group(2)
|
|
||||||
url = f'//www.youtube.com/embed/{video_id}'
|
if 'v' not in query:
|
||||||
return f'''
|
|
||||||
<div class="kazimir__video"><iframe src="{url}" frameborder="0" allowfullscreen></iframe></div>
|
|
||||||
'''.strip()
|
|
||||||
else:
|
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
video_id = query['v'][0]
|
||||||
|
|
||||||
|
url = f'//www.youtube.com/embed/{video_id}'
|
||||||
|
return f'''
|
||||||
|
<div class="kazimir__video"><iframe src="{url}" frameborder="0" allowfullscreen></iframe></div>
|
||||||
|
'''.strip()
|
||||||
Reference in new issue
Block a user