Script to upload every new video from Google Drive to YouTube

I'm in need of help to create a script to upload new videos I send to Google Drive directly to YouTube using a bot. I've done major part of the code, but I can't find anywhere how to get the new video URL and it's metadata, could someone please help me? Here is the code I've wrote so far below:

function upload(url, title, description, topics) {
    try{
        var video = UrlFetchApp.fetch(url);
        YouTube.Videos.insert({
            snippet:{
                title: title,
                description: description,
                tags: topics
            },
            status:{
              privacyStatus: "unlisted",
            },
        },"snippet,status", video);
        return ContentService.createTextOutput("done")
    }catch (err){
      return ContentService.createTextOutput(err.message)
    }
}

Thanks a lot for helping!

Upvotes: 0

Views: 677

Answers (1)

stvar
stvar

Reputation: 6975

Have something like the following:

   response = YouTube.Videos.insert({
            snippet:{
                title: title,
                description: description,
                tags: topics
            },
            status:{
              privacyStatus: "unlisted",
            },
       },
       "snippet,status",
       video
   );
   Logger.log(JSON.stringify(response));

Above, response is a Video resource that contains the metadata associated to your newly uploaded video.

From there on you would use response as you need; for example, the video ID of the newly uploaded video is to be found at response.id. From the ID, you could compose that video's URL as:

url = "https://www.youtube.com/watch?v="
        .concat(response.id)

Upvotes: 1

Related Questions