IvanKaramazov / rpi_plexamp_hack

2 stars 0 forks source link

rpi_plexamp_hack

This repo offers a modified version of the server.prod.js beta code distributed by Plex. I have made a few changes to get the code to work with current Plex infrastructure, but, NB: 1) there may well be other existing bugs in the code that I have not encountered, and 2) new bugs may appear at any time. So no guarantees.

I have done nothing malicious to this file, only the bare minimum code changes I could identify that were required to get it running reliably. However, the file is 85K lines long as prettified automatically by my code editor (JsFormat package in Sublime Text 3 is what I used), so you'll probably have to take my word on that. Up to you.

Changes made

Instructions

  1. Get a working server.json file. Canonical instructions say to use an old Plexamp v1 or v2 installation to generate this, but it only worked partially for me. The file I got from that had only the player and user info defined in the JSON, but a third server object is required (I believe; correct me if it's not). Your final version should look like this:

    {
    "player": {
    "name": "YOUR_SERVER_NAME",
    "identifier": "XXXXXXXXXXXXXXXXXX"
    },
    "user": {
    "id": YOUR_ID_INTEGER,
    "token": "XXXXXXXXXXXXXXXXXX"
    },
    "server": {
    "identifier": "XXXXXXXXXXXXXXXXXX",
    "library": "/library/sections/XX"
    }
    }

    Again, the player and user sections should come through just fine. Server I had to create by hand. To get your server identifier, get an X-Plex-Token (instructions available via Google) and use it to visit the root address of your Plex server, likely at http://YOUR_SERVER_IP:32400/?X-Plex-Token=XXXXXXXXXXXXXXXX. Your server id will be contained in the machineIdentifier attribute of the top-level MediaContainer tag in the XML that you encounter. To get the library info, you need to use the same token to visit http://YOUR_SERVER_IP:32400/library/sections?X-Plex-Token=XXXXXXXXXXXXXXXX. There find the key integer value within any Directory tags living in the tree under the MediaContainer tag. Replace the XX at the end of "/libaray/sections/XX" string in the above example with this value (fill single-digit values with a leading zero as in 02). I have not tested how to deal with multiple libraries on the server yet, but I'm hopeful that simply making a list of library sections will work. Will update when I have more info.

    Once you have added the server definition to your server.json, save it in the same spot the canonical instructions indicate on your RPi.

  2. Download or copy and paste the contents of the server.prod.js file in this repo to your RPi. Your existing server.prod.js should be in ~/plexamp/server/. I would recommend renaming it to server.prod.js.old and then replacing it with the new file you've created.

  3. Get your server's hostname and place it in line 2 of the file, in the plex_server_hostname definition. To find this, visit your server's web interface, find any track and hit "Get Info" on its three-dot menu, then click "View XML" in the box that pops up. You will visit a URL like this: https://192-168-1-X.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.plex.direct:32400/library/metadata/22765?checkFiles=1&many_other_variables=blahblahblah. We care about the protocol and hostname and port here, nothing else, i.e. everything up through the port definition at ":32400". Copy that; do not copy anything starting with "library". Paste this in place of the similar string in line 2 of the server.prod.js file you're creating. No trailing slash after the port, please.

  4. [OPTIONAL] Figure out what address your RPi's MPD instance is listening on and set that in line 4 of this file, in the mpd_ip_address definition. I've left the default of "127.0.0.1" in place, but on my machine I had to update it to "localhost", which worked fine.

  5. Save the file; make sure this version is in the right place and has replaced the old file distributed by Plex.

  6. sudo systemctl restart plexamp

  7. If it doesn't work for you, please reach out and let me know.