From bdc69773b87dd3347fb67bdc9d73813695196e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20K=C3=BChnel?= Date: Fri, 6 Nov 2015 09:46:08 +0100 Subject: [PATCH] Update coverage --- coverage.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coverage.html b/coverage.html index 6c5f5f2..d57e1c7 100644 --- a/coverage.html +++ b/coverage.html @@ -356,4 +356,4 @@ code .keyword { color: #8A6343 } code .number { color: #2F6FAD } -

Coverage

18%
195
36
159

/Users/mkuehnel/Documents/Projects/itunes-remote/index.js

17%
117
20
97
LineHitsSource
11'use strict';
2
31var osascript = require('osascript').eval;
41var stringify = require('js-function-string');
51var logSymbols = require('log-symbols');
61var chalk = require('chalk');
71var requireDir = require('require-dir');
81var lib = requireDir('./lib');
91var osascriptOpts = {
10 type: 'JavaScript',
11 args: ['-s', 's']
12};
13
141function startPlayback(callback) {
15 // Run JavaScript file through OSA
160 osascript(stringify(lib.play.method), function (err) {
170 var result;
180 if (err === null) {
190 result = callback(logSymbols.success + ' Playing ♪♬');
20 } else {
210 result = callback(logSymbols.error + ' ' + chalk.red(err));
22 }
230 return result;
24 });
25}
26
271function stopPlayback(callback) {
28 // Run JavaScript file through OSA
290 osascript(stringify(lib.stop.method), function (err) {
300 var result;
310 if (err === null) {
320 result = callback(logSymbols.success + ' Stopped playing ♪♬');
33 } else {
340 result = callback(logSymbols.error + ' ' + chalk.red(err));
35 }
360 return result;
37 });
38}
39
401function pausePlayback(callback) {
41 // Run JavaScript file through OSA
420 osascript(stringify(lib.pause.method), function (err) {
430 var result;
440 if (err === null) {
450 result = callback(logSymbols.success + ' Paused playing ♪♬');
46 } else {
470 result = callback(logSymbols.error + ' ' + chalk.red(err));
48 }
490 return result;
50 });
51}
52
531function nextTrack(callback) {
54 // Run JavaScript file through OSA
550 osascript(stringify(lib.next.method), function (err) {
560 var result;
570 if (err === null) {
580 result = callback(logSymbols.success + ' Skipped track.');
59 } else {
600 result = callback(logSymbols.error + ' ' + chalk.red(err));
61 }
620 return result;
63 });
64}
65
661function prevTrack(callback) {
67 // Run JavaScript file through OSA
680 osascript(stringify(lib.previous.method), function (err) {
690 var result;
700 if (err === null) {
710 result = callback(logSymbols.success + ' Returned to previous track.');
72 } else {
730 result = callback(logSymbols.error + ' ' + chalk.red(err));
74 }
750 return result;
76 });
77}
78
791function backTrack(callback) {
80 // Run JavaScript file through OSA
810 osascript(stringify(lib.back.method), function (err) {
820 var result;
830 if (err === null) {
840 result = callback(logSymbols.success + ' Returned to previous track or beginning of current track');
85 } else {
860 result = callback(logSymbols.error + ' ' + chalk.red(err));
87 }
880 return result;
89 });
90}
91
921function startPlaylist(playlist, amount, callback) {
93 // Run JavaScript file through OSA
940 osascript(stringify(lib.play.method).replace(/{{playlist}}/, playlist), function (err) {
950 var result;
960 if (err === null) {
970 result = callback(logSymbols.success + ' Playing ' + amount + ' song(s) ♪♬');
98 } else {
990 result = callback(logSymbols.error + ' ' + chalk.red(err));
100 }
1010 return result;
102 });
103}
104
1051function startSearch(searchTerm, opts, callback) {
1060 var limitTo = 'all';
1070 var messagePart = 'songs, albums and artists containing ”';
108
1090 if (opts.songs) {
1100 limitTo = 'songs';
1110 messagePart = 'songs containing ”';
112 }
1130 if (opts.artists) {
1140 limitTo = 'artists';
1150 messagePart = 'songs by ”';
116 }
1170 if (opts.albums) {
1180 limitTo = 'albums';
1190 messagePart = 'album containing ”';
120 }
121
122 // Run JavaScript file through OSA
1230 osascript(stringify(lib.search.method)
124 .replace(/{{searchTerm}}/, searchTerm)
125 .replace(/{{limitTo}}/, limitTo), osascriptOpts, function (err, data) {
1260 data = JSON.parse(data);
1270 var playlist = data[0];
1280 var amount = parseInt(data[1], 10);
1290 var result;
1300 if (err === null && amount) {
1310 if (!opts.dontplay) {
1320 startPlaylist(playlist, amount, function (response) {
1330 result = callback(response);
134 });
135 }
1360 result = callback(logSymbols.success + ' Found ' + messagePart +
137 chalk.inverse(searchTerm) + '“ and generated a temporary playlist');
1380 } else if (err === null) {
1390 result = callback(logSymbols.error + ' Oops. Found 0 ' + messagePart +
140 chalk.inverse(searchTerm) + '“.');
141 } else {
1420 result = callback(logSymbols.error + ' ' + chalk.red(err));
143 }
1440 return result;
145 });
146}
147
1481function getData(callback) {
149 // Run JavaScript file through OSA
1500 osascript(stringify(lib.getLibraryData.method), osascriptOpts, function (err, data) {
1510 var result;
1520 if (err === null) {
1530 result = callback(data);
154 } else {
1550 result = callback(logSymbols.error + ' ' + chalk.red(err));
156 }
1570 return result;
158 });
159}
160
1611module.exports = function (command, callback, args) {
1621 switch (command) {
163 case 'play':
1640 startPlayback(function (response) {
1650 return callback(response);
166 });
1670 break;
168 case 'stop':
1690 stopPlayback(function (response) {
1700 return callback(response);
171 });
1720 break;
173 case 'pause':
1740 pausePlayback(function (response) {
1750 return callback(response);
176 });
1770 break;
178 case 'next':
1790 nextTrack(function (response) {
1800 return callback(response);
181 });
1820 break;
183 case 'previous':
1840 prevTrack(function (response) {
1850 return callback(response);
186 });
1870 break;
188 case 'back':
1890 backTrack(function (response) {
1900 return callback(response);
191 });
1920 break;
193 case 'search':
1940 startSearch(args.searchterm, args.options, function (response) {
1950 return callback(response);
196 });
1970 break;
198 case 'getData':
1990 getData(function (response) {
2000 return callback(response);
201 });
2020 break;
203 default:
2041 throw new Error('You have to call itunesRemote with a command');
205 }
206};
207

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/back.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.backTrack();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/getLibraryData.js

8%
24
2
22
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 (function () {
80 var app = Application('iTunes'); // eslint-disable-line new-cap
90 var library = app.libraryPlaylists[0];
100 var tracks;
110 var artists = [];
120 var uniqueArtists;
130 var albums = [];
140 var uniqueAlbums;
15
160 console.log(app.version());
170 console.log(library.name());
18
190 app.run();
20
210 console.log(library);
22
230 tracks = library.sharedTracks();
240 console.log('tracks.length=', tracks.length);
25
260 tracks.forEach(function (element) {
27 // console.log(element.artist());
280 artists.push(element.artist());
290 albums.push(element.album());
30 });
31
320 uniqueArtists = artists.filter(function (item, pos) {
330 return artists.indexOf(item) === pos;
34 });
35
360 uniqueAlbums = albums.filter(function (item, pos) {
370 return albums.indexOf(item) === pos;
38 });
39
400 return {
41 tracksLength: tracks.length,
42 uniqueArtistsLength: uniqueArtists.length,
43 uniqueArtists: uniqueArtists,
44 uniqueAlbumsLength: uniqueAlbums.length,
45 uniqueAlbums: uniqueAlbums
46 };
47 })();
48 }
49};
50

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/next.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.nextTrack();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/pause.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.pause();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/play.js

