PATCH: Thumbnails not stop generating after stream ends

This commit is contained in:
2025-02-17 19:07:25 +00:00
parent 7af9cb1eb7
commit 62d83aa4eb
3 changed files with 14 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ from utils.path_manager import PathManager
stream_bp = Blueprint("stream", __name__) stream_bp = Blueprint("stream", __name__)
# Constants # Constants
THUMBNAIL_GENERATION_INTERVAL = 180 THUMBNAIL_GENERATION_INTERVAL = 10
## Path Manager ## Path Manager
path_manager = PathManager() path_manager = PathManager()
@@ -182,12 +182,14 @@ def publish_stream():
db.execute("""UPDATE users SET is_live = 1 WHERE user_id = ?""", (user_info["user_id"],)) db.execute("""UPDATE users SET is_live = 1 WHERE user_id = ?""", (user_info["user_id"],))
username = user_info["username"] username = user_info["username"]
user_id = user_info["user_id"]
# Local file creation # Local file creation
create_local_directories(username) create_local_directories(username)
# Update thumbnail periodically # Update thumbnail periodically
update_thumbnail.delay(path_manager.get_stream_file_path(username), update_thumbnail.delay(user_id,
path_manager.get_stream_file_path(username),
path_manager.get_thumbnail_file_path(username), path_manager.get_thumbnail_file_path(username),
THUMBNAIL_GENERATION_INTERVAL) THUMBNAIL_GENERATION_INTERVAL)

View File

@@ -18,14 +18,17 @@ def celery_init_app(app) -> Celery:
return celery_app return celery_app
@shared_task @shared_task
def update_thumbnail(stream_file, thumbnail_file, sleep_time) -> None: def update_thumbnail(user_id, stream_file, thumbnail_file, sleep_time) -> None:
""" """
Updates the thumbnail of a stream periodically Updates the thumbnail of a stream periodically
""" """
while True: if get_streamer_live_status(user_id)['is_live']:
print("Updating thumbnail...")
generate_thumbnail(stream_file, thumbnail_file) generate_thumbnail(stream_file, thumbnail_file)
sleep(sleep_time) update_thumbnail.apply_async((user_id, stream_file, thumbnail_file, sleep_time), countdown=sleep_time)
else:
print("Stream has ended, stopping thumbnail updates")
@shared_task @shared_task
def combine_ts_stream(stream_path, vods_path, vod_file_name): def combine_ts_stream(stream_path, vods_path, vod_file_name):

View File

@@ -109,12 +109,13 @@ def generate_thumbnail(stream_file: str, thumbnail_file: str, retry_time=5, retr
break break
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
attempts -= 1 attempts -= 1
print("FFmpeg failed with an error:") print(f"No information available, retrying in {retry_time} seconds...")
print(e.stderr.decode()) # Print detailed error message
print(f"Retrying in {retry_time} seconds...")
sleep(retry_time) sleep(retry_time)
continue continue
if attempts == 0:
print(f"Failed to generate thumbnail for {stream_file}, skipping...")
def get_stream_tags(user_id: int) -> Optional[List[str]]: def get_stream_tags(user_id: int) -> Optional[List[str]]:
""" """
Given a stream return tags associated with the user's stream Given a stream return tags associated with the user's stream