-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (61 loc) · 2.37 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
60
61
62
63
64
65
66
67
68
69
70
var view = require('cli-view-utils');
var minimist = require('minimist');
var twitch = require('./src/twitch.js');
var playStream = require('./src/streamlink.js');
var args = normalizeArgs();
if (args.version) {
return view.renderMessage(version());
}
if (args.help) {
return view.renderMessage(help());
}
if (args.aliases) {
return twitch.gameAliases();
}
return start(args);
function version() {
return "twitchflix version " + require('./package.json').version;
}
function help() {
return [
'Search streams from twitch, watch them directly thanks to streamlink.',
'',
'Usage: twitchflix [OPTIONS] [-- STREAMLINK OPTIONS]',
'',
'Options:',
' -h, --help: show this message',
' -v, --version: show twitchflix version',
' -g, --game: show streams for given game only',
' must be typed as shown on twich if no alias if available',
' --aliases: show the list of games with an alias available',
' an alias can be passed to the --game option instead of the full game name',
' -l, --limit: limit the number of streams to choose from. Defaults to 25.',
'',
'All params typed after -- are passed to streamlink.',
'By default, the streamlink `--default-stream best` option is passed.',
'Check out the streamlink doc for more details on possible options.',
'',
'Examples:',
' `twitchflix --game "Mount Your Friends"` # list only mount your friends streams',
' `twitchflix --game hots` # list Heroes of the Storm streams',
' `twitchflix -- medium` # override default stream quality',
' `twitchflix -- --player vlc` # list most popular streams & play the source stream in vlc',
' `twitchflix -- -np \'omxplayer -o hdmi\'` # play in omx with custom omx options',
].join('\n');
}
function start(options) {
twitch.getUrlToStream(options).then(function(url) {
playStream(url, options.streamlink);
});
}
function normalizeArgs() {
var args = minimist(process.argv.slice(2), {
alias: { h: 'help', v: 'version', l: 'limit', g: 'game', o: 'offset', c: 'channel' },
'--': true
});
args.streamlink = args['--'];
if (args.streamlink.indexOf('--default-stream') === -1) {
args.streamlink.push('--default-stream', 'best');
}
return args;
}