-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgp_podcast_helper.js
101 lines (94 loc) · 2.52 KB
/
gp_podcast_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"use strict";
const parsePodcast = require("node-podcast-parser");
const got = require("got");
const _ = require("lodash");
const URI = "https://gympiepresbyterian.org.au/sermons/index.xml";
function getPodcast() {
return new Promise(function(resolve, reject) {
(async () => {
try {
const response = await got(URI);
parsePodcast(response.body, (err, data) => {
if (err) {
console.error("Parsing error", err);
reject(err);
}
resolve(data);
});
} catch (error) {
console.log("error:", error);
}
})();
});
}
function GPPodcastHelper() {}
GPPodcastHelper.prototype.getEpisodeURL = function(episode) {
return getPodcast()
.then(function(pod) {
if (_.isUndefined(episode)) {
episode = 0;
}
var URL = pod.episodes[episode].enclosure.url.replace(
"http://",
"https://"
);
console.log("URL", URL);
return URL;
})
.catch(function(error) {
console.log("Failed", error);
return error;
});
};
GPPodcastHelper.prototype.getTitle = function(episode) {
return getPodcast()
.then(function(pod) {
if (_.isUndefined(episode)) {
episode = 0;
}
return pod.episodes[episode].title;
})
.catch(function(error) {
console.log("Failed", error);
return error;
});
};
GPPodcastHelper.prototype.getDate = function(episode) {
return getPodcast()
.then(function(pod) {
if (_.isUndefined(episode)) {
episode = 0;
}
return pod.episodes[episode].published;
})
.catch(function(error) {
console.log("Failed", error);
return error;
});
};
GPPodcastHelper.prototype.getEpisode = function(episode) {
//This function will return an object with a pre-roll string and the URL of the episode
return getPodcast()
.then(function(pod) {
if (_.isUndefined(episode)) {
episode = 0;
}
var prompt =
"This is a sermon from Gympie Presbyterian Church called " +
pod.episodes[episode].title +
" it was recorded on " +
pod.episodes[episode].published.toDateString();
//Alexa has to download the MP3 file over https
var mp3URL = pod.episodes[episode].enclosure.url.replace(
"http://",
"https://"
);
var podcast = { preRoll: prompt, mp3URL: mp3URL };
return podcast;
})
.catch(function(error) {
console.log("Failed", error);
return error;
});
};
module.exports = GPPodcastHelper;