Skip to content

Instantly share code, notes, and snippets.

@kuu
Created September 12, 2017 03:45
Show Gist options
  • Save kuu/32bac5b65d1bf2717ec63ab65088cc01 to your computer and use it in GitHub Desktop.
Save kuu/32bac5b65d1bf2717ec63ab65088cc01 to your computer and use it in GitHub Desktop.
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