Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Jellyfin/Emby version before attempting partial update #181

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/emby.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ def __init__(self, baseurl, token):
super().__init__(
server_type="Emby", baseurl=baseurl, token=token, headers=headers
)

def is_partial_update_supported(self, version):
version_parts = version.split('.')
major, minor, patch = map(int, version_parts[:3])
return major > 4 or (major >= 4 and minor >= 4)
5 changes: 5 additions & 0 deletions src/jellyfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ def __init__(self, baseurl, token):
super().__init__(
server_type="Jellyfin", baseurl=baseurl, token=token, headers=headers
)

def is_partial_update_supported(self, version):
version_parts = version.split('.')
major, minor, patch = map(int, version_parts[:3])
return major > 10 or (major >= 10 and minor >= 9)
38 changes: 36 additions & 2 deletions src/jellyfin_emby.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,19 @@ def info(self) -> str:
logger(f"{self.server_type}: Get server name failed {e}", 2)
raise Exception(e)

def get_server_version(self):
try:
response = self.query('/System/Info/Public', 'get')

if response:
return response['Version']
else:
return None

except Exception as e:
logger(f"{self.server_type}: Get server version failed: {e}", 2)
raise Exception(e)

def get_users(self):
try:
users = {}
Expand Down Expand Up @@ -500,7 +513,7 @@ def get_watched(
raise Exception(e)

def update_user_watched(
self, user_name, user_id, library, library_id, videos, dryrun
self, user_name, user_id, library, library_id, videos, update_partial, dryrun
):
try:
logger(
Expand Down Expand Up @@ -561,6 +574,9 @@ def update_user_watched(
jellyfin_video.get("Name"),
)
else:
if not update_partial:
return

msg = f"{self.server_type}: {jellyfin_video.get('Name')} as partially watched for {floor(movie_status['time'] / 60_000)} minutes for {user_name} in {library}"

if not dryrun:
Expand Down Expand Up @@ -690,6 +706,9 @@ def update_user_watched(
jellyfin_episode.get("Name"),
)
else:
if not update_partial:
return

msg = (
f"{self.server_type}: {jellyfin_episode['SeriesName']} {jellyfin_episode['SeasonName']} Episode {jellyfin_episode.get('IndexNumber')} {jellyfin_episode.get('Name')}"
+ f" as partially watched for {floor(episode_status['time'] / 60_000)} minutes for {user_name} in {library}"
Expand Down Expand Up @@ -741,6 +760,15 @@ def update_watched(
self, watched_list, user_mapping=None, library_mapping=None, dryrun=False
):
try:
server_version = self.get_server_version()
update_partial = self.is_partial_update_supported(server_version)

if not update_partial:
logger(
f"{self.server_type}: Server version {server_version} does not support updating playback position.",
2,
)

for user, libraries in watched_list.items():
logger(f"{self.server_type}: Updating for entry {user}, {libraries}", 1)
user_other = None
Expand Down Expand Up @@ -813,7 +841,13 @@ def update_watched(

if library_id:
self.update_user_watched(
user_name, user_id, library, library_id, videos, dryrun
user_name,
user_id,
library,
library_id,
videos,
update_partial,
dryrun
)

except Exception as e:
Expand Down
Loading