Exemple #1
0
 def check_queue():
     Queue_infile = os.path.isdir("./Queue")
     if Queue_infile is True:
         DIR = os.path.abspath(os.path.realpath("Queue"))
         length = len(os.listdir(DIR))
         still_q = length - 1
         try:
             first_file = os.listdir(DIR)[0]
         except:
             asyncio.run_coroutine_threadsafe(
                 ctx.send("La queue est vide!"), client.loop)
             queues.clear()
             return
         main_location = os.path.dirname(os.path.realpath(__file__))
         song_path = os.path.abspath(
             os.path.realpath("Queue") + "\\" + first_file)
         if length != 0:
             asyncio.run_coroutine_threadsafe(
                 ctx.send(
                     "La musique est finie, la prochaine va être jouée!"
                 ), client.loop)
             asyncio.run_coroutine_threadsafe(
                 ctx.send(f"Liste des musiques restantes: {still_q}"),
                 client.loop)
             song_there = os.path.isfile("")
Exemple #2
0
async def skip(ctx):
    voice = get(client.voice_clients, guild=ctx.guild)

    queues.clear()

    if voice and voice.is_playing():
        print("Music skipped")
        voice.stop()
        await ctx.send("Skipped")
    else:
        print("Nothing to skip")
        await ctx.send("Skip yourself, m**********r")
Exemple #3
0
    async def skip(self, ctx):

        voice = get(self.bot.voice_clients, guild=ctx.guild)

        queues.clear()

        if voice and voice.is_playing():
            print('Music skipped')
            voice.stop()
            await ctx.channel.send('Music skipped')
        else:
            print('Music not playing - failed skipped')
            await ctx.channel.send('Music not playing - failed skipped')
Exemple #4
0
    def check_queue():
        Queue_infile = os.path.isdir("./Queue")
        if Queue_infile is True:
            DIR = os.path.abspath(os.path.realpath("Queue"))
            length = len(os.listdir(DIR))
            still_q = length - 1
            try:
                first_file = os.listdir(DIR)[0]
            except:
                print("Queue is empty\n")
                queues.clear()
                return
            main_location = os.path.dirname(os.path.realpath(__file__))
            song_path = os.path.abspath(
                os.path.realpath("Queue") + "\\" + first_file)
            if length != 0:
                print("Playing next song\n")
                print(f'Songs still in queue: {still_q}')
                song_there = os.path.isfile('song.mp3')
                if song_there:
                    os.remove('song.mp3')
                shutil.move(song_path, main_location)
                for file in os.listdir("./"):
                    if file.endswith('.mp3'):
                        os.rename(file, 'song.mp3')

                voice.play(discord.FFmpegPCMAudio('song.mp3'),
                           after=lambda e: check_queue())
                voice.source = discord.PCMVolumeTransformer(voice.source)
                voice.source.volume = 0.07

            else:
                queues.clear()
                return

        else:
            queues.clear()
            print('No song queued\n')
    def check_queue():
        Queue_infile = os.path.isdir('./Queue')
        if Queue_infile is True:
            filedir = os.path.abspath(os.path.realpath('Queue'))
            length = len(os.listdir(filedir))
            still_q = length - 1
            try:
                first_file = os.listdir(filedir)[0]
            except:
                print('No more queued sond(s)\r\n')
                queues.clear()
                return
            main_location = os.path.dirname(os.path.realpath(__file__))
            song_path = os.path.abspath(
                os.path.realpath('Queue') + '\\' + first_file)
            if length != 0:
                print('Song done, playing next queued\n')
                print(f'Songs still in queue: {still_q}')
                if song_there:
                    os.remove('song.mp3')
                shutil.move(song_path, main_location)
                for file in os.listdir('./'):
                    if file.endswith('.mp3'):
                        os.rename(file, 'song.mp3')

                voice.play(discord.FFmpegPCMAudio('song.mp3'),
                           after=lambda e: check_queue())
                voice.source = discord.PCMVolumeTransformer(voice.source)
                voice.source.volume = 0.07

            else:
                queues.clear()
                return
        else:
            queues.clear()
            print('No Songs were queued befor ending of the last Song\n')
async def play(ctx, url: str):
    def check_queue():
        Queue_infile = os.path.isdir('./Queue')
        if Queue_infile is True:
            filedir = os.path.abspath(os.path.realpath('Queue'))
            length = len(os.listdir(filedir))
            still_q = length - 1
            try:
                first_file = os.listdir(filedir)[0]
            except:
                print('No more queued sond(s)\r\n')
                queues.clear()
                return
            main_location = os.path.dirname(os.path.realpath(__file__))
            song_path = os.path.abspath(
                os.path.realpath('Queue') + '\\' + first_file)
            if length != 0:
                print('Song done, playing next queued\n')
                print(f'Songs still in queue: {still_q}')
                if song_there:
                    os.remove('song.mp3')
                shutil.move(song_path, main_location)
                for file in os.listdir('./'):
                    if file.endswith('.mp3'):
                        os.rename(file, 'song.mp3')

                voice.play(discord.FFmpegPCMAudio('song.mp3'),
                           after=lambda e: check_queue())
                voice.source = discord.PCMVolumeTransformer(voice.source)
                voice.source.volume = 0.07

            else:
                queues.clear()
                return
        else:
            queues.clear()
            print('No Songs were queued befor ending of the last Song\n')

    song_there = os.path.isfile('song.mp3')
    try:
        if song_there:
            os.remove('song.mp3')
            queues.clear()
            print('Remove old song file')
    except PermissionError:
        print('Trying to delete Song file')
        await ctx.channel.send('ERROR: Music playing')
        return

    Queue_infile = os.path.isdir('./Queue')
    try:
        Queue_folder = './Queue'
        if Queue_infile is True:
            print('Remove old Queue Folder')
            shutil.rmtree(Queue_folder)
    except:
        print('No old Queue folder')

    await ctx.channel.send('Getting everything Ready now')

    voice = get(bot.voice_clients, guild=ctx.guild)

    ydl_opts = {
        'format':
        'bestaudio/best',
        'quit':
        True,
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }],
    }

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        print('Downloading audio now\n')
        ydl.download([url])

    for file in os.listdir('./'):
        if file.endswith('.mp3'):
            name = file
            print(f'Renamed File: {file}\n')
            os.rename(file, 'song.mp3')

    voice.play(discord.FFmpegPCMAudio('song.mp3'),
               after=lambda e: check_queue())
    voice.source = discord.PCMVolumeTransformer(voice.source)
    voice.source.volume = 0.07

    name = name.rsplit('-', 2)
    await ctx.channel.send(f'Playing: {name[0]}')
    print('playing\n')
Exemple #7
0
async def play(ctx, url: str):
    def check_queue():
        Queue_infile = os.path.isdir("./Queue")
        if Queue_infile is True:
            DIR = os.path.abspath(os.path.realpath("Queue"))
            length = len(os.listdir(DIR))
            still_q = length - 1
            try:
                first_file = os.listdir(DIR)[0]
            except:
                print("Queue is empty\n")
                queues.clear()
                return
            main_location = os.path.dirname(os.path.realpath(__file__))
            song_path = os.path.abspath(
                os.path.realpath("Queue") + "\\" + first_file)
            if length != 0:
                print("Playing next song\n")
                print(f'Songs still in queue: {still_q}')
                song_there = os.path.isfile('song.mp3')
                if song_there:
                    os.remove('song.mp3')
                shutil.move(song_path, main_location)
                for file in os.listdir("./"):
                    if file.endswith('.mp3'):
                        os.rename(file, 'song.mp3')

                voice.play(discord.FFmpegPCMAudio('song.mp3'),
                           after=lambda e: check_queue())
                voice.source = discord.PCMVolumeTransformer(voice.source)
                voice.source.volume = 0.07

            else:
                queues.clear()
                return

        else:
            queues.clear()
            print('No song queued\n')

    song_there = os.path.isfile('song.mp3')
    try:
        if song_there:
            os.remove('song.mp3')
            queues.clear()
            print('Removed old song file')
    except PermissionError:
        print("Trying to delete old song file, but it's being played")
        await ctx.send("Error: Music playing")
        return

    Queue_infile = os.path.isdir("./Queue")
    try:
        Queue_folder = "./Queue"
        if Queue_infile is True:
            print("Removed old queue folder")
            shutil.rmtree(Queue_folder)
    except:
        print("No old Queue folder")

    await ctx.send("getting everything ready now")

    channel = ctx.message.author.voice.channel
    voice = get(client.voice_clients, guild=ctx.guild)
    if voice and voice.is_connected():
        await voice.move_to(channel)
    else:
        voice = await channel.connect()

    ydl_opts = {
        'format':
        'bestaudio/best',
        'quiet':
        True,
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192'
        }],
    }

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        print("Downloading audio now\n")
        ydl.download([url])

    for file in os.listdir("./"):
        if file.endswith(".mp3"):
            name = file
            print(f"Renamed File: {file}\n")
            os.rename(file, "song.mp3")

    voice.play(discord.FFmpegPCMAudio("song.mp3"),
               after=lambda e: check_queue())
    voice.source = discord.PCMVolumeTransformer(voice.source)
    voice.source.volume = 0.07

    nname = name.rsplit("-", 2)
    await ctx.send(f"Playing: {nname[0]}")
    print("Playing\n")