Вот что у меня получилось:
Код: Выделить всё
app.post('/api/dailymotion/upload', async (req, res) =\> {
const localVideoDirectory = path.join(\__dirname, 'videos');
try {
const videos = fs.readdirSync(localVideoDirectory)
.filter(file => file.endsWith('.mp4') || file.endsWith('.mkv') || file.endsWith('.avi'))
.map(file => ({
name: file,
path: path.join(localVideoDirectory, file)
}));
if (!videos || videos.length === 0) {
return res.status(400).send('No video files found in the local directory.');
}
console.log('[📂] Found Local Videos:', videos);
const token = await getAccessToken();
const uploadResults = await Promise.all(videos.map(async (video) => {
try {
console.log(`[📂] Preparing to upload video: ${video.name}`);
const videoData = fs.readFileSync(video.path);
const form = new FormData();
form.append('file', videoData, video.name);
form.append('title', video.name);
form.append('channel', 'music');
form.append('published', 'true');
form.append('is_created_for_kids', 'false');
// Make the request to upload and publish in one step
const uploadResponse = await axios.post(
`${DAILY_API_BASE}/me/videos`,
form,
{
headers: {
Authorization: `Bearer ${token}`,
...form.getHeaders(),
},
maxContentLength: Infinity,
maxBodyLength: Infinity,
}
);
console.log('[✅] Video Uploaded and Published:', uploadResponse.data);
return uploadResponse.data;
} catch (error) {
console.error(`[❌] Error uploading video (${video.name}):`, error.message);
return { error: error.message, video: video.name };
}
}));
res.json(uploadResults);
} catch (error) {
console.error('[❌] Error in upload endpoint:', error.message);
res.status(500).send('Error uploading videos.');
}
});
Использование проводника API возвращает простой объект json при успех. Я получаю то же самое:
Код: Выделить всё
[✅] Video Uploaded and Published: {
id: 'x9cqoek',
title: 'anpr.mp4',
channel: 'music',
owner: 'x369ws4'
}
Код: Выделить всё
curl -X GET -H "Authorization: Bearer " https://api.dailymotion.com/video/x9cqoek?fields=id,title,channel,status,published
Код: Выделить всё
{"id":"x9cqoek","title":"anpr.mp4","channel":"music","status":"processing","published":false}
Код: Выделить всё
curl -X GET -H "Authorization: Bearer \" https://api.dailymotion.com/video/x9cqoek?fields=encoding_progress
Код: Выделить всё
{"encoding_progress":0}
Код: Выделить всё
curl -X POST -H "Authorization: Bearer \" -F 'published=true' https://api.dailymotion.com/video/x9cqoek
Код: Выделить всё
{"id":"x9cqoek","title":"anpr.mp4","channel":"music","owner":"x369ws4"}
Я перепробовал все, что мог придумать, при этом и, возможно, просто попробую что-нибудь еще, но я бы хотел придерживаться dailymotion, если это возможно. Загрузка видео вручную работает нормально, и я могу использовать тот же токен аутентификации для запроса загруженных видео и возврата тех, которые я загружаю вручную через сайт. Мои видео, загруженные через API, похоже, никогда не распространяются.
Подробнее здесь: https://stackoverflow.com/questions/793 ... motion-api