Reputation: 35
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?
Upvotes: 1
Views: 1770
Reputation: 29
@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'
Upvotes: 0
Reputation: 11
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 .
Upvotes: 1
Reputation: 13469
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.
Upvotes: 1