Ejemplo n.º 1
0
    async def _search(self, ctx: commands.Context, *, search: str):
        """Searches youtube.
        It returns an imbed of the first 10 results collected from youtube.
        Then the user can choose one of the titles by typing a number
        in chat or they can cancel by typing "cancel" in chat.
        Each title in the list can be clicked as a link.
        """
        async with ctx.typing():
            try:
                source = await ytdl.YTDLSource.search_source(
                    self.bot, ctx, search, loop=self.bot.loop)
            except ytdl.YTDLError as e:
                await ctx.send(
                    'An error occurred while processing this request: {}'.
                    format(str(e)))
            else:
                if source == 'sel_invalid':
                    await ctx.send('Invalid selection')
                elif source == 'cancel':
                    await ctx.send(':white_check_mark:')
                elif source == 'timeout':
                    await ctx.send(':alarm_clock: **Time\'s up bud**')
                else:
                    if not ctx.voice_state.voice:
                        await ctx.invoke(self._join)

                    song = voice.Song(source)
                    await ctx.voice_state.songs.put(song)
                    await ctx.send('Enqueued {}'.format(str(source)))
Ejemplo n.º 2
0
    async def _qloop(self, ctx: commands.Context,page: int = 1):

        if len(ctx.voice_state.song_history) == 0:
            return await ctx.send('なにも登録されていません')
            
        ctx.voice_state.qloop = not ctx.voice_state.qloop
        await ctx.send('リストループ機能' + ('on' if ctx.voice_state.qloop else 'off') + 'にしました' )

        items_per_page = 10
        pages = math.ceil(len(ctx.voice_state.songs) / items_per_page)

        start = (page - 1) * items_per_page
        end = start + items_per_page

        queue = []
        for i, song in enumerate(ctx.voice_state.songs[start:end], start=start):
            queue.append('"{1.source.title} "'.format(i + 1, song))
        
        
        while ctx.voice_state.qloop == True:               
            if len(ctx.voice_state.songs) ==  1 :
                for search in queue:     
                    print(search)
                    source = await ytdl.YTDLSource.create_source(ctx, search, loop=self.bot.loop)
                    song = voice.Song(source)
                    await ctx.voice_state.songs.put(song)
                    print("if Trune")
                    await asyncio.sleep(10) 

            else:
                print("else")
                await asyncio.sleep(10)
Ejemplo n.º 3
0
    async def _play(self, ctx: commands.Context, *, search: str):
        """Plays a song.
        If there are songs in the queue, this will be queued until the
        other songs finished playing.
        This command automatically searches from various sites if no URL is provided.
        A list of these sites can be found here: https://rg3.github.io/youtube-dl/supportedsites.html
        """

        async with ctx.typing():
            try:
                print("inside try")
                source = await ytdl.YTDLSource.create_source(
                    ctx, search, loop=self.bot.loop)

            except ytdl.YTDLError as e:
                print("inside try")
                await ctx.send('There is some error my LORDDDDD {}'.format(
                    str(e)))

            else:
                print("inside try")
                if not ctx.voice_state.voice:
                    await ctx.invoke(self._join)

                song = voice.Song(source)
                await ctx.voice_state.songs.put(song)
                messg = await ctx.send(
                    'See this is what i got. Let me know if it is right {}'.
                    format(str(source)))
                await messg.add_reaction('👍')
                await messg.add_reaction('👎')
Ejemplo n.º 4
0
    async def _play(self, ctx: commands.Context, *, search: str):
        """Plays a song.
        If there are songs in the queue, this will be queued until the
        other songs finished playing.
        This command automatically searches from various sites if no URL is provided.
        A list of these sites can be found here: https://rg3.github.io/youtube-dl/supportedsites.html
        """

        async with ctx.typing():
            try:
                source = await ytdl.YTDLSource.create_source(ctx, search, loop=self.bot.loop)
            except ytdl.YTDLError as e:
                await ctx.send('エラー: {}'.format(str(e)))
            else:
                if not ctx.voice_state.voice:
                    await ctx.invoke(self._join)

                song = voice.Song(source)
                await ctx.voice_state.songs.put(song)
                await ctx.send('リストに追加 {}'.format(str(source)))
Ejemplo n.º 5
0
    async def _play(self, ctx: commands.Context, *, search: str):
        """Plays a song.
        Searches from configured gdrive folder first if not url. If not found, search on youtube instead.
        If there are songs in the queue, this will be queued until the
        other songs finished playing.
        This command automatically searches from various sites if no URL is provided.
        A list of these sites can be found here: https://rg3.github.io/youtube-dl/supportedsites.html
        """

        async with ctx.typing():
            parsed_search = await SourceDL.parse_search(
                ctx, search, self.bot.loop)
            song_url, source_type, playlist = SourceDL.get_type(parsed_search)
            source_init = SourceDL.Source(ctx,
                                          source_type=source_type,
                                          loop=self.bot.loop)

            if playlist:
                playlist_info = await source_init.get_playlist_info(song_url)
                playlist_message = await ctx.send(
                    f'Queuing {playlist_info.title}')
                try:
                    sources = await source_init.get_playlist(song_url)
                except SourceDL.SourceError as e:
                    await ctx.send(
                        'An error occurred while processing this request: {}'.
                        format(str(e)))
                    return
            else:
                sources = [song_url]

            for source_num, each_source in enumerate(sources):
                try:
                    source = await source_init.create_source(each_source)
                except SourceDL.SourceError as e:
                    await ctx.send(
                        'An error occurred while processing this request: {}'.
                        format(str(e)))
                    continue
                else:
                    if not ctx.voice_state.voice:
                        await ctx.invoke(self._join)

                    song = voice.Song(source)
                    await ctx.voice_state.songs.put(song)
                    sources[source_num] = source

            color_list = [c for c in voice.colors.values()]
            if playlist:
                embed = (discord.Embed(
                    description=
                    f'Enqueued {playlist_info.song_num} songs from {playlist_info.title} by {ctx.author.name}',
                    color=random.choice(color_list)))
                playlist_message.delete()
            else:
                embed = (discord.Embed(
                    description=
                    f'Enqueued {sources[0].data.title} by {ctx.author.name}',
                    color=random.choice(color_list)))

            await ctx.send(embed=embed, delete_after=10)
            await ctx.message.delete(delay=10)