ChandimaPrabath
commited on
Commit
•
78ececa
1
Parent(s):
36bda90
test 2
Browse files
app.py
CHANGED
@@ -36,12 +36,13 @@ async def serve_video(file_path: str, request: Request):
|
|
36 |
|
37 |
if range_header:
|
38 |
# Simple parsing for range values
|
39 |
-
start, end = None, None
|
40 |
range_specifier = range_header.replace('bytes=', '').strip()
|
|
|
|
|
41 |
if '-' in range_specifier:
|
42 |
-
|
43 |
-
start = int(
|
44 |
-
end = int(
|
45 |
|
46 |
# Validate range
|
47 |
if start is None or start >= file_size or (end is not None and end >= file_size) or (end is not None and start > end):
|
@@ -70,7 +71,7 @@ async def serve_video(file_path: str, request: Request):
|
|
70 |
data.extend(chunk)
|
71 |
start += read_size
|
72 |
|
73 |
-
return Response(content=data, status_code=206, headers=headers)
|
74 |
|
75 |
# Fallback for serving the whole file if no range requested
|
76 |
return FileResponse(file_path, media_type=mime_type)
|
|
|
36 |
|
37 |
if range_header:
|
38 |
# Simple parsing for range values
|
|
|
39 |
range_specifier = range_header.replace('bytes=', '').strip()
|
40 |
+
start, end = (None, None)
|
41 |
+
|
42 |
if '-' in range_specifier:
|
43 |
+
start_str, end_str = range_specifier.split('-')
|
44 |
+
start = int(start_str)
|
45 |
+
end = int(end_str) if end_str else file_size - 1
|
46 |
|
47 |
# Validate range
|
48 |
if start is None or start >= file_size or (end is not None and end >= file_size) or (end is not None and start > end):
|
|
|
71 |
data.extend(chunk)
|
72 |
start += read_size
|
73 |
|
74 |
+
return Response(content=bytes(data), status_code=206, headers=headers) # Convert bytearray to bytes
|
75 |
|
76 |
# Fallback for serving the whole file if no range requested
|
77 |
return FileResponse(file_path, media_type=mime_type)
|