示例#1
0
文件: fun.py 项目: itspapi/Sx4
 async def youtube(self, ctx, *, search: str):
     url = "https://www.googleapis.com/youtube/v3/search?key=" + Token.youtube(
     ) + "&part=snippet&safeSearch=none&{}".format(
         urllib.parse.urlencode({"q": search}))
     request = requests.get(url)
     try:
         await ctx.send("https://www.youtube.com/watch?v={}".format(
             request.json()["items"][0]["id"]["videoId"]))
     except:
         await ctx.send("No results :no_entry:")
示例#2
0
文件: music.py 项目: masternovab/Sx4
 async def playlist(self, ctx, *, query):
     """Search for an play a playlist from youtube"""
     player = self.bot.lavalink.players.get(ctx.guild.id)
     if player.is_connected:
         if not ctx.author.voice or not ctx.author.voice.channel or player.connected_channel.id != ctx.author.voice.channel.id:
             return await ctx.send(
                 "I'm already in a voice channel :no_entry:")
     else:
         if not ctx.author.voice or not ctx.author.voice.channel:
             return await ctx.send(
                 "You are not in a voice channel :no_entry:")
         else:
             player.store('sessionowner', ctx.author.id)
             player.store('channel', ctx.channel.id)
             await player.connect(ctx.author.voice.channel.id)
     url = "https://www.googleapis.com/youtube/v3/search?key=" + Token.youtube(
     ) + "&part=snippet&safeSearch=none&maxResults=10&type=playlist&{}".format(
         urllib.parse.urlencode({"q": query}))
     request = requests.get(url).json()
     if not request["items"]:
         return await ctx.send("No results :no_entry:")
     event = await paged.page(
         ctx,
         request["items"],
         selectable=True,
         function=lambda x: "**[{}]({})**".format(
             x["snippet"]["title"], "https://www.youtube.com/playlist?list="
             + x["id"]["playlistId"]))
     if event:
         results = await self.bot.lavalink.get_tracks(
             "https://www.youtube.com/playlist?list=" +
             event["object"]["id"]["playlistId"])
         tracks = results["tracks"]
         for track in tracks:
             player.add(requester=ctx.author.id, track=track)
         s = discord.Embed()
         s.description = "Enqueued {} with **{}** tracks <:done:403285928233402378>".format(
             results['playlistInfo']['name'], len(tracks))
         await ctx.send(embed=s)
         if not player.is_playing:
             await player.play()