UPDATE: Added custom thumbnail functions and checks in stream utils
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from celery import Celery, shared_task, Task
|
from celery import Celery, shared_task, Task
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from celery_tasks.preferences import user_preferences
|
from celery_tasks.preferences import user_preferences
|
||||||
from utils.stream_utils import generate_thumbnail, get_streamer_live_status
|
from utils.stream_utils import generate_thumbnail, get_streamer_live_status, get_custom_thumbnail_status
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from os import listdir, remove
|
from os import listdir, remove
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -12,12 +12,13 @@ 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
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if get_streamer_live_status(user_id)['is_live']:
|
# Check if stream is still live and custom thumbnail has not been set
|
||||||
|
if get_streamer_live_status(user_id)['is_live'] and not get_custom_thumbnail_status(user_id)['custom_thumbnail']:
|
||||||
print("Updating thumbnail...")
|
print("Updating thumbnail...")
|
||||||
generate_thumbnail(stream_file, thumbnail_file)
|
generate_thumbnail(stream_file, thumbnail_file)
|
||||||
update_thumbnail.apply_async((user_id, stream_file, thumbnail_file, sleep_time), countdown=sleep_time)
|
update_thumbnail.apply_async((user_id, stream_file, thumbnail_file, sleep_time), countdown=sleep_time)
|
||||||
else:
|
else:
|
||||||
print("Stream has ended, stopping thumbnail updates")
|
print(f"Stopping thumbnail updates for stream of {user_id}")
|
||||||
|
|
||||||
@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):
|
||||||
|
|||||||
@@ -60,6 +60,18 @@ def get_category_id(category_name: str) -> Optional[int]:
|
|||||||
""", (category_name,))
|
""", (category_name,))
|
||||||
return data['category_id'] if data else None
|
return data['category_id'] if data else None
|
||||||
|
|
||||||
|
def get_custom_thumbnail_status(user_id: int) -> Optional[dict]:
|
||||||
|
"""
|
||||||
|
Returns the custom thumbnail status of a streamer
|
||||||
|
"""
|
||||||
|
with Database() as db:
|
||||||
|
custom_thumbnail = db.fetchone("""
|
||||||
|
SELECT custom_thumbnail
|
||||||
|
FROM users
|
||||||
|
WHERE user_id = ?;
|
||||||
|
""", (user_id,))
|
||||||
|
return custom_thumbnail
|
||||||
|
|
||||||
def get_vod(vod_id: int) -> dict:
|
def get_vod(vod_id: int) -> dict:
|
||||||
"""
|
"""
|
||||||
Returns data of a streamers vod
|
Returns data of a streamers vod
|
||||||
@@ -92,7 +104,7 @@ def get_all_vods():
|
|||||||
vods = db.fetchall("""SELECT * FROM vods""")
|
vods = db.fetchall("""SELECT * FROM vods""")
|
||||||
return vods
|
return vods
|
||||||
|
|
||||||
def generate_thumbnail(stream_file: str, thumbnail_file: str, retry_time=5, retry_count=3) -> None:
|
def generate_thumbnail(stream_file: str, thumbnail_file: str) -> None:
|
||||||
"""
|
"""
|
||||||
Generates the thumbnail of a stream
|
Generates the thumbnail of a stream
|
||||||
"""
|
"""
|
||||||
@@ -109,21 +121,11 @@ def generate_thumbnail(stream_file: str, thumbnail_file: str, retry_time=5, retr
|
|||||||
f"{thumbnail_file}"
|
f"{thumbnail_file}"
|
||||||
]
|
]
|
||||||
|
|
||||||
attempts = retry_count
|
|
||||||
|
|
||||||
while attempts > 0:
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(thumbnail_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
|
subprocess.run(thumbnail_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
|
||||||
print(f"Thumbnail generated for {stream_file}")
|
print(f"Thumbnail generated for {stream_file}")
|
||||||
break
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
attempts -= 1
|
print(f"No information available for {stream_file}, aborting thumbnail generation")
|
||||||
print(f"No information available, retrying in {retry_time} seconds...")
|
|
||||||
sleep(retry_time)
|
|
||||||
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]]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user