Extract Plex Token

The Plex Media Server token can be extracted by opening up the browser development console (F12), switching to the Network tab, then navigating to some item within the Plex Media Server library, selecting the thee dots icon on the item , choosing Get Info, then View XML and then refreshing the page while clicking on the request in the Network tab. The X-Plex-Token should be part of the "Request URL" after refreshing the page and can also be found in the browser URL bar towards the end of the URL.

Plex Library Refresh

#!/bin/bash
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2024 - License: MIT            ##
###########################################################################
# This is a script that will use "xidel" to refresh a Plex Media Server   # 
# library by using the command line options.                              #
###########################################################################
#                                                                         #
# Requirements: xidel                                                     #
#                                                                         #
# The Plex Media Server Token has to be extracted separately as per the   #
# instructions at the URL: https://grimore.org/fuss/plex_media_server     #
#                                                                         #
# Example:                                                                #
#   * ./script -i https://plex.duckdns.org -t IKqeupxk_FENQpo -l Movies   #
#                                                                         #
###########################################################################
 
###########################################################################
#                               INTERNALS                                 #
###########################################################################
 
#set -o xtrace
 
usage() {
    echo "Usage: $0 [-i <URL>] [-t <string>] [-l <string>]" 1>&2
    exit 1
}
 
while getopts ":i:t:l:" o; do
    case "${o}" in
        i)
            PLEX_URL=${OPTARG}
            ;;
        t)
            PLEX_TOKEN=${OPTARG}
            ;;
        l)
            PLEX_LIBRARY=${OPTARG}
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))
 
if [ -z "${PLEX_URL}" ] || [ -z "${PLEX_TOKEN}" ] || [ -z "${PLEX_LIBRARY}" ]; then
    usage
fi
 
# retrieve library key
LIBRARY_KEY=`xidel "${PLEX_URL}/library/sections/?X-Plex-Token=${PLEX_TOKEN}" \
    -s \
    -e \
    "string(//MediaContainer/Directory[matches(@title, '${PLEX_LIBRARY}', 'i')]/@key)"`
 
# refresh library
curl \
    -s ${PLEX_URL}/library/sections/${LIBRARY_KEY}/refresh?X-Plex-Token=${PLEX_TOKEN}

Making Plex Recognize Separate Subtitle Files

Plex does not directly recognize subtitle files that are place along the video files such that the user has to enable the Local Media Assets agent by going to SettingsAgents and then ticking the Local Media Assets box for all collection types, such as "Movies", "Shows", "Artists", "Albums" and "Photos" if available.

The Local Media Assets option makes Plex consider local files as well as refreshing metadata remotely from the other agents. After the option is selected, the metadata has to be refreshed for the libraries that contain video files with subtitles as files.

Headless Initial Setup of Plex Media Server

One of the major headaches with Plex Media Server is that the initial setup is hardwired to only be accessible via the local machine. Accessing a Plex Media Server instance over the network will just result in a deceptive display telling the user to download Plex Media Server, which makes no sense because the user is already accessing the Plex Media Server. The only way to setup Plex initially, is to initiate a connection via the same machine that Plex is installed on and then access http://localhost:32400/web in order to complete the setup. However, accessing Plex via loopback when Plex Media Server is installed remotely is impossible.

One solution is to use SSH and create a tunnel from the local machine, to the machine running Plex and then access the instance via loopback. Here is a sketch representing the SSH tunnel:

+---------+   +-------------------+
| Work PC |   | Plex Media Server |
+----+----+   +---------+---------+
     |                  |
     +------------------+
   10000             32400

with the corresponding command that is executed on the "Work PC" machine:

ssh -L10000:localhost:32400 USER@PLEX.TLD

where:

  • USER is a user on the machine running Plex Media Server,
  • PLEX.TLD is the FQDN of the machine running Plex Media Server (host or IP)

fuss/plex_media_server.txt · Last modified: 2024/11/13 11:52 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.