upload mp4s to tumblr as gifs (fixes #7)

neu
Tomáš Mládek 2019-05-31 19:43:22 +02:00
parent 45a7594ef3
commit a33e341794
1 changed files with 11 additions and 2 deletions

View File

@ -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'])