Updated JSON
This commit is contained in:
parent
c093e4bf64
commit
7520ac0a9b
2 changed files with 27 additions and 6 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
||||||
run.sh
|
|
||||||
node_modules
|
node_modules
|
||||||
import
|
import
|
||||||
import.sh
|
*.sh
|
||||||
|
|
30
index.js
30
index.js
|
@ -17,6 +17,15 @@ const stats = new Statistics(models)
|
||||||
const list = new List(models)
|
const list = new List(models)
|
||||||
const preferences = new Preferences(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
|
// Stockage du morceau en cours de lecture
|
||||||
let currentSong = {
|
let currentSong = {
|
||||||
artist: null,
|
artist: null,
|
||||||
|
@ -89,14 +98,27 @@ if (!process.env.STREAM_TYPE || process.env.STREAM_TYPE === 'radio') {
|
||||||
},
|
},
|
||||||
(error, response, body) => {
|
(error, response, body) => {
|
||||||
if (!error && response.statusCode === 200) {
|
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) {
|
switch (process.env.STREAM_TYPE) {
|
||||||
case 'json':
|
case 'json':
|
||||||
currentSong = {
|
title = res[titlePath[0]]
|
||||||
title: res.title,
|
for (let i = 1; i < titlePath.length; i += 1) {
|
||||||
artist: res.artist
|
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
|
break
|
||||||
case 'alien':
|
case 'alien':
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue