Spaces:
Paused
Paused
Update stream_server.py
Browse files- stream_server.py +16 -10
stream_server.py
CHANGED
@@ -71,7 +71,7 @@ def convert_to_hls(input_path, output_dir, video_name, start_number):
|
|
71 |
|
72 |
|
73 |
|
74 |
-
async def add_video(video_name: str):
|
75 |
"""
|
76 |
Endpoint to add a video to the streaming queue.
|
77 |
|
@@ -98,16 +98,22 @@ async def add_video(video_name: str):
|
|
98 |
segment_counter += num_new_segments
|
99 |
|
100 |
video_names.append(video_name)
|
101 |
-
|
102 |
-
|
103 |
-
m3u8_file_path
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
with open(m3u8_file_path, 'a') as m3u8_file:
|
108 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
111 |
|
112 |
# Update concatenated playlist
|
113 |
#await concatenate_playlists(video_names, HLS_DIR)
|
|
|
71 |
|
72 |
|
73 |
|
74 |
+
async def add_video(video_name: str, m3u8_file_path: Path):
|
75 |
"""
|
76 |
Endpoint to add a video to the streaming queue.
|
77 |
|
|
|
98 |
segment_counter += num_new_segments
|
99 |
|
100 |
video_names.append(video_name)
|
101 |
+
|
102 |
+
existing_segments = set()
|
103 |
+
if m3u8_file_path.exists():
|
104 |
+
with open(m3u8_file_path, 'r') as m3u8_file:
|
105 |
+
for line in m3u8_file:
|
106 |
+
if line.startswith('/live_stream/video_stream'):
|
107 |
+
existing_segments.add(line.strip())
|
108 |
+
|
109 |
+
new_ts_files = sorted([f for f in os.listdir(HLS_DIR) if f.startswith('video_stream') and f.endswith('.ts')])
|
110 |
+
|
111 |
with open(m3u8_file_path, 'a') as m3u8_file:
|
112 |
+
for ts_file in new_ts_files[-num_new_segments:]: # Only process the new segments
|
113 |
+
segment_path = f"/live_stream/{ts_file}"
|
114 |
+
if segment_path not in existing_segments: # Check if already exists
|
115 |
+
m3u8_file.write(f"#EXTINF:3.000,\n") # Adjust duration as necessary
|
116 |
+
m3u8_file.write(f"{segment_path}\n")
|
117 |
|
118 |
# Update concatenated playlist
|
119 |
#await concatenate_playlists(video_names, HLS_DIR)
|