Passed
Push — master ( 068d7b...acd31e )
by Anas
05:24 queued 12s
created

modules.reverse.reverse()   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 14
nop 2
dl 0
loc 14
rs 9.7
c 0
b 0
f 0
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
from modules.utils import get_image, send_image
4
from modules.logging import logging_decorator
5
from telegram.ext import PrefixHandler, MessageHandler
6
from telegram.ext.dispatcher import run_async
7
from telegram import ChatAction
8
from datetime import datetime
9
import subprocess
10
import os
11
12
13
def module_init(gd):
14
    global path
15
    path = gd.config["path"]
16
    commands = gd.config["commands"]
17
    for command in commands:
18
        gd.dp.add_handler(MessageHandler(caption_filter, reverse))
19
        gd.dp.add_handler(PrefixHandler("/", command, reverse))
20
21
22
@run_async
23
@logging_decorator("reverse")
24
def reverse(update, context):
25
    filename = datetime.now().strftime("%d%m%y-%H%M%S%f")
26
    try:
27
        extension = get_image(update, context, path, filename)
28
    except:
29
        update.message.reply_text("Can't get the video")
30
        return
31
    update.message.chat.send_action(ChatAction.UPLOAD_PHOTO)
32
    video = reverse_video(path, filename, extension)
33
    send_image(update, path, video, extension)
34
    os.remove(path+filename+extension)
35
    os.remove(path+video+extension)
36
37
38
def reverse_video(path, filename, extension):
39
    new_name = "reversed"
40
    print(path + filename + extension)
41
    args = "ffmpeg -loglevel panic -i " + path + filename + extension + " -vf reverse -af areverse " + path + "reversed" + extension + " -y"
42
    subprocess.run(args, shell=True) 
43
    return new_name