From f075548d78020b00337d372131c87ad99f6757c4 Mon Sep 17 00:00:00 2001 From: Alexey Glushko Date: Mon, 25 Jan 2016 20:39:37 +0000 Subject: [PATCH] add ``headers`` option to create_ffmpeg_player() headers can't be passed through 'options' because in '-headers' flag shoul be placed before '-i' At least for ffmpeg 2.8.4 --- discord/voice_client.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/discord/voice_client.py b/discord/voice_client.py index 74713e0b0..70b6574fb 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -334,7 +334,7 @@ class VoiceClient: struct.pack_into('>I', buff, 8, self.ssrc) return buff - def create_ffmpeg_player(self, filename, *, use_avconv=False, pipe=False, options=None, after=None): + def create_ffmpeg_player(self, filename, *, use_avconv=False, pipe=False, options=None, headers=None, after=None): """Creates a stream player for ffmpeg that launches in a separate thread to play audio. @@ -369,6 +369,8 @@ class VoiceClient: to the stdin of ffmpeg. options: str Extra command line flags to pass to ``ffmpeg``. + headers: dict + HTTP headers dictionary to pass to ``-headers`` command line option after : callable The finalizer that is called after the stream is done being played. All exceptions the finalizer throws are silently discarded. @@ -386,8 +388,13 @@ class VoiceClient: """ command = 'ffmpeg' if not use_avconv else 'avconv' input_name = '-' if pipe else shlex.quote(filename) - cmd = command + ' -i {} -f s16le -ar {} -ac {} -loglevel warning' - cmd = cmd.format(input_name, self.encoder.sampling_rate, self.encoder.channels) + headers_arg = "" + if isinstance(headers, dict): + for key, value in headers.items(): + headers_arg += "{}: {}\r\n".format(key, value) + headers_arg = ' -headers ' + shlex.quote(headers_arg) + cmd = command + '{} -i {} -f s16le -ar {} -ac {} -loglevel warning' + cmd = cmd.format(headers_arg, input_name, self.encoder.sampling_rate, self.encoder.channels) if isinstance(options, str): cmd = cmd + ' ' + options