25%
8
2
6
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
80 var playlist = '{{playlist}}';
9
100 app.run();
11
120 if (playlist === '{{playlist}}') {
130 app.play();
14 } else {
150 app.userPlaylists[playlist].play();
16 }
17 }
18};
19

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/previous.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.previousTrack();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/search.js

9%
21
2
19
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 (function () {
80 var playlistName = 'itunes-remote';
90 var app = Application('iTunes'); // eslint-disable-line new-cap
100 var searchTerm = "{{searchTerm}}"; // eslint-disable-line quotes
110 var library = app.libraryPlaylists[0];
120 var result;
130 var list;
14
15 // console.log(app.version());
16 // console.log(library.name());
17
180 app.run();
19
200 result = app.search(library, {
21 for: searchTerm,
22 only: '{{limitTo}}'
23 });
24
25 // console.log(result.length);
26 // console.log(result[0].album());
27
280 try {
290 app.userPlaylists[playlistName]();
30 } catch (e) {
310 console.log('create playlist');
320 app.make({
33 new: 'playlist',
34 withProperties: {
35 name: playlistName
36 }
37 });
38 }
39
400 list = app.userPlaylists[playlistName];
41
420 app.delete(list.tracks);
43
440 result.forEach(function (element) {
450 app.duplicate(element, {
46 to: list
47 });
48 });
49
500 console.log(list.time());
51
52 // list.play();
530 return [
54 playlistName,
55 result.length
56 ];
57 })();
58 }
59};
60

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/stop.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.stop();
11 }
12};
13
\ No newline at end of file +

