-
Notifications
You must be signed in to change notification settings - Fork 0
/
yt.js
31 lines (23 loc) · 771 Bytes
/
yt.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
const app = require('./server').app;
const ytSearch = require('yt-search');
const ytdl = require('ytdl-core');
app.get('/ytobg.mp3',(req,res,err)=>{
// console.log('id='+req.query.id);
if(err) {
console.log(err);
}
var id = req.query.id ? req.query.id : 'vecSVX1QYbQ';
res.writeHead(200, {
'Content-Type': 'audio/mpeg'})
ytdl('https://www.youtube.com/watch?v='+id, {filter: 'audioonly'}).pipe(res);
//fs.createReadStream('audioVideo.mp3').pipe(res);
});
//{q: searchWord}
app.post('/ytobg',(req,res,err)=>{
// console.log(req.body);
ytSearch( req.body.q, function ( err, r ) {
if ( err ) throw err
const videos = r.videos
res.json(videos.filter(e=>e.videoId).slice(0,9));
} )
});