Skip to content

Commit 815a596

Browse files
committed
fix: optimize message push settings
1 parent c951edd commit 815a596

File tree

8 files changed

+49
-12
lines changed

8 files changed

+49
-12
lines changed

app/core/record_manager.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,9 @@ async def check_if_live(self, recording: Recording):
272272

273273
msg_manager = MessagePusher(self.settings)
274274
user_config = self.settings.user_config
275-
if MessagePusher.should_push_message(self.settings, recording, message_type='start'):
275+
276+
if (MessagePusher.should_push_message(self.settings, recording, message_type='start')
277+
and not recording.notified_live_start):
276278
push_content = self._["push_content"]
277279
begin_push_message_text = user_config.get("custom_stream_start_content")
278280
if begin_push_message_text:
@@ -286,20 +288,28 @@ async def check_if_live(self, recording: Recording):
286288
msg_title = msg_title or self._["status_notify"]
287289

288290
self.app.page.run_task(msg_manager.push_messages, msg_title, push_content)
289-
290-
if not user_config.get("only_notify_no_record"):
291+
recording.notified_live_start = True
292+
293+
if not recording.only_notify_no_record:
291294
recording.loop_time_seconds = self.loop_time_seconds
292295
self.start_update(recording)
293296
self.app.page.run_task(recorder.start_recording, stream_info)
294297
else:
295-
notify_loop_time = user_config.get("notify_loop_time")
296-
recording.loop_time_seconds = int(notify_loop_time or 3600)
298+
if recording.notified_live_start:
299+
notify_loop_time = user_config.get("notify_loop_time")
300+
recording.loop_time_seconds = int(notify_loop_time or 3600)
301+
else:
302+
recording.loop_time_seconds = self.loop_time_seconds
297303
recording.status_info = RecordingStatus.NOT_RECORDING
298304
recording.is_checking = False
299305

300306
self.app.page.run_task(self.app.record_card_manager.update_card, recording)
301307
self.app.page.pubsub.send_others_on_topic("update", recording)
302308
else:
309+
if not recording.is_live and recording.notified_live_start:
310+
recording.notified_live_start = False
311+
recording.notified_live_end = False
312+
303313
recording.is_checking = False
304314
recording.status_info = RecordingStatus.MONITORING
305315
title = f"{stream_info.anchor_name or recording.streamer_name} - {self._[recording.quality]}"

app/core/stream_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ async def start_ffmpeg(
292292
user_config = self.settings.user_config
293293

294294
if self.app.recording_enabled and MessagePusher.should_push_message(
295-
self.settings, self.recording, check_manually_stopped=True, message_type='end'):
295+
self.settings, self.recording, check_manually_stopped=True, message_type='end') and not self.recording.notified_live_end:
296296
push_content = self._["push_content_end"]
297297
end_push_message_text = user_config.get("custom_stream_end_content")
298298
if end_push_message_text:
@@ -306,6 +306,7 @@ async def start_ffmpeg(
306306
msg_title = msg_title or self._["status_notify"]
307307

308308
self.app.page.run_task(msg_manager.push_messages, msg_title, push_content)
309+
self.recording.notified_live_end = True
309310

310311
self.recording.is_recording = False
311312
try:

app/models/recording_model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def __init__(
1616
scheduled_start_time,
1717
monitor_hours,
1818
recording_dir,
19-
enabled_message_push
19+
enabled_message_push,
20+
only_notify_no_record
2021
):
2122
"""
2223
Initialize a recording object.
@@ -34,6 +35,7 @@ def __init__(
3435
:param monitor_hours: Number of hours to monitor from the scheduled recording start time, e.g., 3.
3536
:param recording_dir: Directory path where the recorded files will be saved.
3637
:param enabled_message_push: Whether to enable message push.
38+
:param only_notify_no_record: Whether to only notify when no record is made.
3739
"""
3840

3941
self.rec_id = rec_id
@@ -49,6 +51,7 @@ def __init__(
4951
self.monitor_hours = monitor_hours
5052
self.recording_dir = recording_dir
5153
self.enabled_message_push = enabled_message_push
54+
self.only_notify_no_record = only_notify_no_record
5255
self.scheduled_time_range = None
5356
self.title = f"{streamer_name} - {self.quality}"
5457
self.speed = "X KB/s"
@@ -89,6 +92,7 @@ def to_dict(self):
8992
"enabled_message_push": self.enabled_message_push,
9093
"platform": self.platform,
9194
"platform_key": self.platform_key,
95+
"only_notify_no_record": self.only_notify_no_record
9296
}
9397

9498
@classmethod
@@ -108,6 +112,7 @@ def from_dict(cls, data):
108112
data.get("monitor_hours"),
109113
data.get("recording_dir"),
110114
data.get("enabled_message_push"),
115+
data.get("only_notify_no_record")
111116
)
112117
recording.title = data.get("title", recording.title)
113118
recording.display_title = data.get("display_title", recording.title)

app/ui/components/card_dialog.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, app, recording):
1818

1919
def load(self):
2020
language = self.app.language_manager.language
21-
for key in ("recording_card", "recording_manager", "base", "video_quality"):
21+
for key in ("recording_card", "recording_manager", "base", "video_quality", "recording_dialog"):
2222
self._.update(language.get(key, {}))
2323

