mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-27 03:06:10 +00:00
Use the new Server-Time header from KodiSyncQueue
This commit is contained in:
parent
63c424bc4b
commit
3c394bc02c
2 changed files with 27 additions and 10 deletions
|
@ -179,7 +179,12 @@ class HTTP(object):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
self.config.data["server-time"] = r.headers["Date"]
|
# 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")
|
||||||
|
)
|
||||||
elapsed = int(r.elapsed.total_seconds() * 1000)
|
elapsed = int(r.elapsed.total_seconds() * 1000)
|
||||||
response = r.json()
|
response = r.json()
|
||||||
LOG.debug("---<[ http ][%s ms]", elapsed)
|
LOG.debug("---<[ http ][%s ms]", elapsed)
|
||||||
|
|
|
@ -525,18 +525,30 @@ class Library(threading.Thread):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save_last_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:
|
try:
|
||||||
time_now = datetime.strptime(
|
# TODO: Clean up once the probability of most users having
|
||||||
self.server.config.data["server-time"].split(", ", 1)[1],
|
# the updated server-side plugin is high.
|
||||||
"%d %b %Y %H:%M:%S GMT",
|
LOG.warning(
|
||||||
) - timedelta(minutes=2)
|
"Server time not in ISO 8601 format, using fallback (update KodiSyncQueue)."
|
||||||
|
)
|
||||||
|
import email.utils
|
||||||
|
|
||||||
|
time_now = email.utils.parsedate_to_datetime(_raw_time)
|
||||||
|
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
LOG.warning(error)
|
||||||
|
LOG.warning("Failed to parse server time, falling back to client time.")
|
||||||
|
time_now = datetime.utcnow()
|
||||||
|
|
||||||
LOG.exception(error)
|
# Add some tolerance in case time is out of sync with server
|
||||||
time_now = datetime.utcnow() - timedelta(minutes=2)
|
time_now -= timedelta(minutes=2)
|
||||||
|
|
||||||
last_sync = time_now.strftime("%Y-%m-%dT%H:%M:%Sz")
|
last_sync = time_now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
settings("LastIncrementalSync", value=last_sync)
|
settings("LastIncrementalSync", value=last_sync)
|
||||||
LOG.info("--[ sync/%s ]", last_sync)
|
LOG.info("--[ sync/%s ]", last_sync)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue