1. No user installed addons are supported, python or otherwise.
2. No, they really are not supported.
3. They are not coming back
4. Read from 1. again

Any mention of illegal streaming sites, addons or any pirated material will not be tolerated. This is not democracy and any offenders will be banned and posts deleted immediately without warning.

Other than that, we hope you enjoy MrMC so far and we welcome any input and feedback you might have.

Team MrMC.

How-To: Remotely manage library updates via JSON methods

Please, only How to's in here. No questions or support, use appropriate subsection for that
Post Reply
User avatar
zakaron
Posts: 17
Joined: 17 Oct 2016, 21:00

How-To: Remotely manage library updates via JSON methods

Post by zakaron »

Thought I'd do this write-up based on my experience to show how to update the MrMC libraries from a remote computer. By "remote", I mean another computer that is able to access your MrMC client. And technically this is not specific to MrMC as it does work with Kodi clients as well.

For my management purposes, it is easier most times to just run a scan or clean script from where I'm at instead of going to one of my Apple TV boxes to manually do a library scan or clean. In fact, sometimes I manage my media remotely (outside of the house) so being able to send a JSON command via Curl works out well. You may also want to do periodic or nightly scans / cleans, so this can tie in perfectly with a cron job.

Prerequisites:
1. MrMC must allow remote connections
2. Computer with curl installed

1. To allow remote connections to MrMC, go to Settings --> Services. It should be under the web server section. You'll want to enable "allow remote control via HTTP". Default port is fine; this is what I reference in the commands below. I didn't bother setting a username or password since this is only accessible inside my LAN.

2. Curl is probably the most popular method of manipulating / transferring a URL string from a command prompt. I have a FreeNAS server running MythTV, so this works out well in my case.


Essentially you are sending an HTTP POST to the MrMC web server that you enabled in step 1 that contains a JSON method & parameters to interact the with MrMC API. In my examples, I am using the VideoLibrary.Scan and VideoLibrary.Clean methods. Since I want this to be unattended and nonintrusive to the client, I pass the params "showdialogs": false. If left true, the Clean method would end up prompting to keep / remove at the end, and that defeats the purpose of having it run remotely! If you left the showdiags true for the Scan method, anyone using the client would see the message in the top right that the library is being updated. If you would like more info on all the methods available, check out: http://kodi.wiki/view/JSON-RPC_API/v6

Well enough talk. Here is the main code portion that you can incorporate into any shell script.
First the Scan:

Code: Select all

 curl -s -L -m3 --connect-timeout 5 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"VideoLibrary.Scan", "params": { "showdialogs": false }, "id":1}' http://<MrMC_host>:8080/jsonrpc > /dev/null 
Clean is very similar:

Code: Select all

 curl -s -L -m3 --connect-timeout 5 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"VideoLibrary.Clean", "params": { "showdialogs": false }, "id":1}' http://<MrMC_host>:8080/jsonrpc > /dev/null 
In the above examples, you would want to substitute <MrMC_host> for the IP or hostname (if you have DNS running on your network) for whatever MrMC client you want to send the request to. Some of the parameters I use:
-s = silent, as in no output from Curl (does not suppress the JSON API output however).
-m3 = max time of 3 seconds to stay connected. I just want to pass the method request and leave.
--connect-timeout 5 = timeout after 5 seconds. If the client is down or MrMC is not running, don't spend more time than necessary trying to connect.
If you happened to set a username and/or password when you enabled remote access in MrMC settings, you can use the -u option to pass a "username:password" or just a username and have it prompt you for the password.
At the very end, I do redirect all messages sent to stout (screen) to the black hole of /dev/null. If you want JSON output, then you can leave this off, but for my script all I want is the curl exit code. If curl exits with anything but 0, then there was an error and so I know the scan or clean didn't run. For more info on curl: https://curl.haxx.se/docs/manpage.html

I hope this helps anyone looking for a way to script library updates or cleans. I also hope this prompts the devs to keep the API included in future releases :D
User avatar
davilla
Team MrMC
Posts: 4377
Joined: 26 Oct 2015, 17:01

Re: How-To: Remotely manage library updates via JSON methods

Post by davilla »

Nice post, thx and don't worry, that API is here to stay.
Post Reply