2424
def get_content(self, recording):
@@ -40,6 +40,7 @@ def get_content(self, recording):
4040
from ...messages.message_pusher import MessagePusher
4141
should_push_message = MessagePusher.should_push_message(self.app.settings, recording)
4242
message_push = self._["enabled"] if should_push_message else self._["disabled"]
43+
only_notify_no_record = self._["enabled"] if recording.only_notify_no_record else self._["disabled"]
4344

4445
dialog_content = ft.Column(
4546
[
@@ -56,6 +57,7 @@ def get_content(self, recording):
5657
ft.Text(f"{self._['scheduled_recording']}: {scheduled_recording_status}", size=14),
5758
ft.Text(f"{self._['scheduled_time_range']}: {scheduled_time_range}", size=14),
5859
ft.Text(f"{self._['message_push']}: {message_push}", size=14),
60+
ft.Text(f"{self._['only_notify_no_record']}: {only_notify_no_record}", size=14),
5961
ft.Text(f"{self._['save_path']}: {save_path}", size=14, selectable=True),
6062
ft.Text(f"{self._['recording_status']}: {recording_status_info}", size=14),
6163
],

app/ui/components/recording_dialog.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ async def show_dialog(self):
3535
video_segment_time = user_config.get('video_segment_time', 1800)
3636
segment_record = initial_values.get("segment_record", segmented_recording_enabled)
3737
segment_time = initial_values.get("segment_time", video_segment_time)
38+
only_notify_no_record = user_config.get("only_notify_no_record", False)
3839

3940
async def on_url_change(_):
4041
"""Enable or disable the submit button based on whether the URL field is filled."""
@@ -221,6 +222,18 @@ async def handle_change(_):
221222
width=500,
222223
)
223224

225+
no_record_dropdown = ft.Dropdown(
226+
label=self._["only_notify_no_record"],
227+
options=[
228+
ft.dropdown.Option("true", self._["yes"]),
229+
ft.dropdown.Option("false", self._["no"]),
230+
],
231+
border_radius=5,
232+
filled=False,
233+
value="true" if only_notify_no_record else "false",
234+
width=500,
235+
)
236+
224237
hint_text_dict = {
225238
"en": "Example:\n0,https://v.douyin.com/AbcdE,nickname1\n0,https://v.douyin.com/EfghI,nickname2\n\nPS: "
226239
"0=original image or Blu ray, 1=ultra clear, 2=high-definition, 3=standard definition, 4=smooth\n",
@@ -268,7 +281,8 @@ async def handle_change(_):
268281
scheduled_setting_dropdown,
269282
schedule_and_monitor_row,
270283
monitor_hours_input,
271-
message_push_dropdown
284+
message_push_dropdown,
285+
no_record_dropdown
272286
],
273287
tight=True,
274288
spacing=10,
@@ -324,7 +338,8 @@ async def on_confirm(e):
324338
"scheduled_start_time": str(scheduled_start_time_input.value),
325339
"monitor_hours": monitor_hours_input.value,
326340
"recording_dir": recording_dir_field.value,
327-
"enabled_message_push": message_push_dropdown.value == "true"
341+
"enabled_message_push": message_push_dropdown.value == "true",
342+
"only_notify_no_record": no_record_dropdown.value == "true"
328343
}
329344
]
330345
await self.on_confirm_callback(recordings_info)

app/ui/views/home_view.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ async def add_recording(self, recordings_info):
491491
scheduled_start_time=recording_info["scheduled_start_time"],
492492
monitor_hours=recording_info["monitor_hours"],
493493
recording_dir=recording_info["recording_dir"],
494-
enabled_message_push=recording_info["enabled_message_push"]
494+
enabled_message_push=recording_info["enabled_message_push"],
495+
only_notify_no_record=recording_info["only_notify_no_record"]
495496
)
496497
else:
497498
recording = Recording(
@@ -507,7 +508,8 @@ async def add_recording(self, recordings_info):
507508
scheduled_start_time=user_config.get("scheduled_start_time"),
508509
monitor_hours=user_config.get("monitor_hours"),
509510
recording_dir=None,
510-
enabled_message_push=False
511+
enabled_message_push=False,
512+
only_notify_no_record=user_config.get("only_notify_no_record"),
511513
)
512514

513515
platform, platform_key = get_platform_info(recording.url)

locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"scheduled_start_time": "Daily Monitoring Start Time",
5757
"monitor_hours": "Daily Monitoring Hours",
5858
"enable_message_push": "Enable Message Push",
59+
"only_notify_no_record": "Only notify without recording",
5960
"batch_input_tip": "Batch Input (one record per line)",
6061
"single_input": "Single Input",
6162
"batch_input": "Batch Input",

locales/zh_CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"scheduled_start_time": "每日监听开始时间",
5757
"monitor_hours": "每日监听小时数",
5858
"enable_message_push": "是否开启消息推送",
59+
"only_notify_no_record": "仅通知不录制",
5960
"batch_input_tip": "批量录入(每行一条记录)",
6061
"single_input": "单个录入",
6162
"batch_input": "批量录入",

0 commit comments

Comments
 (0)