Skip to content

Instantly share code, notes, and snippets.

@Kylmakalle
Last active July 28, 2017 18:42
Show Gist options
  • Save Kylmakalle/6b7c91504b928bfc0d48632af49f5ec2 to your computer and use it in GitHub Desktop.
Save Kylmakalle/6b7c91504b928bfc0d48632af49f5ec2 to your computer and use it in GitHub Desktop.
# from moviepy.editor import *
# import telebot
# import threading
# ...receive message with link to .webm...
def convert_webm_to_mp4(message, m):
video = VideoFileClip(m.group(0))
converting = bot.reply_to(message, '<i>Конвертирую...</i>', parse_mode='HTML')
bot.send_chat_action(message.chat.id, 'upload_video')
filename = "{}.mp4".format(str(message.chat.id)[1:] + '_' + str(message.message_id))
video.write_videofile(filename, fps=25, preset='ultrafast')
openedfile = open(filename, 'rb')
bot.send_video(message.chat.id, openedfile, reply_to_message_id=message.message_id)
bot.delete_message(message.chat.id, converting.message_id)
openedfile.close()
os.remove(filename)
def webm_to_mp4(message):
if message.entities is not None:
for entity in message.entities:
if entity.type == 'url':
m = re.search('https://2ch\.(?:hk|pm)/[a-z]*/src/[0-9]*/[0-9]*\.webm',
message.text[entity.offset:entity.offset + entity.length])
if m:
t = threading.Thread(
name="{}.webm".format(str(message.chat.id)[1:] + '_' + str(message.message_id)),
target=convert_webm_to_mp4,
args=(message, m,))
t.setDaemon(True)
t.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment