jellyfin-qbittorrent-monitor: cleanup
This commit is contained in:
parent
f40f9748a4
commit
8aabd1466e
@ -67,9 +67,7 @@ class JellyfinQBittorrentMonitor:
|
||||
def check_jellyfin_sessions(self) -> list[str]:
|
||||
"""Check if anyone is actively streaming from Jellyfin (external networks only)"""
|
||||
try:
|
||||
headers = {}
|
||||
if self.jellyfin_api_key:
|
||||
headers["X-Emby-Token"] = self.jellyfin_api_key
|
||||
headers = {"X-Emby-Token": self.jellyfin_api_key} if self.jellyfin_api_key else {}
|
||||
|
||||
response = requests.get(
|
||||
f"{self.jellyfin_url}/Sessions", headers=headers, timeout=10
|
||||
@ -83,20 +81,14 @@ class JellyfinQBittorrentMonitor:
|
||||
if (
|
||||
"NowPlayingItem" in session
|
||||
and not session.get("PlayState", {}).get("IsPaused", True)
|
||||
and not self.is_local_ip(session.get("RemoteEndPoint", ""))
|
||||
):
|
||||
# Check if session is from external network
|
||||
remote_endpoint = session.get("RemoteEndPoint", "")
|
||||
if remote_endpoint and self.is_local_ip(remote_endpoint):
|
||||
logger.debug(f"Skipping local session from {remote_endpoint}")
|
||||
continue
|
||||
|
||||
item = session["NowPlayingItem"]
|
||||
# Only count video streams (Movies, Episodes, etc.)
|
||||
item_type = item.get("Type", "").lower()
|
||||
if item_type in ["movie", "episode", "video"]:
|
||||
user = session.get("UserName", "Unknown")
|
||||
client_info = f" (from {remote_endpoint})" if remote_endpoint else ""
|
||||
active_streams.append(f"{user}: {item.get('Name', 'Unknown')}{client_info}")
|
||||
active_streams.append(f"{user}: {item.get('Name', 'Unknown')}")
|
||||
|
||||
return active_streams
|
||||
|
||||
|
||||
@ -243,9 +243,9 @@ pkgs.testers.runNixOSTest {
|
||||
systemd-run --unit=jellyfin-qbittorrent-monitor-test \\
|
||||
--setenv=JELLYFIN_URL=http://localhost:8096 \\
|
||||
--setenv=QBITTORRENT_URL=http://localhost:8080 \\
|
||||
--setenv=CHECK_INTERVAL=2 \\
|
||||
--setenv=STREAMING_START_DELAY=2 \\
|
||||
--setenv=STREAMING_STOP_DELAY=3 \\
|
||||
--setenv=CHECK_INTERVAL=1 \\
|
||||
--setenv=STREAMING_START_DELAY=1 \\
|
||||
--setenv=STREAMING_STOP_DELAY=1 \\
|
||||
{python_path} {monitor_path}
|
||||
""")
|
||||
|
||||
@ -265,7 +265,7 @@ pkgs.testers.runNixOSTest {
|
||||
|
||||
# Set streaming state
|
||||
set_jellyfin_state(streaming=True, paused=is_paused, local=is_local, media_type=media_type)
|
||||
time.sleep(6) # Wait for monitor to detect and apply changes
|
||||
time.sleep(1.5) # Wait for monitor to detect and apply changes
|
||||
|
||||
throttling_active = get_throttling_state()
|
||||
|
||||
@ -286,23 +286,23 @@ pkgs.testers.runNixOSTest {
|
||||
assert not throttling_active, f"Expected no throttling for {media_type}, {'paused' if is_paused else 'playing'}, {'local' if is_local else 'external'}"
|
||||
|
||||
set_jellyfin_state(streaming=False)
|
||||
time.sleep(7) # Wait for stop delay
|
||||
time.sleep(1.5) # Wait for stop delay
|
||||
|
||||
assert not get_throttling_state(), "No streaming should disable throttling"
|
||||
|
||||
# Start with throttling-enabled state
|
||||
set_jellyfin_state(streaming=True, paused=False, local=False, media_type="Movie")
|
||||
time.sleep(6)
|
||||
time.sleep(1.5)
|
||||
assert get_throttling_state(), "Should enable throttling for external Movie"
|
||||
|
||||
# Switch to paused (should disable throttling)
|
||||
set_jellyfin_state(streaming=True, paused=True, local=False, media_type="Movie")
|
||||
time.sleep(6)
|
||||
time.sleep(1.5)
|
||||
assert not get_throttling_state(), "Should disable throttling when paused"
|
||||
|
||||
# Switch back to playing (should re-enable throttling)
|
||||
set_jellyfin_state(streaming=True, paused=False, local=False, media_type="Movie")
|
||||
time.sleep(6)
|
||||
time.sleep(1.5)
|
||||
assert get_throttling_state(), "Should re-enable throttling when unpaused"
|
||||
'';
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user