Fix plex login via username

pull/11/head
Luigi311 2022-06-11 13:29:30 -06:00
parent 368bd35b16
commit ed536fdc81
2 changed files with 37 additions and 24 deletions

View File

@ -1,33 +1,38 @@
# Do not mark any shows/movies as played and instead just output to log if they would of been marked. ## Do not mark any shows/movies as played and instead just output to log if they would of been marked.
DRYRUN = "True" DRYRUN = "True"
# Additional logging information ## Additional logging information
DEBUG = "True" DEBUG = "True"
# How often to run the script in seconds ## How often to run the script in seconds
SLEEP_DURATION = "3600" SLEEP_DURATION = "3600"
# Log file where all output will be written to ## Log file where all output will be written to
LOGFILE = "log.log" LOGFILE = "log.log"
# Map usernames between plex and jellyfin in the event that they are different, order does not matter ## Map usernames between plex and jellyfin in the event that they are different, order does not matter
#USER_MAPPING = { "testuser2": "testuser3" } #USER_MAPPING = { "testuser2": "testuser3" }
# Map libraries between plex and jellyfin in the even that they are different, order does not matter ## Map libraries between plex and jellyfin in the even that they are different, order does not matter
#LIBRARY_MAPPING = { "Shows": "TV Shows" } #LIBRARY_MAPPING = { "Shows": "TV Shows" }
# URL of the plex server, use hostname or IP address if the hostname is not resolving correctly
## Recommended to use token as it is faster to connect as it is direct to the server instead of going through the plex servers
## URL of the plex server, use hostname or IP address if the hostname is not resolving correctly
PLEX_BASEURL = "http://localhost:32400" PLEX_BASEURL = "http://localhost:32400"
# Plex token https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/ ## Plex token https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/
PLEX_TOKEN = "SuperSecretToken" PLEX_TOKEN = "SuperSecretToken"
# If not using plex token then use username and password of the server admin ## If not using plex token then use username and password of the server admin along with the servername
#PLEX_USERNAME = "" #PLEX_USERNAME = ""
#PLEX_PASSWORD = "" #PLEX_PASSWORD = ""
#PLEX_SERVERNAME = "Plex Server"
# Jellyfin server URL, use hostname or IP address if the hostname is not resolving correctly
## Jellyfin server URL, use hostname or IP address if the hostname is not resolving correctly
JELLYFIN_BASEURL = "http://localhost:8096" JELLYFIN_BASEURL = "http://localhost:8096"
# Jellyfin api token, created manually by logging in to the jellyfin server admin dashboard and creating an api key ## Jellyfin api token, created manually by logging in to the jellyfin server admin dashboard and creating an api key
JELLYFIN_TOKEN = "SuperSecretToken" JELLYFIN_TOKEN = "SuperSecretToken"
# Blacklisting/Whitelisting libraries, library types such as Movies, TV Shows, and users. Mappings apply so if the mapping for the user or library exist then both will be excluded.
## Blacklisting/Whitelisting libraries, library types such as Movies/TV Shows, and users. Mappings apply so if the mapping for the user or library exist then both will be excluded.
#BLACKLIST_LIBRARY = "" #BLACKLIST_LIBRARY = ""
#WHITELIST_LIBRARY = "" #WHITELIST_LIBRARY = ""
#BLACKLIST_LIBRARY_TYPE = "" #BLACKLIST_LIBRARY_TYPE = ""
#WHITELIST_LIBRARY_TYPE = "" #WHITELIST_LIBRARY_TYPE = ""
#BLACKLIST_USERS = "" #BLACKLIST_USERS = ""
WHITELIST_USERS = "testuser1,testuser2" WHITELIST_USERS = "testuser1,testuser2"

View File

@ -11,6 +11,7 @@ plex_baseurl = os.getenv("PLEX_BASEURL")
plex_token = os.getenv("PLEX_TOKEN") plex_token = os.getenv("PLEX_TOKEN")
username = os.getenv("PLEX_USERNAME") username = os.getenv("PLEX_USERNAME")
password = os.getenv("PLEX_PASSWORD") password = os.getenv("PLEX_PASSWORD")
servername = os.getenv("PLEX_SERVERNAME")
# class plex accept base url and token and username and password but default with none # class plex accept base url and token and username and password but default with none
class Plex: class Plex:
@ -19,25 +20,32 @@ class Plex:
self.token = plex_token self.token = plex_token
self.username = username self.username = username
self.password = password self.password = password
self.servername = servername
self.plex = self.plex_login() self.plex = self.plex_login()
self.admin_user = self.plex.myPlexAccount() self.admin_user = self.plex.myPlexAccount()
self.users = self.get_plex_users() self.users = self.get_plex_users()
def plex_login(self): def plex_login(self):
if self.baseurl: try:
if self.token: if self.baseurl and self.token:
# Login via token # Login via token
plex = PlexServer(self.baseurl, self.token) plex = PlexServer(self.baseurl, self.token)
elif self.username and self.password: elif self.username and self.password and self.servername:
# Login via plex account # Login via plex account
account = MyPlexAccount(self.username, self.password) account = MyPlexAccount(self.username, self.password)
plex = account.resource(self.baseurl).connect() plex = account.resource(self.servername).connect()
else: else:
raise Exception("No plex credentials provided") raise Exception("No complete plex credentials provided")
else:
raise Exception("No plex baseurl provided") return plex
except Exception as e:
return plex if self.username or self.password:
msg = f"Failed to login via plex account {self.username}"
logger(f"Plex: Failed to login, {msg}, Error: {e}", 2)
else:
logger(f"Plex: Failed to login, Error: {e}", 2)
return None
def get_plex_users(self): def get_plex_users(self):
users = self.plex.myPlexAccount().users() users = self.plex.myPlexAccount().users()