wesbos / Wes-Bos-Captions

Captions for my video courses
478 stars 321 forks source link

Automatically deploy changes to Vimeo #61

Open wesbos opened 5 years ago

wesbos commented 5 years ago

Right now these changes have to be manually sync'd to vimeo.

I have a script I cobbled together that will push them up to vimeo, but its not automatic.

What I would like is that anytime a file changes, we push that to vimeo so the updated captions are up there.

This would require that we put the video ID in the title, or some sort of metadata.

Also I would like to do this with translated captions as well.

Not an immediate need, but something to think about @lfades

const Vimeo = require('vimeo').Vimeo;
const axios = require('axios');

const lib = new Vimeo(
  'nah',
  'nah',
  'nahhhhhhh'
);

const fs = require('fs');

const videoData = require('../../../Sites/bosmonster/site/data/videos-JS3');

const videos = videoData.videos.filter(video => video.caption).map(video => {
  video.texttrack = fs.readFileSync(`../../Wes-Bos-Captions/${video.caption}`);
  return video;
});

function uploadCaption(video) {
  return new Promise((resolve, reject) => {
    const path = `/videos/${video.id}/texttracks`;
    lib.request(
      {
        method: 'POST',
        path,
        query: {
          type: 'captions',
          language: 'en',
          name: `${video.title} Captions`,
        },
      },
      (err, body) => {
        axios
          .put(body.link, video.texttrack)
          .then(res => {
            resolve(`Finished ${video.title}`)
          })
          .catch(err => {
            reject(`error on video ${video.id}`)
            console.log(err);
          });
      }
    );
  });
}

let i = 1;

async function go() {
  const video = videos[i];
  console.log(`Starting ${video.title}`);
  const res = await uploadCaption(video);
  console.log(res);
  i++;
  if (videos[i]) {
    go();
  }
}

go().catch(console.error);

@lfades