diff --git a/.gitignore b/.gitignore index 8da0357..b4e7f61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -run.sh node_modules import -import.sh +*.sh diff --git a/index.js b/index.js index d118ad1..cfea282 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,15 @@ const stats = new Statistics(models) const list = new List(models) const preferences = new Preferences(models) +let titlePath = null +let artistPath = null +if (process.env.STREAM_PATH_TITLE) { + titlePath = process.env.STREAM_PATH_TITLE.split('.') +} +if (process.env.STREAM_PATH_ARTIST) { + artistPath = process.env.STREAM_PATH_ARTIST.split('.') +} + // Stockage du morceau en cours de lecture let currentSong = { artist: null, @@ -89,14 +98,27 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') { }, (error, response, body) => { if (!error && response.statusCode === 200) { - const res = JSON.parse(body) + const res = JSON.parse(process.env.STREAM_PARSE ? body.replace('updateFromMediaItem(', '').replace(');', '') : body) + + let title = null + let artist = null switch (process.env.STREAM_TYPE) { case 'json': - currentSong = { - title: res.title, - artist: res.artist + title = res[titlePath[0]] + for (let i = 1; i < titlePath.length; i += 1) { + title = title[titlePath[i]] } + artist = res[artistPath[0]] + for (let i = 1; i < artistPath.length; i += 1) { + artist = artist[artistPath[i]] + } + + currentSong = { + title: title, + artist: artist + } + console.log(currentSong) break case 'alien': try {