pythonyoutubeyoutube-apiyoutube-livestreaming-apicaptions

Youtube Live streaming captions


I'm currently developing an rtsp stream speech transcriber and as a test task I'm thinking of trying to send subtitles for youtube stream. According to this link my code in Python is:

post_fields = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + ' region:reg1#cue1' + "<br>" + word + '<br>'
headers = {'content-type': 'text/plain'}
url = self.youtube_link + '&seq=' + str(self.youtube_seq)
r = requests.post(url=url, data=post_fields.encode('utf-8'), headers=headers)
self.youtube_seq += 1

Sadly all what I can recieve from youtube is:

400
2017-04-05T20:19:58.135
Can't parse HTTP POST body.

Did anyone managed to successfully send captions for youtube livestreams via POST requests?


Solution

  • You may refer with this thread. Make sure that you put a new line character \n at the end of each message where each message consists of a time and a text according to the example.

    Also, be noted of this Live caption requirements. In order to add captions to your live event, you need to send captions to YouTube either embedded in the video or through supported software that can send captions over HTTP POSTs.