fix: optimize live streaming end message push

This commit is contained in:
ihmily
2025-06-07 16:42:53 +08:00
parent 1e29317121
commit b6f63635f2
5 changed files with 20 additions and 18 deletions

View File

@@ -125,7 +125,7 @@ class RecordingManager:
status_info=RecordingStatus.STOPPED_MONITORING,
selected=False,
)
self.stop_recording(recording)
self.stop_recording(recording, manually_stopped=True)
self.app.page.run_task(self.app.record_card_manager.update_card, recording)
self.app.page.pubsub.send_others_on_topic("update", recording)
if auto_save:
@@ -331,7 +331,7 @@ class RecordingManager:
logger.info(f"Started recording for {recording.title}")
@staticmethod
def stop_recording(recording: Recording):
def stop_recording(recording: Recording, manually_stopped: bool = True):
"""Stop the recording process."""
if recording.recording:
if recording.start_time is not None:
@@ -342,6 +342,7 @@ class RecordingManager:
recording.last_duration = recording.cumulative_duration
recording.start_time = None
recording.recording = False
recording.manually_stopped = manually_stopped
logger.info(f"Stopped recording for {recording.title}")
def get_duration(self, recording: Recording):

View File

@@ -82,7 +82,7 @@ class LiveStreamRecorder:
current_date = datetime.today().strftime("%Y-%m-%d")
if current_date not in self.recording.recording_dir:
self.recording.recording_dir = None
if self.recording.recording_dir:
return self.recording.recording_dir
@@ -265,8 +265,8 @@ class LiveStreamRecorder:
else:
self.recording.recording = False
logger.success(f"Live recording completed: {record_name}")
if (self.settings.user_config["stream_end_notification_enabled"]
and self.recording.enabled_message_push):
if (self.app.recording_enabled and self.settings.user_config["stream_end_notification_enabled"]
and self.recording.enabled_message_push and not self.recording.manually_stopped):
push_content = self._["push_content_end"]
end_push_message_text = self.settings.user_config.get("custom_stream_end_content")
if end_push_message_text:
@@ -274,7 +274,7 @@ class LiveStreamRecorder:
push_at = datetime.today().strftime("%Y-%m-%d %H:%M:%S")
push_content = push_content.replace("[room_name]", self.recording.streamer_name).replace(
"[time]", push_at
"[time]", push_at
)
msg_title = self.settings.user_config.get("custom_notification_title").strip()
msg_title = msg_title or self._["status_notify"]
@@ -354,10 +354,10 @@ class LiveStreamRecorder:
self.converts_mp4_sync, converts_file_path, is_original_delete
)
return
# Otherwise, execute transcoding normally
await self._do_converts_mp4(converts_file_path, is_original_delete)
def converts_mp4_sync(self, converts_file_path: str, is_original_delete: bool = True) -> None:
"""Synchronous version of the transcoding method, used for background service"""
loop = asyncio.new_event_loop()
@@ -366,7 +366,7 @@ class LiveStreamRecorder:
loop.run_until_complete(self._do_converts_mp4(converts_file_path, is_original_delete))
finally:
loop.close()
async def _do_converts_mp4(self, converts_file_path: str, is_original_delete: bool = True) -> None:
"""Actual execution method for transcoding"""
converts_success = False
@@ -422,7 +422,7 @@ class LiveStreamRecorder:
converts_to_mp4: bool
):
from ..process_manager import BackgroundService
if "python" in script_command:
params = [
f'--record_name "{record_name}"',
@@ -439,15 +439,15 @@ class LiveStreamRecorder:
f"converts_to_mp4: {converts_to_mp4}"
]
script_command = script_command.strip() + " " + " ".join(params)
if not self.app.recording_enabled:
logger.info("Application is closing, adding script execution task to background service")
BackgroundService.get_instance().add_task(self.run_script_sync, script_command)
else:
self.app.page.run_task(self.run_script_async, script_command)
logger.success("Script command execution initiated!")
def run_script_sync(self, command: str) -> None:
"""Synchronous version of the script execution method, used for background service"""
loop = asyncio.new_event_loop()

View File

@@ -53,7 +53,7 @@ class NotificationService:
results["success"].append(api)
else:
results["error"].append(api)
logger.info(f"WeChat push failed, push address: {api}, Failure message: {json_data['msg']}")
logger.info(f"WeChat push failed, push address: {api}, Failure message: {json_data.get('msg')}")
return results
@staticmethod
@@ -139,7 +139,7 @@ class NotificationService:
results["success"].append(_api)
else:
results["error"].append(_api)
logger.info(f"Bark push failed, push address: {_api}, Failure message: {json_data['message']}")
logger.info(f"Bark push failed, push address: {_api}, Failure message: {json_data.get('message')}")
return results
async def send_to_ntfy(
@@ -186,7 +186,7 @@ class NotificationService:
results["success"].append(_api)
else:
results["error"].append(_api)
logger.info(f"Ntfy push failed, push address: {_api}, Failure message: {json_data['error']}")
logger.info(f"Ntfy push failed, push address: {_api}, Failure message: {json_data.get('error')}")
return results
async def send_to_serverchan(

View File

@@ -55,6 +55,7 @@ class Recording:
self.is_live = False
self.recording = False # Record status
self.start_time = None
self.manually_stopped = False
self.cumulative_duration = timedelta() # Accumulated recording time
self.last_duration = timedelta() # Save the total time of the last recording

View File

@@ -295,7 +295,7 @@ class RecordingCardManager:
"display_title": f"[{self._['monitor_stopped']}] {recording.title}",
}
)
self.app.record_manager.stop_recording(recording)
self.app.record_manager.stop_recording(recording, manually_stopped=True)
self.app.page.run_task(self.app.snack_bar.show_snack_bar, self._["stop_monitor_tip"])
else:
recording.update(
@@ -338,7 +338,7 @@ class RecordingCardManager:
"""Toggle the recording state for a specific recording."""
if recording and self.app.recording_enabled:
if recording.recording:
self.app.record_manager.stop_recording(recording)
self.app.record_manager.stop_recording(recording, manually_stopped=True)
await self.app.snack_bar.show_snack_bar(self._["stop_record_tip"])
else:
if recording.monitor_status: