From 86b73a6d31b902930e6a680c22c0d6dac2ad99b8 Mon Sep 17 00:00:00 2001 From: farwmarth Date: Tue, 24 Sep 2024 18:28:34 +0800 Subject: [PATCH] =?UTF-8?q?bark=E6=8E=A8=E9=80=81=E6=94=AF=E6=8C=81=20(#63?= =?UTF-8?q?8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.ini | 3 ++- main.py | 8 ++++++-- msg_push.py | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/config/config.ini b/config/config.ini index 1f89cc1..be6585b 100644 --- a/config/config.ini +++ b/config/config.ini @@ -23,9 +23,10 @@ ts录制完成后自动增加生成m4a格式 = 否 额外使用代理录制的平台(逗号分隔) = [推送配置] -直播状态通知(可选微信|钉钉|tg|邮箱或者都填) = +直播状态通知(可选微信|钉钉|tg|邮箱|bark或者都填) = 钉钉推送接口链接 = 微信推送接口链接 = +bark推送接口链接 = 钉钉通知@对象(填手机号) = tgapi令牌 = tg聊天id(个人或者群组id) = diff --git a/main.py b/main.py index 224eaac..17c5124 100644 --- a/main.py +++ b/main.py @@ -72,7 +72,7 @@ from utils import ( logger, check_md5, trace_error_decorator ) -from msg_push import dingtalk, xizhi, tg_bot, email_message +from msg_push import dingtalk, xizhi, tg_bot, email_message, bark version = "v3.0.7" platforms = ("\n国内站点:抖音|快手|虎牙|斗鱼|YY|B站|小红书|bigo|blued|网易CC|千度热播|猫耳FM|Look|TwitCasting|百度|微博|" @@ -640,6 +640,9 @@ def push_message(content: str) -> Union[str, list]: if 'TG' in live_status_push or 'tg' in live_status_push: push_pts.append('TG') tg_bot(tg_chat_id, tg_token, content) + if 'BARK' in live_status_push or 'bark' in live_status_push: + push_pts.append('BARK') + bark(bark_api_url, content) push_pts = '、'.join(push_pts) if len(push_pts) > 0 else [] return push_pts @@ -1673,9 +1676,10 @@ while True: enable_proxy_platform_list = enable_proxy_platform.replace(',', ',').split(',') if enable_proxy_platform else None extra_enable_proxy = read_config_value(config, '录制设置', '额外使用代理录制的平台(逗号分隔)', '') extra_enable_proxy_platform_list = extra_enable_proxy.replace(',', ',').split(',') if extra_enable_proxy else None - live_status_push = read_config_value(config, '推送配置', '直播状态通知(可选微信|钉钉|tg|邮箱或者都填)', "") + live_status_push = read_config_value(config, '推送配置', '直播状态通知(可选微信|钉钉|tg|邮箱|bark或者都填)', "") dingtalk_api_url = read_config_value(config, '推送配置', '钉钉推送接口链接', "") xizhi_api_url = read_config_value(config, '推送配置', '微信推送接口链接', "") + bark_api_url = read_config_value(config, '推送配置', 'bark推送接口链接', "") dingtalk_phone_num = read_config_value(config, '推送配置', '钉钉通知@对象(填手机号)', "") tg_token = read_config_value(config, '推送配置', 'tgapi令牌', "") tg_chat_id = read_config_value(config, '推送配置', 'tg聊天id(个人或者群组id)', "") diff --git a/msg_push.py b/msg_push.py index 8a60bb6..2201e85 100644 --- a/msg_push.py +++ b/msg_push.py @@ -15,6 +15,8 @@ import smtplib from email.header import Header from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText +from urllib.parse import urljoin +import urllib.parse no_proxy_handler = urllib.request.ProxyHandler({}) opener = urllib.request.build_opener(no_proxy_handler) @@ -94,6 +96,16 @@ def tg_bot(chat_id: int, token: str, content: str) -> Dict[str, Any]: json_data = json.loads(json_str) return json_data +@trace_error_decorator +def bark(url: str, content: str) -> Dict[str, Any]: + json_data = {"body": content} + data = json.dumps(json_data).encode('utf-8') + req = urllib.request.Request(url, data = data, headers=headers) + response = opener.open(req, timeout=10) + json_str = response.read().decode("utf-8") + json_data = json.loads(json_str) + return json_data + if __name__ == '__main__': send_content = '张三 开播了!' # 推送内容 @@ -115,3 +127,6 @@ if __name__ == '__main__': # tg_bot(tg_chat_id, tg_token, send_content) # email_message("", "", "", "", "", "") + + bark_url= 'https://xxx.xxx.com/key/' + # bark(bark_url, send_content)