1

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?

  • You may refer with this [thread](https://productforums.google.com/forum/#!msg/youtube/u54b9ROXy40/_FcHS9cjFAAJ). Make sure that you put a new line character `\n` at the end of each message wherein it consists of a time and a text based in [example](https://support.google.com/youtube/answer/6077032?&ref_topic=2853697). Be noted of [Live caption requirements](https://support.google.com/youtube/answer/3068031?hl=en). 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. – abielita Apr 06 '17 at 18:40
  • Thanks. It works now. – Alexey Elesin Apr 07 '17 at 20:14
  • Does my comment helps? If yes I'll post it as an answer. – abielita Apr 07 '17 at 23:25
  • Yes, it works. I was confused by documentation notes about using the
    tag.
    – Alexey Elesin Apr 09 '17 at 11:40

3 Answers3

1

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.

abielita
  • 13,147
  • 2
  • 17
  • 59
1

This is more a comment than an answer, but I am not allowed yet to comment; I had to add \n after the time stamp in addition to \n after the cc text. Without it, it does not work. Tried to curl, but I failed to make it work while your python script worked immediately, provided one inserts \n .

pkv
  • 11
  • 3
  • 1
    If you're saying that his script works for you adding \n, that's a fine answer. If that's the case, please edit your answer to remove the claim that it is not an answer. – Sam Hartman May 19 '17 at 15:27
0

@pkv thank you I just wanted to add the code changes that you suggested to your answer but I also don't have enough reputation to comment. This was all that was needed for this to work.

post_fields = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + ' region:reg1#cue1\n' + "<br>" + word + '<br>\n'