From a33e3417947cf5e5001fb3d19df62496b8c439ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Fri, 31 May 2019 19:43:22 +0200 Subject: [PATCH] upload mp4s to tumblr as gifs (fixes #7) --- delojza.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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'])