PATCH: Fixed old .ts files still being present after stream end

This commit is contained in:
2025-03-03 21:41:50 +00:00
parent 0ba21a7666
commit 43f3b54e22
2 changed files with 11 additions and 6 deletions

View File

@@ -80,6 +80,9 @@ def end_user_stream(stream_key, user_id, username):
stream_info = db.fetchone("""SELECT *
FROM streams
WHERE user_id = ?""", (user_id,))
# Remove HLS files, even if user is not streaming
remove_hls_files(path_manager.get_stream_path(username))
# If user is not streaming, just return
if not stream_info:
@@ -194,6 +197,14 @@ def generate_thumbnail(stream_file: str, thumbnail_file: str) -> None:
except subprocess.CalledProcessError as e:
print(f"No information available for {stream_file}, aborting thumbnail generation")
def remove_hls_files(stream_path: str) -> None:
"""
Removes all hls files in a stream directory
"""
for file in os.listdir(stream_path):
if file.endswith(".ts") or file.endswith(".m3u8"):
os.remove(os.path.join(stream_path, file))
def get_stream_tags(user_id: int) -> Optional[List[str]]:
"""
Given a stream return tags associated with the user's stream