-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
145 lines (115 loc) · 6.36 KB
/
Copy pathmain.py
File metadata and controls
145 lines (115 loc) · 6.36 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import discord
import os
import time
import json
client = discord.Client()
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
with open('data.json') as json_file: #Check if bot is alredy working
data = json.load(json_file)
if message.author == client.user:
return
if message.content.startswith('!about'):
await message.channel.send('Created by EpicMario71, source code: https://github.com/epicmario7133/Video-to-mp3-bot-discord')
if str(message.attachments) == "[]": # Checks if there is an attachment on the message
return
if data["work"] == "1": #Check if bot is working
await message.channel.send('Bot is working please wait')
pass
else: # If there is it gets the filename from message.attachments
split_v1 = str(message.attachments).split("filename='")[1]
filename = str(split_v1).split("' ")[0]
if filename.endswith(".mp4"): # Checks if it is a .mp4 file
await message.channel.send('Starting')
data["work"] = "1"
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.attachments[0].save(fp="mp4/{}".format("video.mp4")) #save flie
await message.channel.send('I\'m converting the video give me 10 seconds')
os.system("ffmpeg -i /home/ubuntu/bot-mp3/mp4/video.mp4 -y /home/ubuntu/bot-mp3/mp3/audio.mp3") #convert whit ffmpeg (-y to overwrite old file)
time.sleep(10) #Give time for bot to convert, set 20 if your pc is a potato
await message.channel.send(file=discord.File("/home/ubuntu/bot-mp3/mp3/audio.mp3")) #Send file
time.sleep(3) #Wait bot upload file
data["work"] = "0" #set bot to ready
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.channel.send('Now the bot is ready')
#Convert .mov
if str(message.attachments) == "[]": # Checks if there is an attachment on the message
return
if data["work"] == "1": #Check if bot is working
await message.channel.send('Bot is working please wait')
pass
else: # If there is it gets the filename from message.attachments
split_v1 = str(message.attachments).split("filename='")[1]
filename = str(split_v1).split("' ")[0]
if filename.endswith(".mov"): # Checks if it is a .mov file
await message.channel.send('Starting')
data["work"] = "1"
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.attachments[0].save(fp="mov/{}".format("video.mov")) #save flie
await message.channel.send('I\'m converting the video give me 10 seconds')
os.system("ffmpeg -i /home/ubuntu/bot-mp3/mov/video.mov -y /home/ubuntu/bot-mp3/mp3/audio.mp3") #convert whit ffmpeg
time.sleep(10) #Give time for bot to convert, set 20 if your pc is a potato
await message.channel.send(file=discord.File("/home/ubuntu/bot-mp3/mp3/audio.mp3")) #Send file
time.sleep(3) #Wait bot upload file
data["work"] = "0" #set bot to ready
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.channel.send('Now the bot is ready')
#for avi video
if str(message.attachments) == "[]": # Checks if there is an attachment on the message
return
if data["work"] == "1": #Check if bot is working
await message.channel.send('Bot is working please wait')
pass
else: # If there is it gets the filename from message.attachments
split_v1 = str(message.attachments).split("filename='")[1]
filename = str(split_v1).split("' ")[0]
if filename.endswith(".avi"): # Checks if it is a .avi file
await message.channel.send('Starting')
data["work"] = "1"
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.attachments[0].save(fp="avi/{}".format("video.avi")) #save flie
await message.channel.send('I\'m converting the video give me 10 seconds')
os.system("ffmpeg -i /home/ubuntu/bot-mp3/avi/video.avi -y /home/ubuntu/bot-mp3/mp3/audio.mp3") #convert whit ffmpeg
time.sleep(10) #Give time for bot to convert, set 20 if your pc is a potato
await message.channel.send(file=discord.File("/home/ubuntu/bot-mp3/mp3/audio.mp3")) #Send file
time.sleep(3) #Wait bot upload file
data["work"] = "0" #set bot to ready
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.channel.send('Now the bot is ready')
#for webm video
if str(message.attachments) == "[]": # Checks if there is an attachment on the message
return
if data["work"] == "1": #Check if bot is working
await message.channel.send('Bot is working please wait')
pass
else: # If there is it gets the filename from message.attachments
split_v1 = str(message.attachments).split("filename='")[1]
filename = str(split_v1).split("' ")[0]
if filename.endswith(".webm"): # Checks if it is a .avi file
await message.channel.send('Starting')
data["work"] = "1"
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.attachments[0].save(fp="webm/{}".format("video.webm")) #save flie
await message.channel.send('I\'m converting the video give me 10 seconds')
os.system("ffmpeg -i /home/ubuntu/bot-mp3/webm/video.webm -y /home/ubuntu/bot-mp3/mp3/audio.mp3") #convert whit ffmpeg
time.sleep(10) #Give time for bot to convert, set 20 if your pc is a potato
await message.channel.send(file=discord.File("/home/ubuntu/bot-mp3/mp3/audio.mp3")) #Send file
time.sleep(3) #Wait bot upload file
data["work"] = "0" #set bot to ready
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
await message.channel.send('Now the bot is ready')
client.run(TOKEN)