ChandimaPrabath commited on
Commit
78ececa
1 Parent(s): 36bda90
Files changed (1) hide show
  1. app.py +6 -5
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
- start, end = range_specifier.split('-')
43
- start = int(start)
44
- end = int(end) if end else file_size - 1
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)