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

modules.reverse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 5

3 Functions

Rating   Name   Duplication   Size   Complexity  
A reverse_video() 0 6 1
A reverse() 0 14 2
A module_init() 0 7 2
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