-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
52 lines (46 loc) · 1.51 KB
/
api.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
const request = require('request-promise');
const alltomp3 = require('alltomp3');
var fs = require('fs');
var youtubedl = require('youtube-dl');
const yt = require('./yt');
exports.searchDeezerForSongs = (query, limit) => {
if (!limit) {
limit = 5;
}
return request({
uri: 'https://api.deezer.com/search?limit=' + limit + '&q=' + encodeURIComponent(query),
json: true,
}).then((results) => {
return results.data.map((r) => {
return {
title: r.title,
artistName: r.artist.name,
duration: r.duration,
cover: r.album.cover_medium,
deezerId: r.id,
};
});
});
}
exports.searchYouTube = (artistName,title) => {
return alltomp3.findVideoForSong({artistName,title});
}
exports.downloadFromYouTube = (url,dir) => {
// var video = youtubedl(url,['-f', 'bestaudio'], {});
// video.pipe(fs.createWriteStream('./.tmp/myvideo.mp3'));
// return new Promise((res, rej) => {
// video.on('end', info => {
// console.log('completed',info);
// res(info);
// });
// video.on('info', info => {
// console.log('Download started');
// console.log('filename: ' + info._filename);
// console.log('size: ' + info.size);
// });
// video.on('error', e => {
// rej(e);
// })
// });
return yt.download(url,dir);
}