Skip to content

Commit

Permalink
Back out ISO time
Browse files Browse the repository at this point in the history
  • Loading branch information
oddstr13 committed Dec 21, 2024
1 parent 3c394bc commit 8d1ae2e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
7 changes: 1 addition & 6 deletions jellyfin_kodi/jellyfin/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,7 @@ def request(self, data, session=None):

else:
try:
# Prefer custom Server-Time header in ISO 8601 format
# TODO: Clean up once the probability of most users having
# the updated server-side plugin is high.
self.config.data["server-time"] = r.headers.get(
"Server-Time", r.headers.get("Date")
)
self.config.data["server-time"] = r.headers.get("Date")
elapsed = int(r.elapsed.total_seconds() * 1000)
response = r.json()
LOG.debug("---<[ http ][%s ms]", elapsed)
Expand Down
24 changes: 8 additions & 16 deletions jellyfin_kodi/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,24 +526,16 @@ def fast_sync(self):

def save_last_sync(self):
_raw_time = self.server.config.data["server-time"]
# The ISO 8601 header always end with Z
if _raw_time and _raw_time[-1] == "Z":
time_now = datetime.strptime(_raw_time, "%Y-%m-%dT%H:%M:%SZ")
else:
try:
# TODO: Clean up once the probability of most users having
# the updated server-side plugin is high.
LOG.warning(
"Server time not in ISO 8601 format, using fallback (update KodiSyncQueue)."
)
import email.utils

time_now = email.utils.parsedate_to_datetime(_raw_time)
try:
import email.utils

time_now = email.utils.parsedate_to_datetime(_raw_time)

except Exception as error:
LOG.warning(error)
LOG.warning("Failed to parse server time, falling back to client time.")
time_now = datetime.utcnow()
except Exception as error:
LOG.warning(error)
LOG.warning("Failed to parse server time, falling back to client time.")
time_now = datetime.utcnow()

# Add some tolerance in case time is out of sync with server
time_now -= timedelta(minutes=2)
Expand Down

0 comments on commit 8d1ae2e

Please sign in to comment.