Merge pull request #11 from luigi311/dev
Fix plex login, Match plex marking logic to jellyfin
This commit is contained in:
29
.env.sample
29
.env.sample
@@ -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"
|
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 = ""
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# JellyPlex-Watched
|
# JellyPlex-Watched
|
||||||
|
|
||||||
|
[](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
|
Sync watched between jellyfin and plex
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|||||||
28
src/plex.py
28
src/plex.py
@@ -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
|
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
|
||||||
|
|
||||||
|
|
||||||
def get_plex_users(self):
|
def get_plex_users(self):
|
||||||
users = self.plex.myPlexAccount().users()
|
users = self.plex.myPlexAccount().users()
|
||||||
@@ -193,9 +201,9 @@ class Plex:
|
|||||||
for guid in episode_search.guids:
|
for guid in episode_search.guids:
|
||||||
guid_source = re.search(r'(.*)://', guid.id).group(1).lower()
|
guid_source = re.search(r'(.*)://', guid.id).group(1).lower()
|
||||||
guid_id = re.search(r'://(.*)', guid.id).group(1)
|
guid_id = re.search(r'://(.*)', guid.id).group(1)
|
||||||
for show, seasons in videos.items():
|
for show in videos:
|
||||||
for season, episodes in seasons.items():
|
for season in videos[show]:
|
||||||
for episode in episodes:
|
for episode in videos[show][season]:
|
||||||
for episode_keys, episode_id in episode.items():
|
for episode_keys, episode_id in episode.items():
|
||||||
if episode_keys == guid_source and episode_id == guid_id:
|
if episode_keys == guid_source and episode_id == guid_id:
|
||||||
if episode_search.viewCount == 0:
|
if episode_search.viewCount == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user