FEAT: VoDs accessible from browser, named as {vod_id}.mp4
This commit is contained in:
@@ -100,6 +100,14 @@ http {
|
||||
expires -1d;
|
||||
}
|
||||
|
||||
# The vods location
|
||||
location ~ ^/stream/(.+)/vods/(.+\.mp4)$ {
|
||||
alias /stream_data/$1/vods/$2;
|
||||
|
||||
# The vods should not be cacheable
|
||||
expires -1d;
|
||||
}
|
||||
|
||||
location ~ ^/\?token=.*$ {
|
||||
proxy_pass http://frontend:5173;
|
||||
proxy_http_version 1.1;
|
||||
|
||||
@@ -237,6 +237,8 @@ def end_stream():
|
||||
stream_length,
|
||||
0))
|
||||
|
||||
vod_id = db.get_last_insert_id()
|
||||
|
||||
# Set user as not streaming
|
||||
db.execute("""UPDATE users
|
||||
SET is_live = 0
|
||||
@@ -245,6 +247,6 @@ def end_stream():
|
||||
# Get username
|
||||
username = user_info["username"]
|
||||
|
||||
combine_ts_stream.delay(path_manager.get_stream_path(username), path_manager.get_vods_path(username))
|
||||
combine_ts_stream.delay(path_manager.get_stream_path(username), path_manager.get_vods_path(username), vod_id)
|
||||
|
||||
return "Stream ended", 200
|
||||
@@ -28,13 +28,12 @@ def update_thumbnail(stream_file, thumbnail_file, sleep_time) -> None:
|
||||
sleep(sleep_time)
|
||||
|
||||
@shared_task
|
||||
def combine_ts_stream(stream_path, vods_path):
|
||||
def combine_ts_stream(stream_path, vods_path, vod_file_name):
|
||||
"""
|
||||
Combines all ts files into a single vod, and removes the ts files
|
||||
"""
|
||||
ts_files = [f for f in listdir(stream_path) if f.endswith(".ts")]
|
||||
ts_files.sort()
|
||||
print(ts_files)
|
||||
|
||||
# Create temp file listing all ts files
|
||||
with open(f"{stream_path}/list.txt", "w") as f:
|
||||
@@ -42,7 +41,6 @@ def combine_ts_stream(stream_path, vods_path):
|
||||
f.write(f"file '{ts_file}'\n")
|
||||
|
||||
# Concatenate all ts files into a single vod
|
||||
file_name = datetime.now().strftime("%d-%m-%Y-%H-%M-%S") + ".mp4"
|
||||
|
||||
vod_command = [
|
||||
"ffmpeg",
|
||||
@@ -54,7 +52,7 @@ def combine_ts_stream(stream_path, vods_path):
|
||||
f"{stream_path}/list.txt",
|
||||
"-c",
|
||||
"copy",
|
||||
f"{vods_path}/{file_name}"
|
||||
f"{vods_path}/{vod_file_name}.mp4"
|
||||
]
|
||||
|
||||
subprocess.run(vod_command)
|
||||
|
||||
@@ -54,6 +54,10 @@ class Database:
|
||||
print(f"Database error: {e}")
|
||||
raise
|
||||
|
||||
def get_last_insert_id(self) -> int:
|
||||
"""Get the ID of the last inserted row."""
|
||||
return self.cursor.lastrowid if self.cursor else None
|
||||
|
||||
def convert_to_list_dict(self, result):
|
||||
"""Convert query result to a list of dictionaries."""
|
||||
if not result:
|
||||
|
||||
Reference in New Issue
Block a user