-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
96 lines (85 loc) · 4.76 KB
/
server.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
var express = require('express');
var queries = require('./queries.js');
var app = express();
var php = require('php-node')({bin:"php"});
app.use(express.bodyParser());
app.use(express.logger('dev'));
app.set('views', __dirname + '/views');
app.use(express.static('public'));
app.engine('php', php);
app.set('view engine', 'php');
//ejs
app.locals.basedir = __dirname + "/public";
playlists = [
[
{"title": "A Comic History of the U.S 01", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_01_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 02", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_02_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 03", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_03_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 04", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_04_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 05", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_05_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 06", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_06_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 07", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_07_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 08", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_08_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 09", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_09_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 10", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_10_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 11", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_11_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 12", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_12_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 13", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_13_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 14", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_14_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 15", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_15_nye_64kb.mp3"},
{"title": "A Comic History of the U.S 16", "url": "http://www.archive.org/download/comic_history_us_0807_librivox/comichistoryofus_16_nye_64kb.mp3"},
],
[
{"title": "Civil War 84", "url": "http://traffic.libsyn.com/civilwarpodcast/CivilWar84.mp3"},
{"title": "Civil War 25", "url": "http://traffic.libsyn.com/civilwarpodcast/CivilWar25.mp3"},
{"title": "Civil War 42", "url": "http://traffic.libsyn.com/civilwarpodcast/CivilWar42.mp3"}
],
[
]
];
currentPlaylist = 0;
currentEpisode = 0;
searchPlaylist = [];
app.get('/', function(request, response) {
response.redirect('/index');
});
app.get('/index', function(request, response) {
response.render('index.jade', { playlists: playlists });
});
app.post('/setPlaylist', function(request, response) {
var idx = request.body.idx;
currentPlaylist = idx;
currentEpisode = 0;
response.send(playlists[idx][0]);
});
app.post('/getNext', function(request, response) {
if (currentPlaylist === "search") {
currentEpisode = (currentEpisode + 1) % searchPlaylist.length;
response.send(searchPlaylist[currentEpisode]);
} else {
currentEpisode = (currentEpisode + 1) % playlists[currentPlaylist].length;
response.send(playlists[currentPlaylist][currentEpisode]);
}
});
app.post('/search', function(request, response) {
var name = request.body.name;
var period = request.body.period;
var location = request.body.location;
queries.findPodcasts(name, period, location, function(err, results) {
if (err) {
console.log(err);
response.send("ok");
} else {
console.log(results);
searchPlaylist = results;
currentPlaylist = "search";
currentEpisode = 0;
response.send(searchPlaylist[0]);
}
});
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('CastAway listening at http://%s:%s', host, port);
});