Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/refresh_token.yml
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions tools/plex-refreshtoken.py
Original file line number Diff line number Diff line change
@@ -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)
Loading