a79039156c3075c378f6e74d984ff8042c360b51
[DeezloaderRemix.git] / app / lib / deezer-api / obj / Album.js
1 const Track = require('./Track.js')
2
3 module.exports = class Album {
4   constructor(body){
5     switch (body.sourcePage){
6       case 'album.getData':
7         this.id = body.ALB_ID
8         this.title = body.ALB_TITLE
9         this.picture = body.ALB_PICTURE
10         this.artist = {
11           id: body.ART_ID,
12           name: body.ART_NAME
13         }
14         this.label = body.LABEL_NAME
15         this.discTotal = body.NUMBER_DISK
16         this.trackTotal = body.NUMBER_TRACK
17         this.explicit = body.EXPLICIT_ALBUM_CONTENT.EXPLICIT_LYRICS_STATUS > 0
18         this.date = {
19           day: body.PHYSICAL_RELEASE_DATE.slice(8,10),
20           month: body.PHYSICAL_RELEASE_DATE.slice(5,7),
21           year: body.PHYSICAL_RELEASE_DATE.slice(0, 4)
22         }
23       break
24       case 'deezer.pageAlbum':
25         this.id = body.DATA.ALB_ID
26         this.title = body.DATA.ALB_TITLE
27         this.picture = body.DATA.ALB_PICTURE
28         this.artist = {
29           id: body.DATA.ART_ID,
30           name: body.DATA.ART_NAME
31         }
32         body.DATA.ARTISTS.forEach(artist=>{
33           if (artist.__TYPE__ == "artist") this.artists.push({
34             id: artist.ART_ID,
35             name: artist.ART_NAME,
36             picture: artist.ART_PICTURE
37           })
38         })
39         this.label = body.DATA.LABEL_NAME
40         this.date = {
41           day: body.DATA.PHYSICAL_RELEASE_DATE.slice(8,10),
42           month: body.DATA.PHYSICAL_RELEASE_DATE.slice(5,7),
43           year: body.DATA.PHYSICAL_RELEASE_DATE.slice(0, 4)
44         }
45         this.explicit = body.DATA.EXPLICIT_ALBUM_CONTENT.EXPLICIT_LYRICS_STATUS > 0
46         this.barcode = body.DATA.UPC
47         this.trackTotal = body.SONGS.total
48         this.tracks = []
49         body.SONGS.data.forEach(track=>{
50           track.sourcePage = 'deezer.pageAlbum'
51           this.tracks.push(new Track(track))
52         })
53       break
54     }
55   }
56 }