From 115a2c9ffd9053a8d37ed11582a161406118b33d Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Fri, 13 Jul 2018 23:36:33 -0700 Subject: [PATCH] Use plexapi to retrieve a token in tools/plex-gettoken.py --- tools/plex-gettoken.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/tools/plex-gettoken.py b/tools/plex-gettoken.py index ca043775..e54031eb 100644 --- a/tools/plex-gettoken.py +++ b/tools/plex-gettoken.py @@ -1,17 +1,12 @@ -import requests - -url = "https://plex.tv/users/sign_in.json" +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Plex-GetToken is a simple method to retrieve a Plex account token. +""" +from plexapi.myplex import MyPlexAccount username = input("Plex username: ") password = input("Plex password: ") -payload = "user%5Blogin%5D=" + username + "&user%5Bpassword%5D=" + password -headers = { - 'x-plex-client-identifier': "plexapi", - 'x-plex-product': "plexapi", - } - -data = requests.request("POST", url, data=payload, headers=headers) -data = str(data.text) -token = data[(data.find("authToken")+12):((data.find("authToken")+12)+20)] -print(token) \ No newline at end of file +account = MyPlexAccount(username, password) +print(account.authenticationToken) \ No newline at end of file