mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Use the new Server-Time header from KodiSyncQueue
This commit is contained in:
parent
63c424bc4b
commit
3427ab655d
2 changed files with 20 additions and 10 deletions
|
@ -179,7 +179,10 @@ class HTTP(object):
|
|||
|
||||
else:
|
||||
try:
|
||||
self.config.data["server-time"] = r.headers["Date"]
|
||||
# Prefer custom Server-Time header in ISO 8601 format
|
||||
self.config.data["server-time"] = r.headers.get(
|
||||
"Server-Time", r.headers.get("Date")
|
||||
)
|
||||
elapsed = int(r.elapsed.total_seconds() * 1000)
|
||||
response = r.json()
|
||||
LOG.debug("---<[ http ][%s ms]", elapsed)
|
||||
|
|
|
@ -525,18 +525,25 @@ class Library(threading.Thread):
|
|||
return True
|
||||
|
||||
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:
|
||||
import locale
|
||||
|
||||
try:
|
||||
time_now = datetime.strptime(
|
||||
self.server.config.data["server-time"].split(", ", 1)[1],
|
||||
"%d %b %Y %H:%M:%S GMT",
|
||||
) - timedelta(minutes=2)
|
||||
except Exception as error:
|
||||
old = locale.getlocale(locale.LC_TIME)
|
||||
locale.setlocale(locale.LC_TIME, ("C", "UTF-8"))
|
||||
time_now = datetime.strptime(_raw_time, "%a, %d %b %Y %H:%M:%S %Z")
|
||||
locale.setlocale(locale.LC_TIME, old)
|
||||
except Exception as error:
|
||||
|
||||
LOG.exception(error)
|
||||
time_now = datetime.utcnow() - timedelta(minutes=2)
|
||||
LOG.warning(error)
|
||||
time_now = datetime.utcnow()
|
||||
|
||||
last_sync = time_now.strftime("%Y-%m-%dT%H:%M:%Sz")
|
||||
time_now -= timedelta(minutes=2)
|
||||
last_sync = time_now.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
settings("LastIncrementalSync", value=last_sync)
|
||||
LOG.info("--[ sync/%s ]", last_sync)
|
||||
|
||||
|
|
Loading…
Reference in a new issue