yt timestamps

master
Aevann1 2021-10-29 05:33:37 +02:00
parent d6406fea6f
commit 4cbad50c0d
3 changed files with 5 additions and 5 deletions

View File

@ -201,9 +201,11 @@ 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>'
url = url.replace("watch?v=", "embed/").replace("&amp;t", "?start").replace("?t", "?start")
url = re.sub('(\?start=([0-9]*?))s', r'\1', url)
htmlsource = f'<iframe class="embedvid" loading="lazy" src="{url}" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
sanitized = sanitized.replace(replacing, htmlsource.replace("watch?v=", "embed/"))
sanitized = sanitized.replace(replacing, htmlsource)
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>'

View File

@ -38,10 +38,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
comment = get_comment(cid, v=v)
if v and request.values.get("read"):
print(1)
notif = g.db.query(Notification).options(lazyload('*')).filter_by(comment_id=cid, user_id=v.id, read=False).first()
if notif:
print(2)
notif.read = True
g.db.add(notif)
g.db.commit()

View File

@ -552,7 +552,7 @@ def submit_post(v):
try:
yt_id = re.match(re.compile("^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|shorts\/|\&v=)([^#\&\?]*).*"), url).group(2)
params = parse_qs(urlparse(url).query)
t = params.get('t', params.get('start', [0]))[0]
t = params.get('t', params.get('start', [0]))[0].replace('s','')
if t: embed = f"https://youtube.com/embed/{yt_id}?start={t}"
else: embed = f"https://youtube.com/embed/{yt_id}"
except: embed = None