Merge pull request #11 from luigi311/dev

Fix plex login, Match plex marking logic to jellyfin
This commit is contained in:
Luigi311
2022-06-11 13:48:57 -06:00
committed by GitHub
6 changed files with 94 additions and 79 deletions

View File

@@ -1,30 +1,35 @@
# 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"
# Additional logging information
## Additional logging information
DEBUG = "True"
# How often to run the script in seconds
## How often to run the script in seconds
SLEEP_DURATION = "3600"
# Log file where all output will be written to
## Log file where all output will be written to
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" }
# 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" }
# 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 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"
# 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_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 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"
# 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 = ""
#WHITELIST_LIBRARY = ""
#BLACKLIST_LIBRARY_TYPE = ""

View File

@@ -1,5 +1,7 @@
# JellyPlex-Watched
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/26b47c5db63942f28f02f207f692dc85)](https://www.codacy.com/gh/luigi311/JellyPlex-Watched/dashboard?utm_source=github.com&utm_medium=referral&utm_content=luigi311/JellyPlex-Watched&utm_campaign=Badge_Grade)
Sync watched between jellyfin and plex
## Description

View File

@@ -11,6 +11,7 @@ plex_baseurl = os.getenv("PLEX_BASEURL")
plex_token = os.getenv("PLEX_TOKEN")
username = os.getenv("PLEX_USERNAME")
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:
@@ -19,25 +20,32 @@ class Plex:
self.token = plex_token
self.username = username
self.password = password
self.servername = servername
self.plex = self.plex_login()
self.admin_user = self.plex.myPlexAccount()
self.users = self.get_plex_users()
def plex_login(self):
if self.baseurl:
if self.token:
# Login via token
plex = PlexServer(self.baseurl, self.token)
elif self.username and self.password:
try:
if self.baseurl and self.token:
# Login via token
plex = PlexServer(self.baseurl, self.token)
elif self.username and self.password and self.servername:
# Login via plex account
account = MyPlexAccount(self.username, self.password)
plex = account.resource(self.baseurl).connect()
plex = account.resource(self.servername).connect()
else:
raise Exception("No plex credentials provided")
else:
raise Exception("No plex baseurl provided")
raise Exception("No complete plex credentials provided")
return plex
except Exception as e:
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
return plex
def get_plex_users(self):
users = self.plex.myPlexAccount().users()
@@ -193,9 +201,9 @@ class Plex:
for guid in episode_search.guids:
guid_source = re.search(r'(.*)://', guid.id).group(1).lower()
guid_id = re.search(r'://(.*)', guid.id).group(1)
for show, seasons in videos.items():
for season, episodes in seasons.items():
for episode in episodes:
for show in videos:
for season in videos[show]:
for episode in videos[show][season]:
for episode_keys, episode_id in episode.items():
if episode_keys == guid_source and episode_id == guid_id:
if episode_search.viewCount == 0: