File tree Expand file tree Collapse file tree 2 files changed +91
-0
lines changed
Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Refresh CI Plex Account Token
2+
3+ on :
4+ workflow_dispatch : ~
5+ schedule :
6+ - cron : ' 52 04 * * *'
7+
8+ env :
9+ CACHE_VERSION : 1
10+ DEFAULT_PYTHON : 3.9
11+
12+ jobs :
13+ refresh-token :
14+ name : Refresh Token
15+ runs-on : ubuntu-latest
16+ steps :
17+ - name : Check out code from Github
18+ uses : actions/checkout@v4
19+
20+ - name : Set up Python ${{ env.DEFAULT_PYTHON }}
21+ id : python
22+ uses : actions/setup-python@v5
23+ with :
24+ python-version : ${{ env.DEFAULT_PYTHON }}
25+
26+ - name : Restore Python ${{ steps.python.outputs.python-version }} virtual environment
27+ id : cache-venv
28+ uses : actions/cache@v4
29+ with :
30+ path : venv
31+ key : >-
32+ ${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
33+ steps.python.outputs.python-version }}-${{
34+ hashFiles('requirements_dev.txt') }}
35+ restore-keys : >-
36+ ${{ env.CACHE_VERSION }}-${{ runner.os }}-venv-${{
37+ steps.python.outputs.python-version }}-
38+
39+ - name : Create Python virtual environment
40+ if : steps.cache-venv.outputs.cache-hit != 'true'
41+ run : |
42+ python -m venv venv
43+ . venv/bin/activate
44+ pip install -U pip
45+ pip install -r requirements_dev.txt
46+ pip install -e .
47+
48+ - name : Set Plex credentials
49+ run : |
50+ echo "PLEXAPI_AUTH_SERVER_TOKEN=${{ secrets.PLEXAPI_AUTH_SERVER_TOKEN }}" >> $GITHUB_ENV
51+
52+ - name : Refresh account token
53+ run : |
54+ . venv/bin/activate
55+ python \
56+ -u tools/plex-refreshtoken.py
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+ """
4+ Plex-RefreshToken is a simple method to refresh a Plex account token by pinging Plex.tv.
5+ """
6+ import argparse
7+
8+ import plexapi
9+ from plexapi .myplex import MyPlexAccount
10+
11+
12+ def refresh_token (token ):
13+ """Refresh the Plex authentication token."""
14+ account = MyPlexAccount (token = token )
15+ if account .ping ():
16+ print ("Plex.tv authentication token refreshed successfully." )
17+ else :
18+ print ("Failed to refresh Plex.tv authentication token." )
19+ exit (1 )
20+
21+
22+ if __name__ == "__main__" : # noqa: C901
23+ parser = argparse .ArgumentParser (description = __doc__ )
24+ parser .add_argument (
25+ "--token" ,
26+ help = "Plex.tv authentication token" ,
27+ default = plexapi .CONFIG .get ("auth.server_token" ),
28+ )
29+
30+ args = parser .parse_args ()
31+ if not args .token :
32+ print ("No Plex.tv authentication token provided." )
33+ exit (1 )
34+
35+ refresh_token (args .token )
You can’t perform that action at this time.
0 commit comments