No description
Find a file
2023-10-01 21:24:58 +05:30
.github/workflows Dockerisation 2023-10-01 19:11:42 +05:30
models Added config option to hide media's total duration 2022-09-06 01:05:22 +05:30
services Dockerisation 2023-10-01 19:11:42 +05:30
store Fixed issues with non-interactive environments 2023-10-01 21:24:58 +05:30
utils Fixed issue while running in background 2022-05-22 10:07:09 +05:30
.dockerignore Dockerisation 2023-10-01 19:11:42 +05:30
.gitignore Dockerisation 2023-10-01 19:11:42 +05:30
CONTRIBUTING.md Tweaks 2022-09-06 01:22:18 +05:30
Dockerfile Dockerisation 2023-10-01 19:11:42 +05:30
LICENSE README tweaks 2023-02-28 18:05:53 +05:30
main.py Fixed issues with non-interactive environments 2023-10-01 21:24:58 +05:30
NOTICE Dockerisation 2023-10-01 19:11:42 +05:30
pyrightconfig.json Fixed issue while running in background 2022-05-22 10:07:09 +05:30
README.md Fixed issues with non-interactive environments 2023-10-01 21:24:58 +05:30
requirements.txt Fixed versions in requirements.txt 2022-05-11 06:40:28 +05:30
test.py Dockerisation 2023-10-01 19:11:42 +05:30

Discord Rich Presence for Plex

Showcase

Discord Rich Presence for Plex is a Python script which displays your Plex status on Discord using Rich Presence.

Latest Release Build Status

Usage

When the script runs for the first time, a data directory will be created in the current working directory along with a config.json file inside of it. You will be prompted to complete the authentication flow to allow the script to retrieve an access token for your Plex account.

The script must be running on the same machine as your Discord client.

Instructions

  1. Install Python 3.10 - Make sure to tick "Add Python 3.10 to PATH" during the installation.
  2. Download the latest release of this script.
  3. Extract the directory contained in the above ZIP file.
  4. Navigate a command-line interface (cmd.exe, PowerShell, bash, etc.) into the above-extracted directory.
  5. Install the required Python modules by running python -m pip install -U -r requirements.txt.
  6. Start the script by running python main.py.

Alternatively, you can run with Docker if you're using a Linux-based operating system.

Configuration - config.json

  • logging
    • debug (boolean, default: true) - Outputs additional debug-helpful information to the console if enabled.
    • writeToFile (boolean, default: false) - Writes console output to a console.log file in the data directory if enabled.
  • display - Display settings for Rich Presence
    • hideTotalTime (boolean, default: false) - Hides the total duration of the media if enabled.
    • useRemainingTime (boolean, default: false) - Displays the media's remaining time instead of elapsed time if enabled.
    • posters
      • enabled (boolean, default: false) - Displays media posters if enabled. Requires imgurClientID.
      • imgurClientID (string, default: "") - Obtention Instructions
    • buttons (list) - Information
      • label (string) - The label to be displayed on the button.
      • url (string) - A web address or a dynamic URL placeholder.
  • users (list)
    • token (string) - An access token associated with your Plex account. (X-Plex-Token, Authenticating with Plex)
    • servers (list)
      • name (string) - Name of the Plex Media Server you wish to connect to.
      • listenForUser (string, optional) - The script will respond to alerts originating only from this username. Defaults to the parent user's username if not set.
      • blacklistedLibraries (list, optional) - Alerts originating from libraries in this list are ignored.
      • whitelistedLibraries (list, optional) - If set, alerts originating from libraries that are not in this list are ignored.

Obtaining an Imgur client ID

  1. Go to Imgur's application registration page.
  2. Enter any name for the application and pick OAuth2 without a callback URL as the authorisation type.
  3. Submit the form to obtain your application's client ID.

Buttons

Discord can display up to 2 buttons in your Rich Presence.

Due to a strange Discord bug, these buttons are unresponsive or exhibit strange behaviour towards your own clicks, but other users are able to click on them to open their corresponding URLs.

Dynamic Button URLs

During runtime, the following dynamic URL placeholders will get replaced with real URLs based on the media being played:

  • dynamic:imdb
  • dynamic:tmdb

Example

{
  "logging": {
    "debug": true,
    "writeToFile": false
  },
  "display": {
    "hideTotalTime": false,
    "useRemainingTime": false,
    "posters": {
      "enabled": true,
      "imgurClientID": "9e9sf637S8bRp4z"
    },
    "buttons": [
      {
        "label": "IMDb Link",
        "url": "dynamic:imdb"
      },
      {
        "label": "My YouTube Channel",
        "url": "https://www.youtube.com/channel/me"
      }
    ]
  },
  "users": [
    {
      "token": "HPbrz2NhfLRjU888Rrdt",
      "servers": [
        {
          "name": "Bob's Home Media Server"
        },
        {
          "name": "A Friend's Server",
          "listenForUser": "xyz",
          "whitelistedLibraries": ["Movies"]
        }
      ]
    }
  ]
}

Configuration - Environment Variables

  • PLEX_SERVER_NAME - Name of the Plex Media Server you wish to connect to. Used only during the initial setup (when the config file isn't present) for adding a server to the config after authentication. If this isn't set, the user is prompted for an input. In non-interactive environments, "ServerName" is used as a placeholder when this variable isn't set.

Configuration - Discord

The "Display current activity as a status message" setting must be enabled in Discord Settings → Activity Settings → Activity Privacy.

Discord Settings

Run with Docker

Image

ghcr.io/phin05/discord-rich-presence-plex

Volumes

Mount a directory for persistent data (config file, cache file and log file) at /app/data.

The directory where Discord stores its inter-process communication Unix socket file needs to be mounted into the container at /run/app. The path for this would be the first non-null value from the values of the following environment variables: (source)

  • XDG_RUNTIME_DIR
  • TMPDIR
  • TMP
  • TEMP
  • Fallback path: /tmp

Example

docker run \
  -v ./data:/app/data \
  -v /run/user/1000:/run/app:ro \
  --detach \
  --restart unless-stopped \
  --name discord-rich-presence-plex \
  ghcr.io/phin05/discord-rich-presence-plex:latest