Coverage

18%
195
36
159

/Users/mkuehnel/Documents/Projects/itunes-remote/index.js

17%
117
20
97
LineHitsSource
11'use strict';
2
31var osascript = require('osascript').eval;
41var stringify = require('js-function-string');
51var logSymbols = require('log-symbols');
61var chalk = require('chalk');
71var requireDir = require('require-dir');
81var lib = requireDir('./lib');
91var osascriptOpts = {
10 flags: ['-s', 's']
11};
12
131function startPlayback(callback) {
14 // Run JavaScript file through OSA
150 osascript(stringify(lib.play.method), function (err) {
160 var result;
170 if (err === null) {
180 result = callback(logSymbols.success + ' Playing ♪♬');
19 } else {
200 result = callback(logSymbols.error + ' ' + chalk.red(err));
21 }
220 return result;
23 });
24}
25
261function stopPlayback(callback) {
27 // Run JavaScript file through OSA
280 osascript(stringify(lib.stop.method), function (err) {
290 var result;
300 if (err === null) {
310 result = callback(logSymbols.success + ' Stopped playing ♪♬');
32 } else {
330 result = callback(logSymbols.error + ' ' + chalk.red(err));
34 }
350 return result;
36 });
37}
38
391function pausePlayback(callback) {
40 // Run JavaScript file through OSA
410 osascript(stringify(lib.pause.method), function (err) {
420 var result;
430 if (err === null) {
440 result = callback(logSymbols.success + ' Paused playing ♪♬');
45 } else {
460 result = callback(logSymbols.error + ' ' + chalk.red(err));
47 }
480 return result;
49 });
50}
51
521function nextTrack(callback) {
53 // Run JavaScript file through OSA
540 osascript(stringify(lib.next.method), function (err) {
550 var result;
560 if (err === null) {
570 result = callback(logSymbols.success + ' Skipped track.');
58 } else {
590 result = callback(logSymbols.error + ' ' + chalk.red(err));
60 }
610 return result;
62 });
63}
64
651function prevTrack(callback) {
66 // Run JavaScript file through OSA
670 osascript(stringify(lib.previous.method), function (err) {
680 var result;
690 if (err === null) {
700 result = callback(logSymbols.success + ' Returned to previous track.');
71 } else {
720 result = callback(logSymbols.error + ' ' + chalk.red(err));
73 }
740 return result;
75 });
76}
77
781function backTrack(callback) {
79 // Run JavaScript file through OSA
800 osascript(stringify(lib.back.method), function (err) {
810 var result;
820 if (err === null) {
830 result = callback(logSymbols.success + ' Returned to previous track or beginning of current track');
84 } else {
850 result = callback(logSymbols.error + ' ' + chalk.red(err));
86 }
870 return result;
88 });
89}
90
911function startPlaylist(playlist, amount, callback) {
92 // Run JavaScript file through OSA
930 osascript(stringify(lib.play.method).replace(/{{playlist}}/, playlist), function (err) {
940 var result;
950 if (err === null) {
960 result = callback(logSymbols.success + ' Playing ' + amount + ' song(s) ♪♬');
97 } else {
980 result = callback(logSymbols.error + ' ' + chalk.red(err));
99 }
1000 return result;
101 });
102}
103
1041function startSearch(searchTerm, opts, callback) {
1050 var limitTo = 'all';
1060 var messagePart = 'songs, albums and artists containing ”';
107
1080 if (opts.songs) {
1090 limitTo = 'songs';
1100 messagePart = 'songs containing ”';
111 }
1120 if (opts.artists) {
1130 limitTo = 'artists';
1140 messagePart = 'songs by ”';
115 }
1160 if (opts.albums) {
1170 limitTo = 'albums';
1180 messagePart = 'album containing ”';
119 }
120
121 // Run JavaScript file through OSA
1220 osascript(stringify(lib.search.method)
123 .replace(/{{searchTerm}}/, searchTerm)
124 .replace(/{{limitTo}}/, limitTo), osascriptOpts, function (err, data) {
1250 data = JSON.parse(data);
1260 var playlist = data[0];
1270 var amount = parseInt(data[1], 10);
1280 var result;
1290 if (err === null && amount) {
1300 if (!opts.dontplay) {
1310 startPlaylist(playlist, amount, function (response) {
1320 result = callback(response);
133 });
134 }
1350 result = callback(logSymbols.success + ' Found ' + messagePart +
136 chalk.inverse(searchTerm) + '“ and generated a temporary playlist');
1370 } else if (err === null) {
1380 result = callback(logSymbols.error + ' Oops. Found 0 ' + messagePart +
139 chalk.inverse(searchTerm) + '“.');
140 } else {
1410 result = callback(logSymbols.error + ' ' + chalk.red(err));
142 }
1430 return result;
144 });
145}
146
1471function getData(callback) {
148 // Run JavaScript file through OSA
1490 osascript(stringify(lib.getLibraryData.method), osascriptOpts, function (err, data) {
1500 var result;
1510 if (err === null) {
1520 result = callback(data);
153 } else {
1540 result = callback(logSymbols.error + ' ' + chalk.red(err));
155 }
1560 return result;
157 });
158}
159
1601module.exports = function (command, callback, args) {
1611 switch (command) {
162 case 'play':
1630 startPlayback(function (response) {
1640 return callback(response);
165 });
1660 break;
167 case 'stop':
1680 stopPlayback(function (response) {
1690 return callback(response);
170 });
1710 break;
172 case 'pause':
1730 pausePlayback(function (response) {
1740 return callback(response);
175 });
1760 break;
177 case 'next':
1780 nextTrack(function (response) {
1790 return callback(response);
180 });
1810 break;
182 case 'previous':
1830 prevTrack(function (response) {
1840 return callback(response);
185 });
1860 break;
187 case 'back':
1880 backTrack(function (response) {
1890 return callback(response);
190 });
1910 break;
192 case 'search':
1930 startSearch(args.searchterm, args.options, function (response) {
1940 return callback(response);
195 });
1960 break;
197 case 'getData':
1980 getData(function (response) {
1990 return callback(response);
200 });
2010 break;
202 default:
2031 throw new Error('You have to call itunesRemote with a command');
204 }
205};
206

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/back.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.backTrack();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/getLibraryData.js

