Skip to content

Commit c7f54ad

Browse files
committed
reorg imports / remove multiprocessing change
1 parent c7e1bfb commit c7f54ad

File tree

4 files changed

+53
-26
lines changed

4 files changed

+53
-26
lines changed

app.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Zero Configuration DLNA Server - A simple DLNA media server."""
2-
import multiprocessing
3-
multiprocessing.set_start_method("fork")
42
import hashlib
53
import os
64
import socket
@@ -9,15 +7,26 @@
97
from http.server import ThreadingHTTPServer
108
import argparse
119

12-
from constants import (
13-
SERVER_NAME,
14-
SERVER_DESCRIPTION,
15-
SERVER_VERSION,
16-
SERVER_MANUFACTURER,
17-
is_supported_media_file,
18-
)
19-
from dlna import DLNAHandler
20-
from ssdp import SSDPServer
10+
try: # Hacky but needed to support both package and module imports
11+
from .constants import (
12+
SERVER_NAME,
13+
SERVER_DESCRIPTION,
14+
SERVER_VERSION,
15+
SERVER_MANUFACTURER,
16+
is_supported_media_file,
17+
)
18+
from .dlna import DLNAHandler
19+
from .ssdp import SSDPServer
20+
except ImportError:
21+
from constants import (
22+
SERVER_NAME,
23+
SERVER_DESCRIPTION,
24+
SERVER_VERSION,
25+
SERVER_MANUFACTURER,
26+
is_supported_media_file,
27+
)
28+
from dlna import DLNAHandler
29+
from ssdp import SSDPServer
2130

2231

2332
class ZeroConfigDLNA:

constants.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
import os
88
import socket
9-
from custom_mimetypes import CustomMimeTypes
9+
try:
10+
from .custom_mimetypes import CustomMimeTypes
11+
except ImportError:
12+
from custom_mimetypes import CustomMimeTypes
1013

1114
# Get hostname, truncate at first dot, then limit to 16 chars max
1215
hostname = socket.gethostname().split(".")[0][:16]

dlna.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@
44
This module provides the HTTP request handler for a DLNA media server,
55
implementing the necessary DLNA and UPnP protocols for media streaming.
66
"""
7-
7+
import html
8+
import traceback
89
import os
910
import struct
1011
import subprocess
1112
import uuid
1213
from http.server import BaseHTTPRequestHandler
1314
from urllib.parse import unquote, urlparse, quote
14-
import html
15-
import traceback
16-
from constants import (
17-
SERVER_AGENT,
18-
SERVER_DESCRIPTION,
19-
SERVER_VERSION,
20-
SERVER_MANUFACTURER,
21-
is_supported_media_file,
22-
)
23-
from custom_mimetypes import CustomMimeTypes
15+
16+
try:
17+
from .constants import (
18+
SERVER_AGENT,
19+
SERVER_DESCRIPTION,
20+
SERVER_VERSION,
21+
SERVER_MANUFACTURER,
22+
is_supported_media_file,
23+
)
24+
from .custom_mimetypes import CustomMimeTypes
25+
except ImportError:
26+
from constants import (
27+
SERVER_AGENT,
28+
SERVER_DESCRIPTION,
29+
SERVER_VERSION,
30+
SERVER_MANUFACTURER,
31+
is_supported_media_file,
32+
)
33+
from custom_mimetypes import CustomMimeTypes
2434

2535
# Create a global instance of CustomMimeTypes
2636
custom_mimetypes = CustomMimeTypes()

ssdp.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
import time
1212
import struct
1313
import select
14-
from constants import (
15-
SERVER_AGENT,
16-
)
14+
try:
15+
from .constants import (
16+
SERVER_AGENT,
17+
)
18+
except ImportError:
19+
from constants import (
20+
SERVER_AGENT,
21+
)
1722

1823

1924
class SSDPServer:

0 commit comments

Comments
 (0)