Created
September 12, 2017 03:45
-
-
Save kuu/32bac5b65d1bf2717ec63ab65088cc01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const OoyalaApi = require('ooyala-api'); | |
const api = new OoyalaApi("Your-API-Key", "Your-API-Secret"); | |
api.get('/v2/assets', {limit: 500}, {recursive: true}) | |
.then(list => { | |
return list.filter(asset => asset.asset_type === 'video'); | |
}) | |
.then(list => { | |
return Promise.all(list.map(asset => getSourceFileSize(asset.embed_code))); | |
}) | |
.then(list => { | |
return list.reduce((a, b) => (a + b), 0); | |
}) | |
.then(total => { | |
console.log(`Total source size is ${total} bytes`); | |
}) | |
.catch(err => { | |
console.log(err.stack); | |
}); | |
function getSourceFileSize(asset) { | |
return api.get(`/v2/assets/${asset}/source_file_info`) | |
.then(sourceInfo => { | |
return sourceInfo.file_size; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment