upload mp4s to tumblr as gifs (fixes #7)

This commit is contained in:
Tomáš Mládek 2019-05-31 19:43:22 +02:00
parent 45a7594ef3
commit a33e341794

View file

@ -6,6 +6,7 @@ import os
import pprint import pprint
import re import re
import shutil import shutil
import subprocess
import sys import sys
import tempfile import tempfile
import unicodedata import unicodedata
@ -332,8 +333,16 @@ class DelojzaBot:
now = cmd_hashtag == 'TUMBLR_NOW' now = cmd_hashtag == 'TUMBLR_NOW'
reply = '(btw, {})'.format("***FIRING TO TUMBLR RIGHT AWAY***" if now else "queueing to tumblr") reply = '(btw, {})'.format("***FIRING TO TUMBLR RIGHT AWAY***" if now else "queueing to tumblr")
message.reply_text(reply, parse_mode=telegram.ParseMode.MARKDOWN) message.reply_text(reply, parse_mode=telegram.ParseMode.MARKDOWN)
for filetitle in filenames: for filename in filenames:
response = self.tumblr_client.create_photo(self.tumblr_name, data=filetitle, 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") state="published" if now else "queue")
if 'id' in response: if 'id' in response:
tumblr_ids.append(response['id']) tumblr_ids.append(response['id'])