Archived
1
0

fix thumbnails

This commit is contained in:
Jeff Becker 2016-11-06 08:00:18 -05:00
parent 31a12185f6
commit 8665b98452
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
2 changed files with 11 additions and 10 deletions

View File

@ -1,7 +1,8 @@
import subprocess
import os
img_ext = []
vid_ext = []
img_ext = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'ico']
vid_ext = ['mp4', 'webm', 'm4v', 'ogv', 'avi']
txt_ext = ['txt', 'pdf', 'ps']
def generate(fname, tname, placeholder):
"""
@ -10,13 +11,13 @@ def generate(fname, tname, placeholder):
ext = fname.split('.')[-1]
cmd = None
if ext in img_ext:
cmd = ['convert', '-thumbnail', '200', fname, tname]
elif ext in vid_ext:
cmd = ['ffmpeg', '-i', fname, '-vf', 'scale=300:200', '-vframes', '1', tname]
cmd = ['/usr/bin/convert', '-thumbnail', '200', fname, tname]
elif ext in vid_ext or ext in txt_ext:
cmd = ['/usr/bin/ffmpeg', '-i', fname, '-vf', 'scale=300:200', '-vframes', '1', tname]
if cmd is None:
os.link(placeholder, tname)
else:
subprocess.call(cmd)
subprocess.run(cmd, check=True)

View File

@ -69,14 +69,14 @@ def webhook(request):
if ctype.startswith("text/plain"):
m += '{} '.format(part.get_payload(decode=True).decode('utf-8'))
else:
print(part.get_content_type())
payload = part.get_payload(decode=True)
if payload is None:
continue
filename = part.get_filename()
mtype = part.get_content_type()
ext = mimetypes.guess_extension(mtype) or ''
ext = filename.split('.')[-1]
fh = util.hashfile(bytes(payload))
fn = fh + ext
fn = fh + '.' + ext
fname = os.path.join(settings.MEDIA_ROOT, fn)
if not os.path.exists(fname):
with open(fname, 'wb') as f:
@ -88,7 +88,7 @@ def webhook(request):
att = Attachment(filehash=fh)
att.mimetype = mtype
att.filename = part.get_filename()
att.filename = filename
att.save()
atts.append(att)
post.message = m