UPDATE: Changed stream access URL to use streamer_name instead of streamer_key, to hide streamer key.

This commit is contained in:
2025-02-26 15:07:09 +00:00
parent c98f892e3e
commit cefd88f525
5 changed files with 23 additions and 22 deletions

View File

@@ -25,7 +25,7 @@ rtmp {
live on; live on;
hls on; hls on;
hls_path /stream_data/stream/; hls_path /stream_data/;
allow publish 127.0.0.1; allow publish 127.0.0.1;
deny publish all; deny publish all;

View File

@@ -185,11 +185,11 @@ def init_stream():
print("Unauthorized - Invalid stream key", flush=True) print("Unauthorized - Invalid stream key", flush=True)
return "Unauthorized - Invalid stream key", 403 return "Unauthorized - Invalid stream key", 403
# Create necessary directories # Create necessary directories
username = user_info["username"] username = user_info["username"]
create_local_directories(username) create_local_directories(username)
return "OK", 200 return redirect(f"/stream/{username}")
@stream_bp.route("/publish_stream", methods=["POST"]) @stream_bp.route("/publish_stream", methods=["POST"])
@@ -243,7 +243,7 @@ def publish_stream():
# Update thumbnail periodically # Update thumbnail periodically
update_thumbnail.delay(user_id, update_thumbnail.delay(user_id,
path_manager.get_stream_file_path(username), path_manager.get_stream_file_path(username),
path_manager.get_thumbnail_file_path(username), path_manager.get_current_stream_thumbnail_file_path(username),
THUMBNAIL_GENERATION_INTERVAL) THUMBNAIL_GENERATION_INTERVAL)
return "OK", 200 return "OK", 200

View File

@@ -22,6 +22,7 @@ def user_data(username: str):
data = get_user(user_id) data = get_user(user_id)
return jsonify(data) return jsonify(data)
@login_required
@user_bp.route('/user/<string:username>/stream_key') @user_bp.route('/user/<string:username>/stream_key')
def user_stream_key(username: str): def user_stream_key(username: str):
""" """

View File

@@ -2,16 +2,19 @@
class PathManager(): class PathManager():
def get_vods_path(self, username): def get_vods_path(self, username):
return f"stream_data/{username}/vods" return f"stream_data/vods/{username}"
def get_stream_path(self, username): def get_stream_path(self, username):
return f"stream_data/{username}/stream" return f"stream_data/stream/{username}"
def get_thumbnail_path(self, username):
return f"stream_data/{username}/thumbnails"
def get_stream_file_path(self, username): def get_stream_file_path(self, username):
return f"{self.get_stream_path(username)}/index.m3u8" return f"{self.get_stream_path(username)}/index.m3u8"
def get_thumbnail_file_path(self, username): def get_current_stream_thumbnail_file_path(self, username):
return f"{self.get_thumbnail_path(username)}/stream.jpg" return f"{self.get_stream_path(username)}/index.jpg"
def get_vod_file_path(self, username, vod_id):
return f"{self.get_vods_path(username)}/{vod_id}.mp4"
def get_vod_thumbnail_file_path(self, username, vod_id):
return f"{self.get_vods_path(username)}/{vod_id}.jpg"

View File

@@ -3,6 +3,7 @@ from typing import Optional
import os, subprocess import os, subprocess
from typing import Optional, List from typing import Optional, List
from time import sleep from time import sleep
from utils.path_manager import PathManager
def get_streamer_live_status(user_id: int): def get_streamer_live_status(user_id: int):
""" """
@@ -147,9 +148,10 @@ def create_local_directories(username: str):
Create directories for user stream data if they do not exist Create directories for user stream data if they do not exist
""" """
vods_path = f"stream_data/vods/{username}" path_m = PathManager()
stream_path = f"stream_data/stream"
thumbnail_path = f"stream_data/thumbnails/{username}" vods_path = path_m.get_vods_path(username)
stream_path = path_m.get_stream_path(username)
if not os.path.exists(vods_path): if not os.path.exists(vods_path):
os.makedirs(vods_path) os.makedirs(vods_path)
@@ -157,16 +159,11 @@ def create_local_directories(username: str):
if not os.path.exists(stream_path): if not os.path.exists(stream_path):
os.makedirs(stream_path) os.makedirs(stream_path)
if not os.path.exists(thumbnail_path):
os.makedirs(thumbnail_path)
# Fix permissions # Fix permissions
os.chmod(vods_path, 0o777) os.chmod(vods_path, 0o777)
os.chmod(stream_path, 0o777) os.chmod(stream_path, 0o777)
os.chmod(thumbnail_path, 0o777)
return { return {
"vod_path": vods_path, "vod_path": vods_path,
"stream_path": stream_path, "stream_path": stream_path
"thumbnail_path": thumbnail_path
} }