-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSong.js
64 lines (52 loc) · 1.26 KB
/
Song.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
const song_data = require('data-store')({ path: process.cwd() + '/data/song.json' });
class Song {
constructor (sid) {
this.sid = sid; // The Spotify ID for the track.
//this.name = name; //name of song
//this.artist = artist; //song's artist
this.features = {};
}
addFeature (features) {
this.features = features;
this.update()
}
update () {
song_data.set(this.sid, this);
}
delete () {
song_data.del(this.sid);
}
}
Song.addFeatures = (sid, features) => {
let count = 0;
//console.log("\tadding features to songs")
sid.forEach(function(sid) {
let s = song_data.get(sid)
s.addFeature(features[count])
count = count+1
})
song_data.save();
}
Song.getSongs = () => {
return song_data.data;
}
Song.create = (sid) => {
let s = new Song(id)
song_data.set(s.sid, s);
return s;
}
Song.createSongs = (songs) => {
//console.log("\tcreating new songs in db")
songs.forEach(function(sid) {
let song = new Song(sid)
song_data.set(sid, song);
})
}
Song.findByID = (sid) => {
let sData = song_data.get(sid);
if (sData != null) {
return sData;
}
return null;
}
module.exports = Song;