-
Notifications
You must be signed in to change notification settings - Fork 31
/
cli.js
executable file
·191 lines (174 loc) · 4.74 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env node
'use strict';
var vorpal = require('vorpal')();
var ora = require('ora');
var chalk = require('chalk');
var itunesRemote = require('./');
vorpal
.history('itunes-remote')
.delimiter('iTunes:')
.show();
vorpal.find('exit').description('Exit itunes-remote.');
vorpal
.command('play', 'Start playing the current selection.')
.alias('start')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('play', function (response) {
spinner.stop();
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
vorpal
.command('play artist', 'Plays songs by an artist.')
.action(function (args, callback) {
var self = this;
var spinner = ora('Getting artists').start();
itunesRemote('getData', function (response) {
var artists = [];
spinner.stop();
artists = response.artists;
self.prompt({
type: 'list',
name: 'artist',
message: 'Choose an artist',
choices: artists
}, function (result) {
var selectedArtist = result.artist;
var spinner = ora('Searching for songs by ' + chalk.blue(result.artist)).start();
itunesRemote('search', function (response) {
spinner.stop();
self.log(response);
callback();
}, {
searchterm: selectedArtist,
options: {artists: true}
});
});
});
});
vorpal
.command('play album', 'Plays an album.')
.action(function (args, callback) {
var self = this;
var spinner = ora('Getting albums').start();
itunesRemote('getData', function (response) {
var albums = [];
spinner.stop();
albums = response.albums;
self.prompt({
type: 'list',
name: 'album',
message: 'Choose an album',
choices: albums
}, function (result) {
var selectedAlbum = result.album;
var spinner = ora('Searching for albums named ' + chalk.blue(result.album)).start();
itunesRemote('search', function (response) {
spinner.stop();
self.log(response);
callback();
}, {
searchterm: selectedAlbum,
options: {albums: true}
});
});
});
});
vorpal
.command('stop', 'Stop playing the current selection')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('stop', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
vorpal
.command('pause', 'Pause playing the current selection')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('pause', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
vorpal
.command('next', 'Advance to the next track in the current playlist.')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('next', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
vorpal
.command('previous', 'Return to the previous track in the current playlist.')
.alias('prev')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('previous', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
vorpal
.command('back', 'Reposition to beginning of current track or go to previous track if already at start of current track.')
.option('-E, --exit', 'exit itunes-remote after executing the command')
.action(function (args, callback) {
var self = this;
var spinner = ora().start();
itunesRemote('back', function (response) {
spinner.stop();
self.log(response);
if (args.options.exit) {
vorpal.execSync('exit');
}
callback();
});
});
vorpal
.command('search <searchterm>', 'Fuzzy search album, artists and songs.')
.option('-A, --albums', 'Limit search to albums')
.option('-s, --songs', 'Limit search to songs')
.option('-a, --artists', 'Limit search to artist')
.option('-d, --dont-play', 'Prevent playing the search result')
.action(function (args, callback) {
var self = this;
var spinner = ora('Searching …').start();
itunesRemote('search', function (response) {
spinner.stop();
self.log(response);
callback();
}, args);
});
vorpal.parse(process.argv);