diff --git a/bin/lib/autovoice.js b/bin/lib/autovoice.js index e42ea89..d37c46f 100644 --- a/bin/lib/autovoice.js +++ b/bin/lib/autovoice.js @@ -9,6 +9,7 @@ const constructRSS = require('./constructRSS'); const formatContentForReading = require('./formatContentForReading'); const fetchContent = require('./fetchContent'); const individualUUIDs = require('./individualUUIDs'); +const filterNullItems = require('./filter-null'); function processItemToMp3(item, voiceId){ debug(`processItemToMp3: index=${item.processingIndex}, item.keys=${JSON.stringify(Object.keys(item))}, voiceId=${voiceId}`); @@ -88,10 +89,16 @@ function generatePodcast(rssUrl, voiceId=tts.defaultVoiceId){ debug(`generatePodcast: items.length=${items.length}`); const promises = items.map( (item, i) => { item.processingIndex = i; - return processItemToMp3(item, voiceId); + return processItemToMp3(item, voiceId) + .catch(err => { + debug(`An error occurred trying to generate speech for item ${item.uuid}. Err:`, err); + return null; + }) + ; } ); return Promise.all(promises); }) + .then( items => filterNullItems(items) ) .then( items => { const feed = constructRSS(rssUrl, items); return feed; @@ -109,10 +116,16 @@ function generateFirstFtBasedPodcast(maxResults, requestedUrl, includeFirstFtUui debug(`generateFirstFtBasedPodcast: items.length=${items.length}`); const promises = items.map( (item, i) => { item.processingIndex = i; - return processItemToMp3(item, voiceId); + return processItemToMp3(item, voiceId) + .catch(err => { + debug(`An error occurred trying to generate speech for item ${item.uuid}. Err:`, err); + return null; + }) + ; } ); return Promise.all(promises); }) + .then( items => filterNullItems(items) ) .then( items => constructRSS(requestedUrl, items) ) ; } diff --git a/bin/lib/filter-null.js b/bin/lib/filter-null.js new file mode 100644 index 0000000..9b0a5d1 --- /dev/null +++ b/bin/lib/filter-null.js @@ -0,0 +1,9 @@ +const debug = require('debug')('bin:lib:filter-null'); + +module.exports = function(listWithNulls){ + + return listWithNulls.filter(item => { + return item !== null; + }); + +} \ No newline at end of file diff --git a/bin/lib/formatContentForReading.js b/bin/lib/formatContentForReading.js index 8c0be0f..9663a4c 100644 --- a/bin/lib/formatContentForReading.js +++ b/bin/lib/formatContentForReading.js @@ -86,6 +86,10 @@ function wrap(itemData) { let texts = []; + if(itemData.content === undefined){ + throw 'itemData.content is undefined. There is nothing to read aloud.'; + } + texts.push(`This article is narrated by Experimental ${itemData.voiceId}.`); texts.push( itemData.content + '.' );