示例#1
0
def get_best_album(args):
    artist = args[0]
    album, date, reviews = best_album(args, internal=True)
    print
    print "Getting %s (%s)" % (album, date)
    q = lambda x: '"%s"' % x
    music.search([q(artist), q(album)])
def getSearch():
    q = request.args.get("query","")
    searchtype = request.args.get("searchtype","")
    res = {}
    if q and searchtype:
        res = music.search(q,searchtype)
    return json.dumps(res)
示例#3
0
 def test_youtube_search(self):
     res = self.loop.run_until_complete(
         search(
             "https://music.youtube.com/watch?v=BaMcFghlVEU&list=RDAMVMBaMcFghlVEU"
         ))
     self.assertTrue(len(res) == 1)
     self.assertEqual(res[0].title, "♂GACHILLMUCHI♂")
示例#4
0
async def youtube(ctx, *args):
    global voice

    if ctx.author.voice:  # If grizzo is not in a voice channel, auto join the one the user is in.
        v_channel = ctx.author.voice.channel
        voice = get(bot.voice_clients, guild=ctx.guild)

        if voice and voice.is_connected():
            await voice.move_to(v_channel)
        else:
            voice = await v_channel.connect()

    else:
        await ctx.send(
            "Please enter a voice channel before requesting Grizzo to play a song."
        )

    url = music.search(args)

    song_there = os.path.isfile("song.mp3")  # checks if a song file is present
    try:
        if song_there:
            os.remove("song.mp3")
    except PermissionError:
        await ctx.send("ERROR: Music playing")
        return

    await ctx.send("Preparing request")

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

    with youtube_dl.YoutubeDL(music.ydl_opts) as ydl:
        ydl.download([url])

    name = music.rename(ctx)

    voice.play(discord.FFmpegPCMAudio("song.mp3"),
               after=lambda e: print(f"{name} has finished playing"))
    voice.source = discord.PCMVolumeTransformer(voice.source)
    voice.source.volume = 0.35

    cut = name.index(music.vid_id)
    name = name[:(cut - 1)]
    await ctx.send(f"Now playing: ***{name}***")
    pass
示例#5
0
 def test_search_knowingly_not_finded(self):
     res = self.loop.run_until_complete(
         search("asodjkaliksjdlakjsdl;'kajsd;lkj"))
     self.assertTrue(len(res) == 0)
示例#6
0
 def test_search_knowingly_finded(self):
     res = self.loop.run_until_complete(search("test"))
     self.assertTrue(len(res) > 0)