add poster images to inline videos
parent
388e8b31f1
commit
80c0ed3959
|
@ -47,6 +47,7 @@ def allowed_attributes(tag, name, value):
|
|||
if name == 'controls' and value == '': return True
|
||||
if name == 'preload' and value == 'none': return True
|
||||
if name == 'src': return is_safe_url(value)
|
||||
if name == 'poster': return is_safe_url(value)
|
||||
|
||||
if tag == 'audio':
|
||||
if name == 'src': return is_safe_url(value)
|
||||
|
|
|
@ -48,6 +48,8 @@ def media_ratelimit(v):
|
|||
|
||||
def process_files(files, v, body, is_dm=False, dm_user=None, is_badge_thread=False, comment_body=None):
|
||||
if g.is_tor or not files.get("file"): return body
|
||||
g.posterurls = {}
|
||||
|
||||
files = files.getlist('file')[:20]
|
||||
|
||||
if files:
|
||||
|
@ -65,7 +67,8 @@ def process_files(files, v, body, is_dm=False, dm_user=None, is_badge_thread=Fal
|
|||
if is_badge_thread:
|
||||
process_badge_entry(name, v, comment_body)
|
||||
elif file.content_type.startswith('video/'):
|
||||
url = process_video(file, v)
|
||||
url, posterurl, name = process_video(file, v)
|
||||
g.posterurls[url] = posterurl
|
||||
elif file.content_type.startswith('audio/'):
|
||||
url = f'{SITE_FULL}{process_audio(file, v)}'
|
||||
elif has_request_context():
|
||||
|
@ -202,14 +205,18 @@ def process_video(file, v):
|
|||
|
||||
if SITE == 'watchpeopledie.tv' and v and v.username.lower().startswith("icosaka"):
|
||||
gevent.spawn(delete_file, new, f'https://videos.{SITE}' + new.split('/videos')[1])
|
||||
return f'https://videos.{SITE}' + new.split('/videos')[1]
|
||||
return f'https://videos.{SITE}' + new.split('/videos')[1], None, None
|
||||
|
||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||
ffmpeg.input(new).output(name, loglevel="quiet", map_metadata=-1, **{"vf":"scale='iw':-2", 'q:v':3, 'frames:v':1}).run()
|
||||
posterurl = SITE_FULL_IMAGES + name
|
||||
|
||||
if SITE == 'watchpeopledie.tv':
|
||||
if not is_reencoding:
|
||||
gevent.spawn(rclone_copy, new)
|
||||
return f'https://videos.{SITE}' + new.split('/videos')[1]
|
||||
return f'https://videos.{SITE}' + new.split('/videos')[1], posterurl, name
|
||||
else:
|
||||
return f"{SITE_FULL}{new}"
|
||||
return f"{SITE_FULL}{new}", posterurl, name
|
||||
|
||||
def process_image(filename, v, resize=0, trim=False, uploader_id=None):
|
||||
# thumbnails are processed in a thread and not in the request context
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import random
|
||||
import re
|
||||
from flask import g
|
||||
|
||||
from .config.const import *
|
||||
|
||||
|
@ -104,6 +105,13 @@ image_check_regex = re.compile(f'!\[\]\(((?!(https:\/\/({hosts})\/|\/)).*?)\)',
|
|||
video_regex_extensions = '|'.join(VIDEO_FORMATS)
|
||||
video_sub_regex = re.compile(f'(?<!")(https:\/\/({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.({video_regex_extensions}))' + NOT_IN_CODE_OR_LINKS, flags=re.A)
|
||||
|
||||
def video_sub_regex_matcher(match):
|
||||
url = match.group(1)
|
||||
posterurl = g.posterurls.get(url)
|
||||
if posterurl:
|
||||
return f'<p class="resizable"><video poster="{posterurl}" controls preload="none" src="{url}"></video></p>'
|
||||
return f'<p class="resizable"><video controls preload="none" src="{url}"></video></p>'
|
||||
|
||||
audio_regex_extensions = '|'.join(AUDIO_FORMATS)
|
||||
audio_sub_regex = re.compile(f'(?<!")(https:\/\/({hosts})\/[\w:~,()\-.#&\/=?@%;+]*?\.({audio_regex_extensions}))' + NOT_IN_CODE_OR_LINKS, flags=re.A)
|
||||
|
||||
|
|
|
@ -489,7 +489,7 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis
|
|||
|
||||
sanitized = sanitized.replace('&','&')
|
||||
|
||||
sanitized = video_sub_regex.sub(r'<p class="resizable"><video controls preload="none" src="\1"></video></p>', sanitized)
|
||||
sanitized = video_sub_regex.sub(video_sub_regex_matcher, sanitized)
|
||||
sanitized = audio_sub_regex.sub(r'<audio controls preload="none" src="\1"></audio>', sanitized)
|
||||
|
||||
if count_emojis:
|
||||
|
|
|
@ -660,15 +660,8 @@ def submit_post(v, hole=None):
|
|||
copyfile(name, name2)
|
||||
p.thumburl = process_image(name2, v, resize=99)
|
||||
elif file.content_type.startswith('video/'):
|
||||
p.url = process_video(file, v)
|
||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
||||
try:
|
||||
x = ffmpeg.input(p.url).output(name, loglevel="quiet", map_metadata=-1, **{"vf":"scale='iw':-2", 'q:v':3, 'frames:v':1}).run()
|
||||
except:
|
||||
if os.path.isfile(name):
|
||||
os.remove(name)
|
||||
else:
|
||||
p.posterurl = SITE_FULL_IMAGES + name
|
||||
p.url, p.posterurl, name = process_video(file, v)
|
||||
if p.posterurl:
|
||||
name2 = name.replace('.webp', 'r.webp')
|
||||
copyfile(name, name2)
|
||||
p.thumburl = process_image(name2, v, resize=99)
|
||||
|
|
Loading…
Reference in New Issue