forked from gitter-badger/node-spotify-downloader
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.coffee
65 lines (47 loc) · 1.84 KB
/
main.coffee
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
require("coffee-script")
try
require('source-map-support').install()
require("colors")
Program = require("commander")
Downloader = require("./lib/downloader")
getBaseDir = -> "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}\"")
#.option("-g, --generate", "Generate file for playlist (PLAYLISTS ONLY!)")
.parse(process.argv)
config =
username: Program.username
password: Program.password
uri: Program.uri
directory: Program.directory
#format: Program.format
folder: Program.folder
generate: Program.generate
onWindows: process.platform == 'win32'
if !config.username? or !config.password?
console.log "No username / password specified!".red
return Program.outputHelp()
if !config.uri?
console.log "No URI specified!".red
return Program.outputHelp()
# Check if it's a Spotify Web-URL - if it is, convert it to a URI
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()