#!/usr/bin/env bash JELLYFIN_URL="http://localhost:8096" API_KEY="KEY" # Query /Sessions and count how many sessions have a NowPlayingItem object ACTIVE_STREAMS=$(curl -s -H "Authorization: MediaBrowser Token=\"$API_KEY\"" \ "$JELLYFIN_URL/Sessions" | jq '[.[] | select(.NowPlayingItem != null)] | length') # Ensure we got a valid number back (in case Jellyfin is already down or unreachable) if ! [[ "$ACTIVE_STREAMS" =~ ^[0-9]+$ ]]; then echo "Error: Could not retrieve session count from Jellyfin." exit 1 fi if [ "$ACTIVE_STREAMS" -gt 0 ]; then echo "Aborting restart: $ACTIVE_STREAMS active stream(s) in progress." exit 0 else echo "No active streams detected. Restarting Jellyfin..." #systemctl restart jellyfin fi