From 4cbad50c0d8327772a512a7622c3d73eecdfc73d Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Fri, 29 Oct 2021 05:33:37 +0200 Subject: [PATCH] yt timestamps --- files/helpers/sanitize.py | 6 ++++-- files/routes/comments.py | 2 -- files/routes/posts.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py index 05122b70c..426df3d60 100755 --- a/files/helpers/sanitize.py +++ b/files/helpers/sanitize.py @@ -201,9 +201,11 @@ def sanitize(sanitized, noimages=False): for i in re.finditer('" target="_blank">(https://youtube.com/watch\?v\=.*?)', sanitized): url = i.group(1) replacing = f'{url}' + url = url.replace("watch?v=", "embed/").replace("&t", "?start").replace("?t", "?start") + url = re.sub('(\?start=([0-9]*?))s', r'\1', url) htmlsource = f'' - sanitized = sanitized.replace(replacing, htmlsource.replace("watch?v=", "embed/")) - + sanitized = sanitized.replace(replacing, htmlsource) + for i in re.finditer('{url}' diff --git a/files/routes/comments.py b/files/routes/comments.py index 83e65521e..f45202176 100755 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -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() diff --git a/files/routes/posts.py b/files/routes/posts.py index a3d77d445..a6d7923d4 100755 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -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