diff --git a/delojza.py b/delojza.py index f7d0f35..1194b1d 100755 --- a/delojza.py +++ b/delojza.py @@ -6,6 +6,7 @@ import os import pprint import re import shutil +import subprocess import sys import tempfile import unicodedata @@ -332,8 +333,16 @@ class DelojzaBot: now = cmd_hashtag == 'TUMBLR_NOW' reply = '(btw, {})'.format("***FIRING TO TUMBLR RIGHT AWAY***" if now else "queueing to tumblr") message.reply_text(reply, parse_mode=telegram.ParseMode.MARKDOWN) - for filetitle in filenames: - response = self.tumblr_client.create_photo(self.tumblr_name, data=filetitle, + for filename in filenames: + if filename.endswith(".mp4"): + try: + output_filename = filename[:-len(".mp4")] + ".gif" + subprocess.check_output(['ffmpeg', '-i', filename, output_filename]) + filename = output_filename + except subprocess.CalledProcessError: + message.reply_text("Conversion to gif failed, sorry! Check log...") + continue + response = self.tumblr_client.create_photo(self.tumblr_name, data=filename, state="published" if now else "queue") if 'id' in response: tumblr_ids.append(response['id'])