aboutsummaryrefslogtreecommitdiffstats
path: root/server.py
diff options
context:
space:
mode:
authorAstounds <kirito@disroot.org>2026-04-25 01:02:17 -0500
committerAstounds <kirito@disroot.org>2026-04-25 01:02:17 -0500
commit50ad959a8051fec95f26b573f9fe067bdf3fdf6a (patch)
tree4d94f63cf9adb951d4200b0f2bb0c762d45297c4 /server.py
parenta0f315be51ef121618e73d5b450c8616c0d11d21 (diff)
downloadyt-local-50ad959a8051fec95f26b573f9fe067bdf3fdf6a.tar.lz
yt-local-50ad959a8051fec95f26b573f9fe067bdf3fdf6a.tar.xz
yt-local-50ad959a8051fec95f26b573f9fe067bdf3fdf6a.zip
refactor: replace string concatenations with f-strings
Diffstat (limited to 'server.py')
-rw-r--r--server.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/server.py b/server.py
index 36ddae5..7f0100c 100644
--- a/server.py
+++ b/server.py
@@ -32,9 +32,9 @@ def youtu_be(env, start_response):
id = env['PATH_INFO'][1:]
env['PATH_INFO'] = '/watch'
if not env['QUERY_STRING']:
- env['QUERY_STRING'] = 'v=' + id
+ env['QUERY_STRING'] = f'v={id}'
else:
- env['QUERY_STRING'] += '&v=' + id
+ env['QUERY_STRING'] += f'&v={id}'
yield from yt_app(env, start_response)
@@ -64,12 +64,12 @@ def proxy_site(env, start_response, video=False):
if 'HTTP_RANGE' in env:
send_headers['Range'] = env['HTTP_RANGE']
- url = "https://" + env['SERVER_NAME'] + env['PATH_INFO']
+ url = f"https://{env['SERVER_NAME']}{env['PATH_INFO']}"
# remove /name portion
if video and '/videoplayback/name/' in url:
url = url[0:url.rfind('/name/')]
if env['QUERY_STRING']:
- url += '?' + env['QUERY_STRING']
+ url += f'?{env["QUERY_STRING"]}'
try_num = 1
first_attempt = True
@@ -96,7 +96,7 @@ def proxy_site(env, start_response, video=False):
+[('Access-Control-Allow-Origin', '*')])
if first_attempt:
- start_response(str(response.status) + ' ' + response.reason,
+ start_response(f"{response.status} {response.reason}",
response_headers)
content_length = int(dict(response_headers).get('Content-Length', 0))
@@ -136,9 +136,8 @@ def proxy_site(env, start_response, video=False):
fail_byte = start + total_received
send_headers['Range'] = 'bytes=%d-%d' % (fail_byte, end)
print(
- 'Warning: YouTube closed the connection before byte',
- str(fail_byte) + '.', 'Expected', start+content_length,
- 'bytes.'
+ f'Warning: YouTube closed the connection before byte {fail_byte}. '
+ f'Expected {start+content_length} bytes.'
)
retry = True
@@ -185,7 +184,7 @@ def split_url(url):
# python STILL doesn't have a proper regular expression engine like grep uses built in...
match = re.match(r'(?:https?://)?([\w-]+(?:\.[\w-]+)+?)(/.*|$)', url)
if match is None:
- raise ValueError('Invalid or unsupported url: ' + url)
+ raise ValueError(f'Invalid or unsupported url: {url}')
return match.group(1), match.group(2)
@@ -238,7 +237,7 @@ def site_dispatch(env, start_response):
if base_name == '':
base_name = domain
else:
- base_name = domain + '.' + base_name
+ base_name = f"{domain}.{base_name}"
try:
handler = site_handlers[base_name]