Skip to content

Commit 35aadb5

Browse files
committed
Add -f flag for skipping ffmpeg stuff
1 parent 4ebaf97 commit 35aadb5

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

app.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ZeroConfigDLNA:
3838
"""
3939

4040
def __init__(
41-
self, media_directory=None, port=8200, verbose=False, server_name=None
41+
self, media_directory=None, port=8200, verbose=False, server_name=None, fast=False
4242
):
4343
self.server_name = server_name
4444
self.version = SERVER_VERSION
@@ -49,6 +49,7 @@ def __init__(
4949
self.server = None
5050
self.server_thread = None
5151
self.verbose = verbose
52+
self.fast = fast
5253
socket.setdefaulttimeout(60) # 60 seconds timeout
5354

5455
# Generate UUID based on directory content hash
@@ -104,6 +105,7 @@ class Handler(DLNAHandler): # Create a subclass of DLNAHandler
104105
server_instance = server_ref
105106
verbose = server_ref.verbose
106107
server_name = self.server_name
108+
fast = server_ref.fast
107109

108110
return Handler
109111

@@ -331,6 +333,12 @@ def main():
331333
default=SERVER_NAME,
332334
help="Set the DLNA server name (default: ZeroConfigDLNA_<hostname> or value from DLNA_HOSTNAME env var)",
333335
)
336+
parser.add_argument(
337+
"-f",
338+
"--fast",
339+
action="store_true",
340+
help="Disable ffprobe and mediainfo subprocess calls for faster operation and wider compatibility",
341+
)
334342

335343
args = parser.parse_args()
336344

@@ -339,6 +347,7 @@ def main():
339347
port=args.port,
340348
verbose=args.verbose,
341349
server_name=args.server_name,
350+
fast=args.fast,
342351
)
343352
server.run()
344353

dlna.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class DLNAHandler(BaseHTTPRequestHandler):
8383
server_instance = None # Reference to the ZeroConfigDLNA server instance
8484
verbose = False # Verbose logging flag
8585
server_name = None # Server name, set by the server instance
86+
fast = False # Fast mode flag to disable subprocess calls
8687

8788
def __init__(self, *args, **kwargs):
8889
# Set default timeout for socket operations (5 minutes)
@@ -101,6 +102,9 @@ def __init__(self, *args, **kwargs):
101102
# Just log it and return gracefully
102103
print(f"Client disconnected during handler initialization: {e}")
103104

105+
if self.fast:
106+
print("Fast mode enabled - subprocess calls will be disabled")
107+
104108
def setup(self):
105109
"""Set up the connection with timeout"""
106110
super().setup()
@@ -2030,8 +2034,8 @@ def _get_media_duration(self, file_path, mime_type):
20302034
"audio/aiff": "00:05:00",
20312035
}
20322036

2033-
# Try to get duration using ffprobe if available
2034-
if mime_type and (
2037+
# Try to get duration using ffprobe if available (skip if fast mode is enabled)
2038+
if not self.fast and mime_type and (
20352039
mime_type.startswith("video/") or mime_type.startswith("audio/")
20362040
):
20372041
try:
@@ -2086,17 +2090,17 @@ def _get_media_duration(self, file_path, mime_type):
20862090
):
20872091
pass
20882092

2089-
# Try basic MP4 parsing for MP4 files
2090-
if mime_type == "video/mp4":
2091-
mp4_duration = self._parse_mp4_duration(file_path)
2092-
if mp4_duration:
2093-
return mp4_duration
2094-
2095-
# Try basic AVI parsing for AVI files
2096-
if mime_type == "video/x-msvideo":
2097-
avi_duration = self._parse_avi_duration(file_path)
2098-
if avi_duration:
2099-
return avi_duration
2093+
# Try basic MP4 parsing for MP4 files (works even in fast mode)
2094+
if mime_type == "video/mp4":
2095+
mp4_duration = self._parse_mp4_duration(file_path)
2096+
if mp4_duration:
2097+
return mp4_duration
2098+
2099+
# Try basic AVI parsing for AVI files (works even in fast mode)
2100+
if mime_type == "video/x-msvideo":
2101+
avi_duration = self._parse_avi_duration(file_path)
2102+
if avi_duration:
2103+
return avi_duration
21002104

21012105
# Return default duration for the mime type
21022106
return default_durations.get(mime_type, "01:00:00")

0 commit comments

Comments
 (0)