This repository has been archived by the owner on Jul 30, 2023. It is now read-only.
forked from shiva20991/Video-Merge-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
109 lines (87 loc) · 2.8 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from logging import DEBUG
import subprocess
import os
import requests
import logging
import sys
from autologging import logged, traced
import telebot
from decouple import config
# Enable logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=DEBUG)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
API_TOKEN = config('API_TOKEN')
bot = telebot.TeleBot(API_TOKEN)
users_files = {}
@bot.message_handler(commands=['start'])
def start_command(message):
keyboard = telebot.types.InlineKeyboardMarkup()
keyboard.add(
telebot.types.InlineKeyboardButton(
'Deployed By', url='telegram.me/Darkridersslk'
)
)
bot.send_message(
message.chat.id,
'Greetings! Video Merge Bot Here 🤗\n\n' +
'To Get Help Press /help',
reply_markup=keyboard
)
@bot.message_handler(content_types=['video'])
def handle_video(message):
"""Add sent video to user's video list."""
chat_id = message.chat.id
if chat_id in users_files:
users_files[chat_id].append(message.video.file_id)
else:
users_files[chat_id] = [message.video.file_id]
@bot.message_handler(commands=['merge'])
def merge(message):
"""Merge user's videos."""
chat_id = message.chat.id
# Stops method if user hasn't sent any videos
if chat_id not in users_files:
bot.send_message(chat_id,
'You Haven\'t Send Any Video For Merge 🥺\n\n'
'Please Send Me Videos First and Press! /merge 🤗'
)
return None
inputs = list()
for i, file_id in enumerate(users_files[chat_id]):
file_info = bot.get_file(file_id)
response = requests.get(
'https://api.telegram.org/file/bot{0}/{1}'.format(
API_TOKEN, file_info.file_path
)
)
inputs.append("file '{}'".format(i))
with open(str(i), 'wb') as arq:
arq.write(response.content)
with open('inputs.txt', 'w') as arq:
arq.write('\n'.join(inputs))
subprocess.call(
['ffmpeg', '-f', 'concat', '-i', 'inputs.txt', '-c', 'copy', 'out.mp4']
)
with open('out.mp4', 'rb') as video:
bot.send_video(chat_id, video)
users_files[chat_id] = []
@bot.message_handler(commands=['help'])
def help_command(message):
keyboard = telebot.types.InlineKeyboardMarkup()
keyboard.add(
telebot.types.InlineKeyboardButton(
'Message The Developer', url='telegram.me/Darkridersslk'
)
)
bot.send_message(
message.chat.id,
'1) Send Two Of Your MP4 Videos (Which You Want To Merge)\n\n' +
'2) After That Press Me! /merge ☺️',
reply_markup=keyboard
)
logger.info("Yeah I'm running!")
bot.polling()