async def play(message: discord.Message, song: Annotate.CleanContent): """ Play a song. The given song could either be a URL or keywords to lookup videos in youtube. """ assert_connected(message.author) state = voice_states[message.server] # Check that the member hasn't already requested enough songs songs_queued = sum(1 for s in state.queue if s.requester == message.author) assert songs_queued < max_songs_queued, "**You have queued enough songs for now.**" # Strip any embed characters, spaces or code symbols. song = song.strip("< >`") try: player = await state.voice.create_ytdl_player( song, ytdl_options=youtube_dl_options, after=state.play_next) except: await client.say(message, "**Could not add this song to the queue.**") print_exc() return # Make sure the song isn't too long if player.duration: assert player.duration < max_song_length, "**The requested song is too long.**" player.volume = state.volume song = Song(player=player, requester=message.author, channel=message.channel) await client.send_message(song.channel, "Queued: " + format_song(song)) state.queue.append(song) # Start the song when there are none if not state.is_playing(): state.play_next()
async def play(message: discord.Message, song: Annotate.CleanContent): """ Play a song. The given song could either be a URL or keywords to lookup videos in youtube. """ assert_connected(message.author) state = voice_states[message.server] # Check that the member hasn't already requested enough songs songs_queued = sum(1 for s in state.queue if s.requester == message.author) assert songs_queued < max_songs_queued, "**You have queued enough songs for now.**" # Strip any embed characters, spaces or code symbols. song = song.strip("< >`") try: player = await state.voice.create_ytdl_player(song, ytdl_options=youtube_dl_options, after=state.play_next) except: await client.say(message, "**Could not add this song to the queue.**") print_exc() return # Make sure the song isn't too long if player.duration: assert player.duration < max_song_length, "**The requested song is too long.**" player.volume = state.volume song = Song(player=player, requester=message.author, channel=message.channel) await client.send_message(song.channel, "Queued: " + format_song(song)) state.queue.append(song) # Start the song when there are none if not state.is_playing(): state.play_next()
async def play(message: discord.Message, song: Annotate.CleanContent): """ Play a song. The given song could either be a URL or keywords to lookup videos in youtube. """ assert_connected(message.author) state = voice_states[message.server] # Check that the member hasn't already requested enough songs songs_queued = sum(1 for s in state.queue if s.requester == message.author) assert songs_queued < max_songs_queued, "**You have queued enough songs for now.**" # Strip any embed characters, spaces or code symbols. song = song.strip("< >`") try: player = await state.voice.create_ytdl_player( song, ytdl_options=youtube_dl_options, after=state.play_next, before_options=ffmpeg_before_options) except: await client.say(message, "**Could not add this song to the queue.**") print_exc() return # Make sure the song isn't too long if player.duration: assert player.duration < max_song_length, "**The requested song is too long.**" url_match = utils.http_url_pattern.match(song) if url_match and player.title == url_match.group("sub"): # Try retrieving the filename as this is probably a file headers = await utils.retrieve_headers(song) if "Content-Disposition" in headers: name_match = disposition_pattern.search( headers["Content-Disposition"]) if name_match: player.title = "".join( name_match.group("name").split(".")[:-1]) player.volume = state.volume song = Song(player=player, requester=message.author, channel=message.channel) await client.send_message(song.channel, "Queued: " + format_song(song)) state.queue.append(song) # Start the song when there are none if not state.is_playing(): state.play_next()