This repository was archived by the owner on Jun 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
42 lines (36 loc) · 1.22 KB
/
Copy pathserver.js
File metadata and controls
42 lines (36 loc) · 1.22 KB
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
var y = require('youtube-dl')
var ffmpeg = require('liquid-ffmpeg')
var fs = require('fs')
var http = require('http')
var url = require('url')
var through = require('through2')
var request = require('request')
var options = require('./options.json')
var stream;
var data;
var child;
var video;
http.createServer(audio).listen(8000, 'localhost');
console.log('Server listening on port 8000');
function audio(a, b) {
data = url.parse(a.url, true).query;
video = y(data.i);
if (data.s != 0) {
request({
url: "http://gdata.youtube.com/feeds/api/videos/" + data.i + "?v=2&alt=jsonc",
json: true
}, function(error, response, p) {
p = parseInt(options.bitrate + "000") / 8 * p["data"]["duration"];
b.writeHead(200, {
'Transfer-Encoding': 'binary',
"Connection": "keep-alive",
"Content-Type": "audio/mpeg",
'Content-Length': p,
"Accept-Ranges": "bytes"
});
});
}
stream = b.file ? fs.createWriteStream(b.file):through();
new ffmpeg({source: video, timeout: 6000}).toFormat('mp3').withAudioBitrate(options.bitrate).writeToStream(stream);
stream.pipe(b);
};