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