Updated JSON

This commit is contained in:
dbroqua 2020-01-06 20:14:12 +01:00
parent c093e4bf64
commit 7520ac0a9b
2 changed files with 27 additions and 6 deletions

3
.gitignore vendored
View File

@ -1,4 +1,3 @@
run.sh
node_modules
import
import.sh
*.sh

View File

@ -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 {