Jump to content

API 'LastestActivity' field is wrong


embylad892746
Go to solution Solved by embylad892746,

Recommended Posts

embylad892746

I have a simple python script that checks that there have been no active users for at least, the past 10 minutes. Returns True if no active users in last 10 mins, otherwise Returns False if active users in the last 10 mins. It's a useful trigger script to make that i don't stop containers and backup data while users are active.

The script has been running for probably 1 year+ without issue.

However, since March 9th, i noticed it's ALWAYS saying someone is active even when this is not true.  I checked the emby API data and my script is 100% working as expected, the issue is that Emby API is incorrectly reporting the LastActivityDate, specifically for my own account. For example, I have zero devices currently running emby client apps and yet every 5 mins, the LastActivityDate for my admin account updates, but I'm literally not on emby anywhere. This strange behavior only recently started happening.

Was there an API change to a recent emby update that might cause this?

 

Emby Server: Version 4.9.0.10 beta (official Emby docker)

 

import json
import os
import requests
import dateutil.parser as dp
from datetime import datetime, timedelta, timezone


api_token = "<token>"
emby_url  = "<url>"
minutes   = 10

url       = os.path.join(emby_url, "emby", "Users", "?api_key=" + api_token)
headers   = {'Accept': 'application/json'}
response  = requests.get(url, headers=headers)
json_data = json.loads(response.text)
now = datetime.now(timezone.utc)
active_status = False

for user in json_data:
  if "LastActivityDate" in user:
    last_active = dp.isoparse(user["LastActivityDate"])
    if now - timedelta(minutes=minutes) <= last_active <= now:
      active_status = True
      break

print(active_status)

 

Link to comment
Share on other sites

Quote

Was there an API change to a recent emby update that might cause this?

Hi, no, but there's got to be something open that is causing this.

Link to comment
Share on other sites

  • Solution
embylad892746

I didn't find a real solution. I just modified my script to ignore my admin account LastActivityDate. When the emby app is not open on my tv, phone and computer it still says online with updates every 5mins. I absolutetly don't have any other devices logged in or functioning. All i can think of is that somewhere on some device, there is a process running on standby that isn't getting killed. Makes no sense otherwise.

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...