From 5a0d1473d0eea8414a189af2d4641e42378197fc Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:56:29 -0700 Subject: [PATCH 1/2] Add helper script to refresh account token --- tools/plex-refreshtoken.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tools/plex-refreshtoken.py diff --git a/tools/plex-refreshtoken.py b/tools/plex-refreshtoken.py new file mode 100644 index 000000000..939bb68fc --- /dev/null +++ b/tools/plex-refreshtoken.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Plex-RefreshToken is a simple method to refresh a Plex account token by pinging Plex.tv. +""" +import argparse + +import plexapi +from plexapi.myplex import MyPlexAccount + + +def refresh_token(token): + """Refresh the Plex authentication token.""" + account = MyPlexAccount(token=token) + if account.ping(): + print("Plex.tv authentication token refreshed successfully.") + else: + print("Failed to refresh Plex.tv authentication token.") + exit(1) + + +if __name__ == "__main__": # noqa: C901 + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--token", + help="Plex.tv authentication token", + default=plexapi.CONFIG.get("auth.server_token"), + ) + + args = parser.parse_args() + if not args.token: + print("No Plex.tv authentication token provided.") + exit(1) + + refresh_token(args.token) From 2d9e791998daadc3089ff2c3b49ec6a1705eb71f Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Thu, 17 Jul 2025 21:56:52 -0700 Subject: [PATCH 2/2] Add GitHub workflow to refresh the CI account token --- .github/workflows/refresh_token.yml | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/refresh_token.yml diff --git a/.github/workflows/refresh_token.yml b/.github/workflows/refresh_token.yml new file mode 100644 index 000000000..4b06aafe6 --- /dev/null +++ b/.github/workflows/refresh_token.yml @@ -0,0 +1,56 @@ +name: Refresh CI Plex Account Token + +on: + workflow_dispatch: ~ + schedule: + - cron: '52 04 * * *' + +env: + CACHE_VERSION: 1 + DEFAULT_PYTHON: 3.9 + +jobs: + refresh-token: + name: Refresh Token + runs-on: ubuntu-latest + steps: + - name: Check out code from Github + uses: actions/checkout@v4 + + - name: Set up Python ${{ env.DEFAULT_PYTHON }} + id: python + uses: actions/setup-python@v5 + with: + python-version: ${{ env.DEFAULT_PYTHON }} + + - name: Restore Python ${{ steps.python.outputs.python-version }} virtual environment + id: cache-venv + uses: actions/cache@v4 + with: + path: venv + key: >- + ${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{ + steps.python.outputs.python-version }}-${{ + hashFiles('requirements_dev.txt') }} + restore-keys: >- + ${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{ + steps.python.outputs.python-version }}- + + - name: Create Python virtual environment + if: steps.cache-venv.outputs.cache-hit != 'true' + run: | + python -m venv venv + . venv/bin/activate + pip install -U pip + pip install -r requirements_dev.txt + pip install -e . + + - name: Set Plex credentials + run: | + echo "PLEXAPI_AUTH_SERVER_TOKEN=${{ secrets.PLEXAPI_AUTH_SERVER_TOKEN }}" >> $GITHUB_ENV + + - name: Refresh account token + run: | + . venv/bin/activate + python \ + -u tools/plex-refreshtoken.py