Skip to content

Commit 5a0d147

Browse files
committed
Add helper script to refresh account token
1 parent 9d71a81 commit 5a0d147

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tools/plex-refreshtoken.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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)

0 commit comments

Comments
 (0)