Skip to content

Commit 88b9738

Browse files
committed
Use very long HTTP timeout to avoid issues when resuming from pause
1 parent 3905b90 commit 88b9738

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

app.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Zero Configuration DLNA Server - A simple DLNA media server."""
2+
23
import hashlib
34
import os
45
import socket
@@ -7,7 +8,7 @@
78
from http.server import ThreadingHTTPServer
89
import argparse
910

10-
try: # Hacky but needed to support both package and module imports
11+
try: # Hacky but needed to support both package and module imports
1112
from .constants import (
1213
SERVER_NAME,
1314
SERVER_DESCRIPTION,
@@ -38,7 +39,12 @@ class ZeroConfigDLNA:
3839
"""
3940

4041
def __init__(
41-
self, media_directory=None, port=8200, verbose=False, server_name=None, fast=False
42+
self,
43+
media_directory=None,
44+
port=8200,
45+
verbose=False,
46+
server_name=None,
47+
fast=False,
4248
):
4349
self.server_name = server_name
4450
self.version = SERVER_VERSION
@@ -70,10 +76,11 @@ def __init__(
7076

7177
self.now_playing = None # Track currently playing media
7278
self.now_playing_timestamp = None # Track when media was last accessed
73-
79+
7480
def get_now_playing(self):
7581
"""Get the currently playing media file from the server."""
7682
import time
83+
7784
if self.now_playing:
7885
time_since_access = None
7986
if self.now_playing_timestamp:
@@ -83,20 +90,21 @@ def get_now_playing(self):
8390
"status": "playing",
8491
"server_running": self.running,
8592
"last_accessed": self.now_playing_timestamp,
86-
"seconds_since_access": time_since_access
93+
"seconds_since_access": time_since_access,
8794
}
8895
else:
8996
return {
9097
"filename": None,
9198
"status": "no media playing",
9299
"server_running": self.running,
93100
"last_accessed": None,
94-
"seconds_since_access": None
101+
"seconds_since_access": None,
95102
}
96103

97104
def set_now_playing(self, filename):
98105
"""Set the currently playing media file."""
99106
import time
107+
100108
self.now_playing = filename
101109
self.now_playing_timestamp = time.time()
102110
if self.verbose:
@@ -189,7 +197,9 @@ def count_media_files(directory):
189197
(self.server_ip, self.port), self.create_handler()
190198
)
191199
# Set server-side timeout to ensure we don't block forever on client operations
192-
self.server.timeout = 300 # Long timeout for media streaming / pausing etc
200+
self.server.timeout = (
201+
7200 # Very long timeout for media streaming / pausing etc
202+
)
193203
self.server_thread = threading.Thread(target=self.server.serve_forever)
194204
self.server_thread.daemon = True
195205
self.server_thread.start()
@@ -350,23 +360,24 @@ def get_media_info(self, filename=None):
350360
target_file = filename or self.now_playing
351361
if not target_file:
352362
return None
353-
363+
354364
file_path = os.path.join(self.media_directory, target_file)
355365
if not os.path.exists(file_path):
356366
return None
357-
367+
358368
try:
359369
stat_info = os.stat(file_path)
360370
return {
361371
"filename": target_file,
362372
"full_path": file_path,
363373
"size": stat_info.st_size,
364374
"modified": stat_info.st_mtime,
365-
"is_supported": is_supported_media_file(file_path)
375+
"is_supported": is_supported_media_file(file_path),
366376
}
367377
except OSError:
368378
return None
369379

380+
370381
def main():
371382
"""Main entry point for the DLNA server application."""
372383
parser = argparse.ArgumentParser(description=SERVER_DESCRIPTION)

0 commit comments

Comments
 (0)