2016-06-08 1 views

Antwort

0

/youtube/videos/list bietet die API zum Abfragen des Video-Upload-Status.

var videoId = 'aBcdEfjhkLm' 

const Youtube = require("youtube-api"), fs = require("fs"), 
    readJson = require("r-json"), Lien = require("lien"), 
    Logger = require("bug-killer"), opn = require("opn"), 
    prettyBytes = require("pretty-bytes"); 

const CREDENTIALS = readJson(`${__dirname}/credentials.json`); 
let server = new Lien({ host: "localhost" , port: 5000 }); 
let oauth = Youtube.authenticate({ 
    type: "oauth", client_id: CREDENTIALS.web.client_id, 
    client_secret: CREDENTIALS.web.client_secret, 
    redirect_url: CREDENTIALS.web.redirect_uris[0] 
}); 

opn(oauth.generateAuthUrl({ 
    access_type: "offline", scope: ["https://www.googleapis.com/auth/youtube"] 
})); 

server.addPage("/oauth2callback", lien => { 
    Logger.log("code: " + lien.query.code); 
    oauth.getToken(lien.query.code, (err, tokens) => { 
     if (err) { lien.lien(err, 400); return Logger.log(err); } 
     Logger.log("Got the tokens."); 
     oauth.setCredentials(tokens); 
     lien.end(
     '<script>window.close()</script>' 

     ); 
     var req = Youtube.videos.list({ 
      id: 'fEJc2CwddgU', 
      part: "status", 
     }, 
     (err, data) => { 
      if (err) { 
       console.log('err:', err) 
       process.exit() 
      } 
      var s = data.items[0].status.uploadStatus 
      if (s == 'uploaded') console.log('Video is being processed.') 
      if (s == 'processed') console.log('Video processing completed.') 
      process.exit() 
     }); 
    }); 
}); 
Verwandte Themen