-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
39 lines (36 loc) · 1.21 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
/**
* Created by chris on 02.01.16.
*/
"use strict";
var logger = require('./logger');
var spotifyPlaylist = require('./spotifyPlaylist');
var radioCrawler = require('./radioCrawler');
var spotifySearch = require('./spotifySearch');
var fs = require('fs');
var config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
// starting the procedure
start();
function start(){
let playlistName = process.argv[2];
if(!playlistName || !config.playlists[playlistName]){
logger.log('Error: playlist not found');
process.exit();
}
spotifyPlaylist.getAllTracks(playlistName)
.then(() => radioCrawler.getTracks(playlistName))
.then(radioTracks => radioCrawler.cleanTracks(radioTracks))
.then(cleanedTracks => spotifySearch.searchTracks(cleanedTracks, playlistName))
.then(newTracks => spotifyPlaylist.addTracks(playlistName, newTracks))
.then(process.exit)
.catch((error) => {
let message = 'Unknown Error';
if(typeof error === 'string'){
message = error;
}
logger.log('exited due to error: ' + message, playlistName);
process.exit();
});
}
module.exports = {
start: start
};