-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
executable file
·59 lines (50 loc) · 1.31 KB
/
cli.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
'use strict';
var pkg = require('./package.json');
var open = require('open');
var youtubeThumbnail = require('./');
var argv = process.argv.slice(2);
function help() {
console.log([
'',
' ' + pkg.description,
'',
' Example',
' youtube-thumbnail https://www.youtube.com/watch?v=9bZkp7q19f0',
' => http://img.youtube.com/vi/9bZkp7q19f0/default.jpg',
'',
' youtube-thumbnail https://www.youtube.com/watch?v=9bZkp7q19f0 --high --open',
' => http://img.youtube.com/vi/9bZkp7q19f0/hqdefault.jpg',
'',
' Options',
' --open',
' opens the thumbnail image in your browser',
'',
' --medium',
' returns the medium resolution thumbnail',
'',
' --high',
' returns the high resolution thumbnail'
].join('\n'));
}
if (argv.indexOf('--help') !== -1) {
help();
return;
}
if (argv.indexOf('--version') !== -1) {
console.log(pkg.version);
return;
}
var openImage = (argv.indexOf('--open') !== -1);
var thumbnail = youtubeThumbnail(argv[0]);
var url = thumbnail.default.url;
if (argv.indexOf('--medium') !== -1) {
url = thumbnail.medium.url;
}
if (argv.indexOf('--high') !== -1) {
url = thumbnail.high.url;
}
console.log(thumbnail.default.url);
if (openImage) {
return open(url);
}