fix thumbnails
This commit is contained in:
parent
31a12185f6
commit
8665b98452
@ -1,7 +1,8 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
img_ext = []
|
img_ext = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'ico']
|
||||||
vid_ext = []
|
vid_ext = ['mp4', 'webm', 'm4v', 'ogv', 'avi']
|
||||||
|
txt_ext = ['txt', 'pdf', 'ps']
|
||||||
|
|
||||||
def generate(fname, tname, placeholder):
|
def generate(fname, tname, placeholder):
|
||||||
"""
|
"""
|
||||||
@ -10,13 +11,13 @@ def generate(fname, tname, placeholder):
|
|||||||
ext = fname.split('.')[-1]
|
ext = fname.split('.')[-1]
|
||||||
cmd = None
|
cmd = None
|
||||||
if ext in img_ext:
|
if ext in img_ext:
|
||||||
cmd = ['convert', '-thumbnail', '200', fname, tname]
|
cmd = ['/usr/bin/convert', '-thumbnail', '200', fname, tname]
|
||||||
elif ext in vid_ext:
|
elif ext in vid_ext or ext in txt_ext:
|
||||||
cmd = ['ffmpeg', '-i', fname, '-vf', 'scale=300:200', '-vframes', '1', tname]
|
cmd = ['/usr/bin/ffmpeg', '-i', fname, '-vf', 'scale=300:200', '-vframes', '1', tname]
|
||||||
|
|
||||||
if cmd is None:
|
if cmd is None:
|
||||||
os.link(placeholder, tname)
|
os.link(placeholder, tname)
|
||||||
else:
|
else:
|
||||||
subprocess.call(cmd)
|
subprocess.run(cmd, check=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,14 +69,14 @@ def webhook(request):
|
|||||||
if ctype.startswith("text/plain"):
|
if ctype.startswith("text/plain"):
|
||||||
m += '{} '.format(part.get_payload(decode=True).decode('utf-8'))
|
m += '{} '.format(part.get_payload(decode=True).decode('utf-8'))
|
||||||
else:
|
else:
|
||||||
print(part.get_content_type())
|
|
||||||
payload = part.get_payload(decode=True)
|
payload = part.get_payload(decode=True)
|
||||||
if payload is None:
|
if payload is None:
|
||||||
continue
|
continue
|
||||||
|
filename = part.get_filename()
|
||||||
mtype = part.get_content_type()
|
mtype = part.get_content_type()
|
||||||
ext = mimetypes.guess_extension(mtype) or ''
|
ext = filename.split('.')[-1]
|
||||||
fh = util.hashfile(bytes(payload))
|
fh = util.hashfile(bytes(payload))
|
||||||
fn = fh + ext
|
fn = fh + '.' + ext
|
||||||
fname = os.path.join(settings.MEDIA_ROOT, fn)
|
fname = os.path.join(settings.MEDIA_ROOT, fn)
|
||||||
if not os.path.exists(fname):
|
if not os.path.exists(fname):
|
||||||
with open(fname, 'wb') as f:
|
with open(fname, 'wb') as f:
|
||||||
@ -88,7 +88,7 @@ def webhook(request):
|
|||||||
|
|
||||||
att = Attachment(filehash=fh)
|
att = Attachment(filehash=fh)
|
||||||
att.mimetype = mtype
|
att.mimetype = mtype
|
||||||
att.filename = part.get_filename()
|
att.filename = filename
|
||||||
att.save()
|
att.save()
|
||||||
atts.append(att)
|
atts.append(att)
|
||||||
post.message = m
|
post.message = m
|
||||||
|
Reference in New Issue
Block a user