8%
24
2
22
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 (function () {
80 var app = Application('iTunes'); // eslint-disable-line new-cap
90 var library = app.libraryPlaylists[0];
100 var tracks;
110 var artists = [];
120 var uniqueArtists;
130 var albums = [];
140 var uniqueAlbums;
15
160 console.log(app.version());
170 console.log(library.name());
18
190 app.run();
20
210 console.log(library);
22
230 tracks = library.sharedTracks();
240 console.log('tracks.length=', tracks.length);
25
260 tracks.forEach(function (element) {
27 // console.log(element.artist());
280 artists.push(element.artist());
290 albums.push(element.album());
30 });
31
320 uniqueArtists = artists.filter(function (item, pos) {
330 return artists.indexOf(item) === pos;
34 });
35
360 uniqueAlbums = albums.filter(function (item, pos) {
370 return albums.indexOf(item) === pos;
38 });
39
400 return {
41 tracksLength: tracks.length,
42 uniqueArtistsLength: uniqueArtists.length,
43 uniqueArtists: uniqueArtists,
44 uniqueAlbumsLength: uniqueAlbums.length,
45 uniqueAlbums: uniqueAlbums
46 };
47 })();
48 }
49};
50

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/next.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.nextTrack();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/pause.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.pause();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/play.js

25%
8
2
6
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
80 var playlist = '{{playlist}}';
9
100 app.run();
11
120 if (playlist === '{{playlist}}') {
130 app.play();
14 } else {
150 app.userPlaylists[playlist].play();
16 }
17 }
18};
19

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/previous.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.previousTrack();
11 }
12};
13

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/search.js

9%
21
2
19
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 (function () {
80 var playlistName = 'itunes-remote';
90 var app = Application('iTunes'); // eslint-disable-line new-cap
100 var searchTerm = "{{searchTerm}}"; // eslint-disable-line quotes
110 var library = app.libraryPlaylists[0];
120 var result;
130 var list;
14
15 // console.log(app.version());
16 // console.log(library.name());
17
180 app.run();
19
200 result = app.search(library, {
21 for: searchTerm,
22 only: '{{limitTo}}'
23 });
24
25 // console.log(result.length);
26 // console.log(result[0].album());
27
280 try {
290 app.userPlaylists[playlistName]();
30 } catch (e) {
310 console.log('create playlist');
320 app.make({
33 new: 'playlist',
34 withProperties: {
35 name: playlistName
36 }
37 });
38 }
39
400 list = app.userPlaylists[playlistName];
41
420 app.delete(list.tracks);
43
440 result.forEach(function (element) {
450 app.duplicate(element, {
46 to: list
47 });
48 });
49
500 console.log(list.time());
51
52 // list.play();
530 return [
54 playlistName,
55 result.length
56 ];
57 })();
58 }
59};
60

/Users/mkuehnel/Documents/Projects/itunes-remote/lib/stop.js

40%
5
2
3
LineHitsSource
11'use strict';
2
3/* global Application */
4
51module.exports = {
6 method: function () {
70 var app = Application('iTunes'); // eslint-disable-line new-cap
8
90 app.run();
100 app.stop();
11 }
12};
13
\ No newline at end of file