-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
50 lines (39 loc) · 1.02 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
'use strict'
let express = require('express')
let ytdl = require('youtube-dl')
let ytpl = require('ytpl');
const { getInfo } = require('ytdl-getinfo')
let Feed = require('./Feed')
let config = require('./config')
let app = express();
app.get('/video/:id([a-z0-9_\-]{10,20})', (req, res) => {
let id = req.params.id;
console.debug('looking up video with ID ' + id);
ytdl.getInfo(id, [], { maxBuffer: Infinity }, (err, info) => {
if (err) {
console.error(err);
res.send("Playlist not found");
}
else {
res.redirect(info.url)
}
})
})
app.get('/youtube/:id', (req, res) => {
let id = req.params.id;
console.log(config.host);
console.debug('looking up playlist with ID ' + id);
ytpl(id)
.then(playlist => {
let feed = Feed.playlistToFeed(playlist);
var xml = feed.xml();
// res.setHeader('content-type', 'application/rss+xml')
res.set('Content-Type', 'text/xml');
res.send(xml);
})
.catch(err => {
console.error(err);
res.send("Playlist not found");
})
})
app.listen(config.port)