From 25312029aa3516f0144eb4f6557fe4ca7d5e5bd8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 11 Mar 2023 08:29:52 +0200 Subject: [PATCH] add poster_url for videos --- files/classes/submission.py | 8 ++++++++ files/routes/posts.py | 8 ++++++-- files/templates/submission.html | 2 +- files/templates/submission_listing.html | 2 +- migrations/20230311-add-poster-url.sql | 1 + 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 migrations/20230311-add-poster-url.sql diff --git a/files/classes/submission.py b/files/classes/submission.py index 7959c2c9d..bea221810 100644 --- a/files/classes/submission.py +++ b/files/classes/submission.py @@ -26,6 +26,7 @@ class Submission(Base): edited_utc = Column(Integer, default=0) created_utc = Column(Integer) thumburl = Column(String) + posterurl = Column(String) is_banned = Column(Boolean, default=False) bannedfor = Column(String) chuddedfor = Column(String) @@ -162,6 +163,13 @@ class Submission(Base): return f"{SITE_FULL}/i/{SITE_NAME}/site_preview.webp?v=3009" else: return f"{SITE_FULL}/i/default_thumb_link.webp?v=1" + @property + @lazy + def poster_url(self): + if self.posterurl: return self.posterurl + if self.thumburl: return self.thumburl + return None + @lazy def json(self, db:scoped_session): if self.is_banned: diff --git a/files/routes/posts.py b/files/routes/posts.py index 51435a1ed..e2aef59eb 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -629,9 +629,13 @@ def submit_post(v:User, sub=None): p.url = process_video(file, v) name = f'/images/{time.time()}'.replace('.','') + '.webp' subprocess.run(['ffmpeg', '-y', '-loglevel', 'warning', - '-i', p.url, '-vf', "scale='min(500,iw)':-2", + '-i', p.url, '-vf', "scale='iw':-2", '-q:v', '3', '-frames:v', '1', name], check=True) - p.thumburl = name + p.posterurl = name + + name2 = name.replace('.webp', 'r.webp') + copyfile(name, name2) + p.thumburl = process_image(name2, v, resize=99) elif file.content_type.startswith('audio/'): p.url = process_audio(file, v) else: diff --git a/files/templates/submission.html b/files/templates/submission.html index 27f9c95da..94edd8352 100644 --- a/files/templates/submission.html +++ b/files/templates/submission.html @@ -137,7 +137,7 @@

- +

diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 706082ad7..18a5bf25b 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -225,7 +225,7 @@ {% if p.is_video %}

- +

{% elif p.is_audio %} diff --git a/migrations/20230311-add-poster-url.sql b/migrations/20230311-add-poster-url.sql new file mode 100644 index 000000000..1dccf4456 --- /dev/null +++ b/migrations/20230311-add-poster-url.sql @@ -0,0 +1 @@ +alter table submissions add column posterurl varchar(200);