alexa-samples/skill-sample-nodejs-audio-player

Play episodes from RSS feed?

Closed this issue ยท 28 comments

Is there a possibility to pull episodes from the RSS feed instead of manually entering each file/episode?

I used 'sync-request' to avoid issues with audioData being undefined on export (regular 'request' is an async call). Then xml2js to parse the rss. It's a hack but it works.

'use-strict';  
var request = require('sync-request');  
var xml2js = require('xml2js');  
var audioData;  
var res = request('GET',"http://feeds.feedburner.com/foxnews/podcasts/FoxNewsSundayAudio");  
var parseString = xml2js.parseString;  
parseString(res.getBody(), function(err,result){  
        var raw = result['rss']['channel'][0]['item'][0]['guid'][0]['_'];  
        var url = "https:/" + raw.substring(raw.search("mp3")+3,raw.length+1);  
        var title = result['rss']['channel'][0]['item'][0]['title'][0];  
        audioData = [{"title":title,"url":url}];  
});  
module.exports = audioData;  

Neat solution. Works only if the rss feed uses https for audio urls.

Correct, Alexa skills playing audio are required to use HTTPS for audio materials.

Hello - I got this to work but it is only grabbing the newest episode. How can I get it to grab all the episodes? Thanks

you can navigate between episode by voice with "Alexa next" or "Alexa previous"

Thank you for your reply but every time I ask Alexa to do that, it says that I have reached the end of the playlist.

With regards to audio files needing HTTPS, I replaced http with https in the raw variable and the first episode played.

I tried modifying the audioplayer using the above code... But lambda keeps on showing me a lot of modules missing one by one... eg promise , util-deprecate , asap etc etc... Could you tell me a solution to this? Or upload your own node_modules folder?

I uploaded them one by one, it takes a while because there are a lot. I am sure there is a better way tho

Thanks for letting me know... At least now I know that it won't go on till infinity... @ramseyk39

On installing a lot of modules manually... I'm stuck on this error... "Cannot read property '_' of undefined"

Depending on your RSS feed, I am using soundcloud so for me to get this line to work:
var raw = result['rss']['channel'][0]['item'][0]['guid'][0]['_'];

I had to use this: var raw = result['rss']['channel'][0]['item'][0]['enclosure'][0]['$'].url;

Why did you replace the underscore with a dollar sign? and .url?

I Googled the issue and one of the results said to try it and it worked.

"enclosure": {
"@Length": "49880169",
"@url": "https://traffic.libsyn.com/secure/XYZ.mp3"
},

My enclosure is like this. So should I use .url here as well?

I would try it. By using .url I didn't have to use this:
var url = "https:/" + raw.substring(raw.search("mp3")+3,raw.length+1);

So the variable raw stored your url directly?

And so did you substitute url with raw in this line?

audioData = [{"title":title,"url":url}];

I'm getting this error after doing what you said and I cannot find what this means...

Cannot read property '0' of undefined

Basically, the rest looks like this. I had to replace http with https...
var urlfull = raw; //"http:/" + raw.substring(raw.search("url")+3,raw.length+1);
var url = urlfull.replace('http:/','https:/');
var titlefull = result['rss']['channel'][0]['item'][0]['title'][0];
var title = titlefull.replace('&', 'and');
audioData = [{"title":title,"url":url}];

Didn't you get this error?
Cannot read property '0' of undefined

Cuz my code is similar. And I'm getting that error.

I did at first but now I don't. My only issue is getting the entire rss feed to play. I can only get the latest episode.

For that I guess instead of getting title you can get the episode number and store them in audioData. So when user says episode 2 then it will check with audioData.

My code :
var url = result['rss']['channel'][0]['item'][0]['enclosure'][0]['$'].url;
var episode = result['rss']['channel'][0]['item'][0]['episode'][0];
MyPodcast = [{"episode":episode,"url":url}];

But I don't know how to get rid of the error Cannot read property '0' of undefined

Maybe change episode to title?

In RSS feed there is only one one and many . So why do and also have [0]?

What does the [0] signify? I'm guessing it stores the link as an array?

Item 0 is the first or latest episode. If you set URL item to 7 and Title item to 7 it jumps to the 8th episode. I just need to figure out how to increment it...

I am trying to read anchor.fm RSS feed and the JSON object format is different. dont we have same schema definition?