Add check when adding a new sound, add readme and rename main file

This commit is contained in:
Artlef 2023-05-08 15:11:57 +02:00
parent f9b53454d5
commit 51bda764fa
2 changed files with 8 additions and 4 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
usage:
./toitadesbot.py TOKEN

View File

@ -11,7 +11,7 @@ from pydub import AudioSegment
from discord.ext import commands
if len(sys.argv) < 2:
print("./main.py TOKEN")
print("./toitadesbot.py TOKEN")
exit(1)
sounds_folder = 'Sounds'
@ -36,8 +36,11 @@ async def play(ctx, arg):
@bot.command()
async def add(ctx, name, url, start, end):
if os.path.isfile(computePath(name)):
await ctx.send("Ce nom est déjà utilisé, merci d'en choisir un autre.")
return
downloadAndCutVideo(url, name, start, end)
await ctx.send("Téléchargé !")
await play(name)
@bot.command()
async def remove(ctx, name):
@ -62,12 +65,11 @@ def downloadAndCutVideo(url, filename, start = -1, end = -1):
tmpFilename = filename + "tmp"
downloadVideo(url, tmpFilename)
song = AudioSegment.from_mp3(computePath(tmpFilename))
if start != -1:
start = start * 1000
if end != -1:
end = end * 1000
cutted_song = song[start:end].export(computePath(filename), format="mp3")
song[start:end].export(computePath(filename), format="mp3")
os.remove(computePath(tmpFilename))
def downloadVideo(url, filename):