mirror of
https://github.com/ihmily/StreamCap.git
synced 2026-05-07 22:15:58 +08:00
fix: improve message push judgment
This commit is contained in:
@@ -262,7 +262,6 @@ class RecordingManager:
|
||||
stream_info.anchor_name = utils.clean_name(stream_info.anchor_name, self._["live_room"])
|
||||
|
||||
recording.is_live = stream_info.is_live
|
||||
is_record = True
|
||||
if recording.is_live and not recording.is_recording:
|
||||
recording.status_info = RecordingStatus.PREPARING_RECORDING
|
||||
recording.live_title = stream_info.title
|
||||
@@ -273,7 +272,7 @@ class RecordingManager:
|
||||
|
||||
msg_manager = MessagePusher(self.settings)
|
||||
user_config = self.settings.user_config
|
||||
if MessagePusher.should_push_message(self.settings, recording):
|
||||
if MessagePusher.should_push_message(self.settings, recording, message_type='start'):
|
||||
push_content = self._["push_content"]
|
||||
begin_push_message_text = user_config.get("custom_stream_start_content")
|
||||
if begin_push_message_text:
|
||||
@@ -288,17 +287,14 @@ class RecordingManager:
|
||||
|
||||
self.app.page.run_task(msg_manager.push_messages, msg_title, push_content)
|
||||
|
||||
if user_config.get("only_notify_no_record"):
|
||||
notify_loop_time = user_config.get("notify_loop_time")
|
||||
recording.loop_time_seconds = int(notify_loop_time or 3600)
|
||||
is_record = False
|
||||
else:
|
||||
recording.loop_time_seconds = self.loop_time_seconds
|
||||
|
||||
if is_record:
|
||||
if not user_config.get("only_notify_no_record"):
|
||||
recording.loop_time_seconds = self.loop_time_seconds
|
||||
self.start_update(recording)
|
||||
self.app.page.run_task(recorder.start_recording, stream_info)
|
||||
else:
|
||||
notify_loop_time = user_config.get("notify_loop_time")
|
||||
recording.loop_time_seconds = int(notify_loop_time or 3600)
|
||||
recording.status_info = RecordingStatus.NOT_RECORDING
|
||||
recording.is_checking = False
|
||||
|
||||
self.app.page.run_task(self.app.record_card_manager.update_card, recording)
|
||||
|
||||
@@ -263,13 +263,13 @@ class LiveStreamRecorder:
|
||||
if not self.recording.is_recording:
|
||||
logger.success(f"Live recording has stopped: {record_name}")
|
||||
else:
|
||||
self.recording.is_recording = False
|
||||
|
||||
logger.success(f"Live recording completed: {record_name}")
|
||||
msg_manager = MessagePusher(self.settings)
|
||||
user_config = self.settings.user_config
|
||||
|
||||
if self.app.recording_enabled and MessagePusher.should_push_message(
|
||||
self.settings, self.recording, check_manually_stopped=True):
|
||||
self.settings, self.recording, check_manually_stopped=True, message_type='end'):
|
||||
push_content = self._["push_content_end"]
|
||||
end_push_message_text = user_config.get("custom_stream_end_content")
|
||||
if end_push_message_text:
|
||||
@@ -283,6 +283,8 @@ class LiveStreamRecorder:
|
||||
msg_title = msg_title or self._["status_notify"]
|
||||
|
||||
self.app.page.run_task(msg_manager.push_messages, msg_title, push_content)
|
||||
|
||||
self.recording.is_recording = False
|
||||
try:
|
||||
self.recording.update({"display_title": display_title})
|
||||
await self.app.record_card_manager.update_card(self.recording)
|
||||
|
||||
@@ -24,7 +24,7 @@ class MessagePusher:
|
||||
return any(self.settings.user_config.get(channel) for channel in push_channels)
|
||||
|
||||
@staticmethod
|
||||
def should_push_message(settings, recording, check_manually_stopped=False):
|
||||
def should_push_message(settings, recording, check_manually_stopped=False, message_type=None):
|
||||
"""
|
||||
Check if message should be pushed
|
||||
"""
|
||||
@@ -32,18 +32,25 @@ class MessagePusher:
|
||||
return False
|
||||
|
||||
user_config = settings.user_config
|
||||
should_only_notify_no_record = user_config.get("only_notify_no_record")
|
||||
is_stream_start_enabled = user_config.get("stream_start_notification_enabled")
|
||||
is_stream_end_enabled = user_config.get("stream_end_notification_enabled")
|
||||
|
||||
# Check if global push settings are enabled
|
||||
global_push_enabled = (
|
||||
user_config.get("stream_start_notification_enabled") or
|
||||
user_config.get("stream_end_notification_enabled") or
|
||||
user_config.get("only_notify_no_record")
|
||||
)
|
||||
|
||||
if not global_push_enabled:
|
||||
if message_type is None:
|
||||
if hasattr(recording, 'is_recording') and recording.is_recording:
|
||||
message_type = 'end'
|
||||
else:
|
||||
message_type = 'start'
|
||||
|
||||
if message_type == 'start' and should_only_notify_no_record and is_stream_start_enabled:
|
||||
return True
|
||||
|
||||
if message_type == 'start' and not is_stream_start_enabled:
|
||||
return False
|
||||
|
||||
# Check if any push platform is enabled
|
||||
|
||||
if message_type == 'end' and not is_stream_end_enabled:
|
||||
return False
|
||||
|
||||
push_channels = [
|
||||
"dingtalk_enabled",
|
||||
"wechat_enabled",
|
||||
@@ -59,10 +66,8 @@ class MessagePusher:
|
||||
if not any_channel_enabled:
|
||||
return False
|
||||
|
||||
# Check if manually stopped status is needed
|
||||
if check_manually_stopped and recording.manually_stopped:
|
||||
if message_type == 'end' and check_manually_stopped and recording.manually_stopped:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def push_messages(self, msg_title: str, push_content: str):
|
||||
|
||||
@@ -1181,7 +1181,7 @@ class SettingsPage(PageBase):
|
||||
)
|
||||
|
||||
login_required_switch = ft.Switch(
|
||||
value=self.get_config_value("login_required", True),
|
||||
value=self.get_config_value("login_required", False),
|
||||
on_change=toggle_login_required,
|
||||
)
|
||||
|
||||
|
||||
2
main.py
2
main.py
@@ -133,7 +133,7 @@ async def main(page: ft.Page) -> None:
|
||||
app.auth_manager = auth_manager
|
||||
await auth_manager.initialize()
|
||||
|
||||
login_required = app.settings.get_config_value("login_required", True)
|
||||
login_required = app.settings.get_config_value("login_required", False)
|
||||
|
||||
if login_required:
|
||||
session_token = await page.client_storage.get_async("session_token")
|
||||
|
||||
Reference in New Issue
Block a user