Well that mass upload is a long rocky road, now I’m struggling with captions. Once the video is uploaded and I get its uid, I’m adding a caption as shown here PeerTube
and it looks like everything’s fine: I get a 204 response, the video shows there’s a caption, except it’s like there’s nothing inside, no text shows over the video while playing. But if I delete it and replace with the same file in Peertube backoffice, the captions show as intended. Here’s how I’m doing it:
static videoPostUpload(response, data) {
response.json()
.then(result => {
Log.debug(result);
data.shortUUID = result.video.shortUUID;
data.url = `${settings.baseurl}w/${data.shortUUID}`;
//Add subtitles?
if (data.subs) {
Object.keys(data.subs).forEach(lang => {
let form = new FormData();
let captionurl = paths.wip + data.subs[lang];
let caption = new Blob([fs.readFileSync(captionurl)], { type: "application/octet-stream" });
Log.info(caption);
form.set("captionfile", caption);
fetch(`${this.url}videos/${data.shortUUID}/captions/${lang}`, {
method: "PUT",
headers: {
Authorization: `Bearer ${this.accessToken}`
},
body: form
})
.then(response => {
if (response.ok) {
Log.debug("Captions ok");
}
Log.debug(response);
});
});
}
});
}
This method is called once the video is uploaded, with its response and some data sent as arguments. When I run it I get the « Captions ok » log. FWIW I added a mime type here but I first did without it, with no error. The blob I send is the same size as the file so I guess nothing’s wrong here. The url used for fetch looks like http://127.0.0.1:9001/api/v1/videos/fKRrCjVAg1mfLvkoQtGUD9/captions/fr which seems legit. No error in logs neither. I really don’t get it.
In case that helps, here’s the upload video method that calls videoPostUpload if successful:
static videoUpload(data) {
this.getAccessToken()
.then((response) => {
if (response) {
Log.info(`Importing "${data.filename}"`);
Mediafiles.moveDatafilesToFolder(data, paths.todo, paths.wip, "debug");
const form = new FormData(),
fileurl = paths.wip + data.filename;
//Get file content.
const file = new Blob([fs.readFileSync(fileurl)], { type: "video/mp4" });
form.set("videofile", file, data.filename);
form.set("channelId", data.channelId);
form.set("category", data.categoryId);
form.set("name", data.titre);
form.set("description", data.description);
form.set("originallyPublishedAt", data.date);
form.set("language", data.languageId);
form.set("privacy", data.privacyId);
//TODO: playlist
//Tags
data.tags.forEach(tag => {
form.set("tags[]", tag);
});
//Poster & thumbnail
if (data.poster) {
const posterurl = paths.wip + data.poster;
const poster = new Blob([fs.readFileSync(posterurl)], { type: "image/jpeg" });
form.set("previewfile", poster, data.poster);
form.set("thumbnailfile", poster, data.poster);
}
Log.debug(form);
fetch(this.url + "videos/upload", {
method: "POST",
headers: {
Authorization: `Bearer ${this.accessToken}`
},
body: form
})
.then(response => {
Log.debug(response);
if (response.ok) {
//Upload done.
this.videoPostUpload(response, data);
} else {
Log.error(response);
}
});
} else {
Log.fatal("videoUpload: couldn't authorize Peertube API.");
}
});
}