-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·59 lines (49 loc) · 1.17 KB
/
index.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
#!/usr/bin/env node
const podcast = 4239;
const inquirer = require('inquirer');
const Speaker = require('speaker');
const request = require('request');
const lame = require('lame');
const bent = require('bent');
const ora = require('ora');
const getJson = bent('json');
function getEpisodes() {
return getJson(
`https://kortslutning-server-qtoearljfv.now.sh/v1/podcasts/${podcast}/episodes.json`
);
}
var options = {
channels: 2,
bitDepth: 16,
sampleRate: 44100
};
const decoder = new lame.Decoder(options);
const speaker = new Speaker(options);
getEpisodes().then(selectSong);
function getMp3(item) {
return request(item.audio_url);
}
function startPlaying(item) {
ora({
text: `Playing ${item.title}`,
spinner: 'simpleDotsScrolling'
}).start();
getMp3(item)
.pipe(decoder)
.pipe(speaker);
}
function selectSong(items) {
inquirer
.prompt([
{
type: 'list',
name: 'episode',
message: 'Which episode do you want to play?',
choices: items.map(i => i.title)
}
])
.then(({ episode }) => {
const episodeToPlay = items.find(i => i.title === episode);
startPlaying(episodeToPlay);
});
}