forked from MarseyWorld/MarseyWorld
stop inline video posters from becoming unused when editing comment/post
parent
9d50b43e8a
commit
140318e946
|
@ -6,11 +6,12 @@ from files.classes import Base
|
||||||
|
|
||||||
class Media(Base):
|
class Media(Base):
|
||||||
__tablename__ = "media"
|
__tablename__ = "media"
|
||||||
kind = Column(String, primary_key=True)
|
|
||||||
filename = Column(String, primary_key=True)
|
filename = Column(String, primary_key=True)
|
||||||
|
kind = Column(String)
|
||||||
user_id = Column(Integer, ForeignKey("users.id"))
|
user_id = Column(Integer, ForeignKey("users.id"))
|
||||||
created_utc = Column(Integer)
|
created_utc = Column(Integer)
|
||||||
size = Column(Integer)
|
size = Column(Integer)
|
||||||
|
posterurl = Column(String)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
if "created_utc" not in kwargs: kwargs["created_utc"] = int(time.time())
|
||||||
|
|
|
@ -48,7 +48,6 @@ def media_ratelimit(v):
|
||||||
|
|
||||||
def process_files(files, v, body, is_dm=False, dm_user=None, is_badge_thread=False, comment_body=None):
|
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
|
if g.is_tor or not files.get("file"): return body
|
||||||
g.posterurls = {}
|
|
||||||
|
|
||||||
files = files.getlist('file')[:20]
|
files = files.getlist('file')[:20]
|
||||||
|
|
||||||
|
@ -67,8 +66,7 @@ def process_files(files, v, body, is_dm=False, dm_user=None, is_badge_thread=Fal
|
||||||
if is_badge_thread:
|
if is_badge_thread:
|
||||||
process_badge_entry(name, v, comment_body)
|
process_badge_entry(name, v, comment_body)
|
||||||
elif file.content_type.startswith('video/'):
|
elif file.content_type.startswith('video/'):
|
||||||
url, posterurl, name = process_video(file, v)
|
url, _, _ = process_video(file, v)
|
||||||
g.posterurls[url] = posterurl
|
|
||||||
elif file.content_type.startswith('audio/'):
|
elif file.content_type.startswith('audio/'):
|
||||||
url = f'{SITE_FULL}{process_audio(file, v)}'
|
url = f'{SITE_FULL}{process_audio(file, v)}'
|
||||||
elif has_request_context():
|
elif has_request_context():
|
||||||
|
@ -218,6 +216,7 @@ def process_video(file, v):
|
||||||
name = f'/images/{time.time()}'.replace('.','') + '.webp'
|
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()
|
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
|
posterurl = SITE_FULL_IMAGES + name
|
||||||
|
media.posterurl = posterurl
|
||||||
|
|
||||||
if SITE == 'watchpeopledie.tv' and not is_reencoding:
|
if SITE == 'watchpeopledie.tv' and not is_reencoding:
|
||||||
gevent.spawn(rclone_copy, new)
|
gevent.spawn(rclone_copy, new)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import random
|
||||||
import re
|
import re
|
||||||
from flask import g
|
from flask import g
|
||||||
|
|
||||||
|
from files.classes.media import Media
|
||||||
from .config.const import *
|
from .config.const import *
|
||||||
|
|
||||||
NOT_IN_CODE_OR_LINKS = '(?!([^<]*<\/(code|pre|a)>|[^`\n]*`))'
|
NOT_IN_CODE_OR_LINKS = '(?!([^<]*<\/(code|pre|a)>|[^`\n]*`))'
|
||||||
|
@ -107,10 +108,12 @@ video_sub_regex = re.compile(f'(?<!")(https:\/\/({hosts})\/[\w:~,()\-.#&\/=?@%;+
|
||||||
|
|
||||||
def video_sub_regex_matcher(match):
|
def video_sub_regex_matcher(match):
|
||||||
url = match.group(1)
|
url = match.group(1)
|
||||||
if hasattr(g, 'posterurls'):
|
if url.startswith(SITE_FULL_VIDEOS):
|
||||||
posterurl = g.posterurls.get(url)
|
filename = '/videos/' + url.split(f'{SITE_FULL_VIDEOS}/')[1]
|
||||||
|
g.db.flush()
|
||||||
|
posterurl = g.db.query(Media.posterurl).filter_by(filename=filename).one_or_none()
|
||||||
if posterurl:
|
if posterurl:
|
||||||
return f'<p class="resizable"><video poster="{posterurl}" controls preload="none" src="{url}"></video></p>'
|
return f'<p class="resizable"><video poster="{posterurl[0]}" controls preload="none" src="{url}"></video></p>'
|
||||||
return f'<p class="resizable"><video 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_regex_extensions = '|'.join(AUDIO_FORMATS)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
alter table media add column posterurl varchar(65);
|
||||||
|
alter table media drop constraint media_pkey;
|
||||||
|
alter table media add primary key (filename);
|
Loading…
Reference in New Issue