feat: add email push function (#616)

This commit is contained in:
灯火不休时
2024-09-18 10:42:15 +08:00
committed by GitHub
parent 72f84fdee7
commit cf45521a05
3 changed files with 47 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
[录制设置]
是否跳过代理检测(是/否) =
是否跳过代理检测(是/否) =
直播保存路径(不填则默认) =
保存文件夹是否以作者区分 =
保存文件夹是否以时间区分 =
@@ -23,12 +23,16 @@ ts录制完成后自动增加生成m4a格式 = 否
额外使用代理录制的平台(逗号分隔) =
[推送配置]
直播状态通知(可选微信|钉钉|tg或者都填) =
直播状态通知(可选微信|钉钉|tg|邮箱或者都填) =
钉钉推送接口链接 =
微信推送接口链接 =
钉钉通知@对象(填手机号) =
tgapi令牌 =
tg聊天id(个人或者群组id) =
smtp邮件服务器 =
发件人 =
发件人密码 =
收件人 =
自定义开播推送内容 =
自定义关播推送内容 =
只推送通知不录制(是/否) =
@@ -66,7 +70,7 @@ liuxing_cookie =
showroom_cookie =
acfun_cookie =
shiguang_cookie =
yinbo_cookie =
yinbo_cookie =
yingke_cookie =
zhihu_cookie =
@@ -84,3 +88,4 @@ popkontv密码 =
twitcasting账号类型 = normal
twitcasting账号 =
twitcasting密码 =

11
main.py
View File

@@ -72,7 +72,7 @@ from utils import (
logger, check_md5,
trace_error_decorator
)
from msg_push import dingtalk, xizhi, tg_bot
from msg_push import dingtalk, xizhi, tg_bot, email_message
version = "v3.0.7"
platforms = ("\n国内站点:抖音|快手|虎牙|斗鱼|YY|B站|小红书|bigo|blued|网易CC|千度热播|猫耳FM|Look|TwitCasting|百度|微博|"
@@ -634,6 +634,9 @@ def push_message(content: str) -> Union[str, list]:
if '钉钉' in live_status_push:
push_pts.append('钉钉')
dingtalk(dingtalk_api_url, content, dingtalk_phone_num)
if '邮箱' in live_status_push:
push_pts.append('邮箱')
email_message(mail_host, mail_pass, from_email, to_email, "直播间状态更新", content)
if 'TG' in live_status_push or 'tg' in live_status_push:
push_pts.append('TG')
tg_bot(tg_chat_id, tg_token, content)
@@ -1667,12 +1670,16 @@ 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|邮箱或者都填)', "")
dingtalk_api_url = read_config_value(config, '推送配置', '钉钉推送接口链接', "")
xizhi_api_url = read_config_value(config, '推送配置', '微信推送接口链接', "")
dingtalk_phone_num = read_config_value(config, '推送配置', '钉钉通知@对象(填手机号)', "")
tg_token = read_config_value(config, '推送配置', 'tgapi令牌', "")
tg_chat_id = read_config_value(config, '推送配置', 'tg聊天id(个人或者群组id)', "")
mail_host = read_config_value(config, '推送配置', 'SMTP邮件服务器', "")
from_email = read_config_value(config, '推送配置', '发件人', "")
mail_pass = read_config_value(config, '推送配置', '发件人密码', "")
to_email = read_config_value(config, '推送配置', '收件人', "")
begin_push_message_text = read_config_value(config, '推送配置', '自定义开播推送内容', "")
over_push_message_text = read_config_value(config, '推送配置', '自定义关播推送内容', "")
disable_record = options.get(read_config_value(config, '推送配置', '只推送通知不录制(是/否)', ""), False)

View File

@@ -13,6 +13,10 @@ import json
import urllib.request
from utils import trace_error_decorator
# 发送邮件相关库
import smtplib
from email.mime.text import MIMEText
no_proxy_handler = urllib.request.ProxyHandler({})
opener = urllib.request.build_opener(no_proxy_handler)
headers: Dict[str, str] = {'Content-Type': 'application/json'}
@@ -52,6 +56,28 @@ def xizhi(url: str, content: str) -> Dict[str, Any]:
json_data = json.loads(json_str)
return json_data
@trace_error_decorator
def email_message(mail_host: str, mail_pass: str, from_email: str, to_email:str, title: str , content: str) -> Dict[str, Any]:
receivers = [to_email] # 接收邮件地址
# 创建一个带附件的实例
message = MIMEText(content, 'plain', 'utf-8')
message['From'] = "{}".format(from_email)
message['To'] = to_email
message['Subject'] = title
try:
smtpObj = smtplib.SMTP_SSL(mail_host, 465)
smtpObj.login(from_email, mail_pass)
smtpObj.sendmail(from_email, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error: 无法发送邮件", e)
data = {'code': '200'}
json_data = json.dumps(data).encode('utf-8')
return json_data
@trace_error_decorator
def tg_bot(chat_id: int, token: str, content: str) -> Dict[str, Any]:
@@ -85,4 +111,7 @@ if __name__ == '__main__':
# telegram推送通知
token = '' # tg搜索"BotFather"获取的token值
chat_id = 000000 # tg搜索"userinfobot"获取的chat_id值即可发送推送消息给你自己如果下面的是群组id则发送到群
# tg_bot(chat_id, token, content)
# tg_bot(chat_id, token, content)
# 邮件推送通知
# email_message("", "","", "", "测试python发送邮件", "测试python发送邮件")