Add media via rest API to Transcript module

Hi we are using the Transcript module for a project that has about 400 items. Each item will have an mp3/webvtt added via the Transcript module which works great. The Transcript module doesn’t work with CSV importer (which it calls out in the instructions) which is how we are adding items so I was trying to use the REST api to add the media after the fact but no dice. Here is the meat of the code, I have hardcoded in some values and pre-uploaded the vtt file to try and take that out of the equation. Is this even possible? I’m not 100% sure what the webvtt ingester is expecting. Thanks!

data = {
‘o:ingester’: ‘webvtt’,
“o:renderer”: “webvtt”,
‘o:name’: ‘Story’,
“file_index”: “0”,
“o:media_type”: “audio/mpeg”,
‘o:item’: {“o:id”: “348”},
“data”: {
“texttracks”: [
{
“storage”: “asset/07f1fbc15837277263b4e767230b6396a42b8258.vtt”,
“language”: “en”
}
]
}
}

files = [
(‘data’, (None, json.dumps(data), ‘application/json’)),
(‘file[0]’, (‘85_WildCenter.mp3’, open(
‘85_WildCenter.mp3’, ‘rb’), ‘audio/mpeg’))
]

Send the POST request

response = requests.post(url, params=params, files=files)

When you say “no dice”: what happens? An error back from the API? If so, what’s the error message?

When I run the code above I get
"Failed to add mp3: {“errors”:{“error”:["Unsupported media format: “]}}”
It’s not a permissions thing because I tested uploading one of the mp3s through the upload ingester and it attached the media OK.

My gut says that the webvtt ingester is expecting the mp3 and vtt files together since that is how the module works in the admin interface but I couldn’t figure out how to put the 2 files in the post.

I’m not very familiar with the Transcript module, but from a quick look, it sets up the data it’s looking for in a slightly different format than a normal upload, and it looks like you’d need to match that format for it to work.

It’s looking for files at, for example, file[0][media] and file[0][subtitles][0] rather than the standard file[0] as you’re using. And you don’t need to pass the data/texttracks part at all to create a media: the module generates that itself.

I can’t provide really in-depth help on this, though.

Thanks for the help, I’ll poke around a bit and see if I an get it working.

Just to close this out, I got it to work using your suggestions so thanks a ton!

Just for anybody else looking for something similar here is the rough code to upload an mp3 plus and English transcript and a Portuguese transcript to an existing item for use with the Transcript module.

data = {
‘o:ingester’: ‘webvtt’,
“o:renderer”: “webvtt”,
‘o:name’: ‘Story’,
“file_index”: “0”,
“subtitle_index”: “1”,
“o:media_type”: “audio/mpeg”,
‘o:item’: {“o:id”: “345”},
“locale”: [‘en_US’, ‘pt_BR’]
}

files = [
(‘data’, (None, json.dumps(data), ‘application/json’)),
(‘file[0][media]’, (‘yourfile.mp3’, open(
‘yourfile.mp3’, ‘rb’), ‘audio/mpeg’)),
(‘file[0][subtitles][0]’, (‘yourfile.vtt’, open(
‘yourfile.vtt’, ‘rb’), ‘text/vtt’)),
(‘file[0][subtitles][1]’, (‘yourfile_pt_BR.vtt’, open(
‘yourfile_pt_BR.vtt’, ‘rb’), ‘text/vtt’))

]

1 Like