More > JRiver Media Center 27 for Linux
Remote Control/Automation issues
RemyJ:
Well, I use Python, JavaScript or just plain BASH for scripting depending on the task and yes, there are plenty of solutions out there to get JSON from XML. Not the point though. I'd like MC to do it.
max096:
--- Quote from: RemyJ on May 20, 2021, 04:28:36 pm ---Well, I use Python, JavaScript or just plain BASH for scripting depending on the task and yes, there are plenty of solutions out there to get JSON from XML. Not the point though. I'd like MC to do it.
--- End quote ---
Thatīs fair. I donīt know how much effort it is for them to make it return JSON, given that in there are threads from 2017 where people asked for the first ever JSON endpoints and they straight up said 'no, too much work for now'. Im under the impression they did it later to improve performance of jpanel for instance and less so to please other people using the APIs.
Maybe there is a chance. Hopefully, somebody who actually works for JRiver can step in and awnswer that part. But either way you are probably better off just getting it done for now, I think.
For good measures here is a little more condenced nodejs version
--- Code: ---const fetch = require('node-fetch');
const xml2js = require('xml2js')
const ip = '<ip>'
const port = '52199'
const username = '<username>'
const password = '<password>'
async function parseMpl(textContent) {
const xmlContent = await xml2js.parseStringPromise(textContent)
let response = {};
Object.entries(xmlContent.Response.Item).forEach(([_, item]) => {
const name = item['$']['Name']
const value = item['_']
response[name] = value;
})
return response;
}
async function getPlaybackInfo() {
const response = await fetch(`http://${ip}:${port}/MCWS/v1/Playback/Info?Zone=-1`, {
method: 'GET',
headers: {
'Authorization': `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`
}
})
if(response.status != 200)
throw `Status code ${response.status} does not indicate success.`
const textContent = await response.text()
return await parseMpl(textContent)
}
async function main() {
const result = await getPlaybackInfo()
console.log(JSON.stringify(result))
}
main()
--- End code ---
Would be similar in the browser. Fetch just exists, instead of Buffer and toString('base64') you can use atob and instead of xml2js use DOMParser.
bob:
--- Quote from: RemyJ on May 16, 2021, 01:45:20 pm ---Besides fiddling with Library Servers, I'm also fiddling with my remote control/automation stuff. I think these have been mentioned before but it's been a while so I thought I'd mention them again. None of the /MCC, /Play, /Pause, /Stop, etc command line options do anything other than give focus to the currently running instance (which is bad by itself). /MCWS/* options do work but because they also give focus to the running instance, they're not really useful for automation.
Using the MCWS via the network works fine of course but it does require that the media server be started. That's fine but could we get an option to get the MCWS output in JSON rather than XML? JSON is much easier to work with in most scripting languages.
--- End quote ---
Actually MCC is implemented in the last builds of MC27.
Use the /usr/lib/jriver/Media\ Center\ 27/mc27
stub to do them.
RemyJ:
Ah, thanks Bob! Yeah it does work with the stub.
max096:
--- Quote from: bob on May 21, 2021, 11:42:54 am ---Actually MCC is implemented in the last builds of MC27.
Use the /usr/lib/jriver/Media\ Center\ 27/mc27
stub to do them.
--- End quote ---
Thatīs pretty cool! Didnīt know that was a thing since MC27 somewhen. Kinda overslept that part. MCWS is great, but it kind of falls apart when you want to build automation into things where you cannot (yet) know what the username and password is gonna be for MC.
Navigation
[0] Message Index
[*] Previous page
Go to full version