diff --git a/config/config.ini b/config/config.ini index 238b1b9..9222495 100644 --- a/config/config.ini +++ b/config/config.ini @@ -35,6 +35,7 @@ tg聊天id(个人或者群组id) = smtp邮件服务器 = 发件人邮箱 = 发件人密码(授权码) = +发件人显示昵称 = 收件人邮箱 = 自定义开播推送内容 = 自定义关播推送内容 = diff --git a/demo.py b/demo.py deleted file mode 100644 index c1c8d1c..0000000 --- a/demo.py +++ /dev/null @@ -1,197 +0,0 @@ -# -*- coding: utf-8 -*- -from douyinliverecorder.logger import logger -from douyinliverecorder import spider - -# 以下示例直播间链接不保证时效性,请自行查看链接是否能正常访问 -LIVE_STREAM_CONFIG = { - "douyin": { - "url": "https://live.douyin.com/745964462470", - "func": spider.get_douyin_app_stream_data, - }, - "tiktok": { - "url": "https://www.tiktok.com/@pearlgaga88/live", - "func": spider.get_tiktok_stream_data, - }, - "kuaishou": { - "url": "https://live.kuaishou.com/u/yall1102", - "func": spider.get_kuaishou_stream_data, - }, - "huya": { - "url": "https://www.huya.com/116", - "func": spider.get_huya_app_stream_url, - }, - "douyu": { - "url": "https://www.douyu.com/topic/wzDBLS6?rid=4921614&dyshid=", - "func": spider.get_douyu_info_data, - }, - "yy": { - "url": "https://www.yy.com/22490906/22490906", - "func": spider.get_yy_stream_data, - }, - "bilibili": { - "url": "https://live.bilibili.com/21593109", - "func": spider.get_bilibili_stream_data, - }, - "xhs": { - "url": "http://xhslink.com/O9f9fM", - "func": spider.get_xhs_stream_url, - }, - "bigo": { - "url": "https://www.bigo.tv/cn/716418802", - "func": spider.get_bigo_stream_url, - }, - "blued": { - "url": "https://app.blued.cn/live?id=Mp6G2R", - "func": spider.get_blued_stream_url, - }, - "afreecatv": { - "url": "https://play.afreecatv.com/sw7love", - "func": spider.get_afreecatv_stream_data, - }, - "soop": { - "url": "https://play.sooplive.co.kr/sw7love", - "func": spider.get_afreecatv_stream_data, - }, - "netease": { - "url": "https://cc.163.com/583946984", - "func": spider.get_netease_stream_data, - }, - "qiandurebo": { - "url": "https://qiandurebo.com/web/video.php?roomnumber=33333", - "func": spider.get_qiandurebo_stream_data, - }, - "pandatv": { - "url": "https://www.pandalive.co.kr/live/play/bara0109", - "func": spider.get_pandatv_stream_data, - }, - "maoerfm": { - "url": "https://fm.missevan.com/live/868895007", - "func": spider.get_maoerfm_stream_url, - }, - "winktv": { - "url": "https://www.winktv.co.kr/live/play/anjer1004", - "func": spider.get_winktv_stream_data, - }, - "flextv": { - "url": "https://www.flextv.co.kr/channels/593127/live", - "func": spider.get_flextv_stream_data, - }, - "looklive": { - "url": "https://look.163.com/live?id=65108820&position=3", - "func": spider.get_looklive_stream_url, - }, - "popkontv": { - "url": "https://www.popkontv.com/live/view?castId=wjfal007&partnerCode=P-00117", - "func": spider.get_popkontv_stream_url, - }, - "twitcasting": { - "url": "https://twitcasting.tv/c:uonq", - "func": spider.get_twitcasting_stream_url, - }, - "baidu": { - "url": "https://live.baidu.com/m/media/pclive/pchome/live.html?room_id=9175031377&tab_category", - "func": spider.get_baidu_stream_data, - }, - "weibo": { - "url": "https://weibo.com/u/7849520225", - "func": spider.get_weibo_stream_data, - }, - "kugou": { - "url": "https://fanxing2.kugou.com/50428671?refer=2177&sourceFrom=", - "func": spider.get_kugou_stream_url, - }, - "twitchtv": { - "url": "https://www.twitch.tv/gamerbee", - "func": spider.get_twitchtv_stream_data, - }, - "liveme": { - "url": "https://www.liveme.com/zh/v/17141937295821012854/index.html", - "func": spider.get_liveme_stream_url, - }, - "huajiao": { - "url": "https://www.huajiao.com/user/223184650", - "func": spider.get_huajiao_stream_url, - }, - "liuxing": { - "url": "https://www.7u66.com/100960", - "func": spider.get_liuxing_stream_url, - }, - "showroom": { - "url": "https://www.showroom-live.com/room/profile?room_id=511033", - "func": spider.get_showroom_stream_data, - }, - "acfun": { - "url": "https://live.acfun.cn/live/17912421", - "func": spider.get_acfun_stream_data, - }, - "changliao": { - "url": "https://www.tlclw.com/801044397", - "func": spider.get_changliao_stream_url, - }, - "yingke": { - "url": "https://www.inke.cn/liveroom/index.html?uid=710032101&id=1720857535354099", - "func": spider.get_yingke_stream_url, - }, - "yinbo": { - "url": "https://live.ybw1666.com/800002949", - "func": spider.get_yinbo_stream_url, - }, - "zhihu": { - "url": "https://www.zhihu.com/theater/114453", - "func": spider.get_zhihu_stream_url, - }, - "chzzk": { - "url": "https://chzzk.naver.com/live/458f6ec20b034f49e0fc6d03921646d2", - "func": spider.get_chzzk_stream_data, - }, - "haixiu": { - "url": "https://www.haixiutv.com/6095106", - "func": spider.get_haixiu_stream_url, - }, - "vvxqiu": { - "url": "https://h5webcdn-pro.vvxqiu.com//activity/videoShare/videoShare.html?h5Server=https://h5p.vvxqiu.com" - "&roomId=LP115924473&platformId=vvstar", - "func": spider.get_vvxqiu_stream_url, - }, - "17live": { - "url": "https://17.live/en/live/6302408", - "func": spider.get_17live_stream_url, - }, - "langlive": { - "url": "https://www.lang.live/en-US/room/3349463", - "func": spider.get_langlive_stream_url, - }, - "pplive": { - "url": "https://m.pp.weimipopo.com/live/preview.html?uid=91648673&anchorUid=91625862&app=plpl", - "func": spider.get_pplive_stream_url, - }, - "6room": { - "url": "https://v.6.cn/634435", - "func": spider.get_6room_stream_url, - }, - "lehai": { - "url": "https://www.lehaitv.com/8059096", - "func": spider.get_haixiu_stream_url, - }, - "huamao": { - "url": "https://h.catshow168.com/live/preview.html?uid=19066357&anchorUid=18895331", - "func": spider.get_pplive_stream_url, - } -} - - -def test_live_stream(platform_name: str, proxy_addr=None) -> None: - if platform_name in LIVE_STREAM_CONFIG: - config = LIVE_STREAM_CONFIG[platform_name] - try: - stream_data = config['func'](config['url'], proxy_addr=proxy_addr) - logger.debug(f"Stream data for {platform_name}: {stream_data}") - except Exception as e: - logger.error(f"Error fetching stream data for {platform_name}: {e}") - else: - logger.warning(f"No configuration found for platform: {platform_name}") - - -if __name__ == "__main__": - platform = "douyin" - test_live_stream(platform) diff --git a/main.py b/main.py index 3f5236e..5d40687 100644 --- a/main.py +++ b/main.py @@ -253,7 +253,9 @@ def push_message(record_name, content: str) -> None: push_functions = { '微信': lambda: xizhi(xizhi_api_url, content), '钉钉': lambda: dingtalk(dingtalk_api_url, content, dingtalk_phone_num), - '邮箱': lambda: email_message(mail_host, mail_password, from_email, to_email, "直播间状态更新通知", content), + '邮箱': lambda: email_message( + email_host, sender_email, email_password, sender_name, to_email, "直播间状态更新通知", content + ), 'TG': lambda: tg_bot(tg_chat_id, tg_token, content), 'BARK': lambda: bark( bark_msg_api, title="直播录制通知", content=content, level=bark_msg_level, sound=bark_msg_ring), @@ -291,7 +293,6 @@ def clear_record_info(record_name, record_url): def check_subprocess(record_name: str, record_url: str, ffmpeg_command: list, save_type: str, bash_file_path: Union[str, None] = None) -> bool: - save_path_name = ffmpeg_command[-1] process = subprocess.Popen( ffmpeg_command, stderr=subprocess.STDOUT, startupinfo=get_startup_info(os_type) @@ -926,9 +927,11 @@ def start_record(url_data: tuple, count_variable: int = -1): _filepath, _ = urllib.request.urlretrieve(real_url, save_file_path) record_finished = True recording.discard(record_name) - print(f"\n{anchor_name} {time.strftime('%Y-%m-%d %H:%M:%S')} 直播录制完成\n") + print( + f"\n{anchor_name} {time.strftime('%Y-%m-%d %H:%M:%S')} 直播录制完成\n") except Exception as e: - print(f"\n{anchor_name} {time.strftime('%Y-%m-%d %H:%M:%S')} 直播录制出错,请检查网络\n") + print( + f"\n{anchor_name} {time.strftime('%Y-%m-%d %H:%M:%S')} 直播录制出错,请检查网络\n") logger.error(f"错误信息: {e} 发生错误的行数: {e.__traceback__.tb_lineno}") with max_request_lock: error_count += 1 @@ -1289,7 +1292,8 @@ def check_ffmpeg_existence(): # print(f"已将ffmpeg路径添加到环境变量:{ffmpeg_path}") return True else: - logger.error("未检测到ffmpeg。请确保ffmpeg位于系统路径中,或将其路径添加到环境变量。缺少ffmpeg将导致无法进行录制。") + logger.error( + "未检测到ffmpeg。请确保ffmpeg位于系统路径中,或将其路径添加到环境变量。缺少ffmpeg将导致无法进行录制。") sys.exit(0) finally: dev_null.close() @@ -1415,9 +1419,10 @@ while True: 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_password = read_config_value(config, '推送配置', '发件人密码(授权码)', "") + email_host = read_config_value(config, '推送配置', 'SMTP邮件服务器', "") + sender_email = read_config_value(config, '推送配置', '发件人邮箱', "") + email_password = read_config_value(config, '推送配置', '发件人密码(授权码)', "") + sender_name = 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, '推送配置', '自定义关播推送内容', "") @@ -1484,10 +1489,12 @@ while True: else: video_save_type = "TS" + def contains_url(string: str) -> bool: pattern = r"(https?://)?(www\.)?[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+(:\d+)?(/.*)?" return re.search(pattern, string) is not None + try: url_comments = [] with (open(url_config_file, "r", encoding=text_encoding, errors='ignore') as file): @@ -1664,4 +1671,4 @@ while True: t2.start() first_run = False - time.sleep(3) \ No newline at end of file + time.sleep(3) diff --git a/msg_push.py b/msg_push.py index fd4e6f3..5cc5461 100644 --- a/msg_push.py +++ b/msg_push.py @@ -4,11 +4,12 @@ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-09-03 19:18:36 -Update: 2024-10-12 19:22:12 +Update: 2024-10-23 23:18:12 Copyright (c) 2023-2024 by Hmily, All Rights Reserved. """ from typing import Dict, Any, Optional import json +import base64 import urllib.request import smtplib from email.header import Header @@ -79,14 +80,14 @@ def xizhi(url: str, content: str, title: str = '直播间状态更新') -> Dict[ return {"success": success, "error": error} -def email_message(mail_host: str, mail_pass: str, from_email: str, to_email: str, title: str, content: str) -> ( - Dict)[str, Any]: - +def email_message(email_host: str, sender_email: str, email_pass: str, sender_name: str, to_email: str, title: str, + content: str) -> Dict[str, Any]: receivers = to_email.replace(',', ',').split(',') if to_email.strip() else [] try: message = MIMEMultipart() - message['From'] = "{}".format(from_email) + send_name = base64.b64encode(sender_name.encode("utf-8")).decode() + message['From'] = f'=?UTF-8?B?{send_name}?= <{sender_email}>' message['Subject'] = Header(title, 'utf-8') if len(receivers) == 1: message['To'] = receivers[0] @@ -94,9 +95,9 @@ def email_message(mail_host: str, mail_pass: str, from_email: str, to_email: str t_apart = MIMEText(content, 'plain', 'utf-8') message.attach(t_apart) - smtp_obj = smtplib.SMTP_SSL(mail_host, 465) - smtp_obj.login(from_email, mail_pass) - smtp_obj.sendmail(from_email, receivers, message.as_string()) + smtp_obj = smtplib.SMTP_SSL(email_host, 465) + smtp_obj.login(sender_email, email_pass) + smtp_obj.sendmail(sender_email, receivers, message.as_string()) return {"success": receivers, "error": []} except smtplib.SMTPException as e: print(f'邮件推送失败, 推送邮箱:{to_email}, 错误信息:{e}') @@ -177,7 +178,15 @@ if __name__ == '__main__': tg_chat_id = 000000 # tg搜索"userinfobot"获取的chat_id值,即可发送推送消息给你自己,如果下面的是群组id则发送到群 # tg_bot(tg_chat_id, tg_token, send_content) - # email_message("", "", "", "", "", "") + email_message( + email_host="smtp.qq.com", + sender_email="", + email_pass="", + sender_name="邮箱昵称示例", + to_email="", + title="邮箱标题", + content="123456" + ) bark_url = 'https://xxx.xxx.com/key/' - # bark(bark_url, send_title, send_content) \ No newline at end of file +# bark(bark_url, send_title, send_content)