MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / normalize_server_url

Function normalize_server_url

core/xtream_codes.py:9–25  ·  view source on GitHub ↗

Normalize server URL: strip XC API endpoints and query params, preserve base path.

(url)

Source from the content-addressed store, hash-verified

7
8
9def normalize_server_url(url):
10 """Normalize server URL: strip XC API endpoints and query params, preserve base path."""
11 if not url:
12 return url
13
14 from urllib.parse import urlparse, urlunparse
15
16 parsed = urlparse(url.strip())
17 path = parsed.path.rstrip('/')
18
19 # XC API endpoints are always .php files; legitimate base paths never are.
20 # Stripping the trailing segment when it ends in .php handles any pasted API URL.
21 last_segment = path.rsplit('/', 1)[-1]
22 if last_segment.endswith('.php'):
23 path = path[:-(len(last_segment) + 1)] if '/' in path else ''
24
25 return urlunparse((parsed.scheme, parsed.netloc, path, '', '', ''))
26
27
28class Client:

Calls

no outgoing calls