forked from gitter-badger/node-spotify-downloader
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
64 lines (48 loc) · 2.03 KB
/
main.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
// Generated by CoffeeScript 1.10.0
(function() {
var Downloader, Program, config, downloader, getBaseDir;
require("coffee-script");
try {
require('source-map-support').install();
} catch (undefined) {}
require("colors");
Program = require("commander");
Downloader = require("./lib/downloader");
getBaseDir = function() {
return "download";
};
Program.version("0.0.1").option("-u, --username [username]", "Spotify Username (required)", null).option("-p, --password [password]", "Spotify Password (required)", null).option("-i, --uri [url / uri]", "Spotify URL / URI (Track / Album / Playlist)", null).option("-d, --directory [directory]", "Download Directory - Default: \"download\" folder within the same directory", getBaseDir()).option("-f, --folder [format]", "Save songs in single folder with the playlist name or specified path format - e.g. \"{artist.name}/{album.name}/{track.name}\"").parse(process.argv);
config = {
username: Program.username,
password: Program.password,
uri: Program.uri,
directory: Program.directory,
folder: Program.folder,
generate: Program.generate,
onWindows: process.platform === 'win32'
};
if ((config.username == null) || (config.password == null)) {
console.log("No username / password specified!".red);
return Program.outputHelp();
}
if (config.uri == null) {
console.log("No URI specified!".red);
return Program.outputHelp();
}
config.uri = config.uri.replace(/^(https?):\/\//, "");
config.uri = config.uri.replace("play.spotify.com", "spotify").replace(/\//g, ":");
if (config.uri.indexOf("album") !== -1) {
config.type = "album";
} else if (config.uri.indexOf("track") !== -1) {
config.type = "track";
} else if (config.uri.indexOf("playlist") !== -1) {
config.type = "playlist";
} else if (config.uri === "library") {
config.type = "library";
} else {
console.log("Invalid URI specified!".red);
return Program.outputHelp();
}
downloader = new Downloader(config);
downloader.run();
}).call(this);