Welcome to Incremental Social! Learn more about this project here!
Check out lemmyverse to find more communities to join from here!

Esca , (edited )

Yep, the api in jellyfin is quite easy. Someone already sent the link to the docs. The specific endpoint you want is Sessions. You need to get yourself an api_key which you can get in the admin panel. Here is an example code in Python to give you an idea on how to use the api:

#!/usr/bin/env python3

import requests

response = requests.get("http://your_jellyfin_server:8096/Sessions?api_key=your_api_key")
json = response.json()

currently_watching = []
for session in json:
    if "NowPlayingItem" in session:
        currently_watching.append(session["UserName"])

if currently_watching:
    print("Currently watching: " + ", ".join(currently_watching))
else:
    print("Nobody is watching")

If it is indeed Python that you want to use, you can adjust it to your needs depending on what you want it to output.

Basically, it is as simple as looping through every current session and checking if they have a NowPlayingItem key which is only present when they have a video open (both playing and paused). It works very reliability, I am using it to automatically change my lights when I watch a long video or movie.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • jellyfin@lemmy.ml
  • incremental_games
  • meta
  • All magazines