From 5e0a7360446beba085a31ce1b163a13307c6f86e Mon Sep 17 00:00:00 2001 From: ihmily <961532186@qq.com> Date: Fri, 5 Jul 2024 12:45:25 +0800 Subject: [PATCH] feat: add shiguang live record --- README.md | 18 ++++++++++++----- config/config.ini | 1 + main.py | 15 +++++++++++--- spider.py | 51 +++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 75 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 74515d6..2019a99 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ - [x] 流星直播 - [x] ShowRoom - [x] Acfun +- [x] 时光直播 - [ ] 更多平台正在更新中 @@ -99,6 +100,7 @@ 抖音: https://live.douyin.com/745964462470 https://v.douyin.com/iQFeBnt/ +https://live.douyin.com/yall1102 TikTok: https://www.tiktok.com/@pearlgaga88/live @@ -164,7 +166,7 @@ https://twitcasting.tv/c:uonq https://live.baidu.com/m/media/pclive/pchome/live.html?room_id=9175031377&tab_category 微博直播: -https://weibo.com/u/7676267963 +https://weibo.com/u/7676267963 (主页地址) https://weibo.com/l/wblive/p/show/1022:2321325026370190442592 酷狗直播: @@ -177,16 +179,19 @@ LiveMe: https://www.liveme.com/zh/v/17141543493018047815/index.html 花椒直播: -https://www.huajiao.com/user/223184650 +https://www.huajiao.com/user/223184650 (主页地址) 流星直播: https://www.7u66.com/100960 ShowRoom: -https://www.showroom-live.com/room/profile?room_id=480206 +https://www.showroom-live.com/room/profile?room_id=480206 (主页地址) Acfun: https://live.acfun.cn/live/179922 + +时光直播: +https://www.rengzu.com/180778 ``` 直播间分享地址和网页端长地址都能正常进行录制(抖音尽量用长链接,避免因短链接转换失效导致不能正常录制,而且需要有nodejs环境,否则无法转换)。 @@ -314,11 +319,14 @@ docker-compose stop ## ⏳提交日志 +- 20240705 + - 新增时光直播录制 + - 20240701 - 修复虎牙直播录制2分钟断流问题 - + - 新增自定义直播推送内容 - + - 20240621 - 新增Acfun、ShowRoom直播录制 - 修复微博录制、新增直播源线路 diff --git a/config/config.ini b/config/config.ini index 7a82f52..6cd1403 100644 --- a/config/config.ini +++ b/config/config.ini @@ -64,6 +64,7 @@ huajiao_cookie = liuxing_cookie = showroom_cookie = acfun_cookie = +shiguang_cookie = [Authorization] popkontv_token = diff --git a/main.py b/main.py index 5bb9312..28b1ee6 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,7 @@ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-17 23:52:05 -Update: 2024-07-01 22:36:12 +Update: 2024-07-05 12:36:12 Copyright (c) 2023-2024 by Hmily, All Rights Reserved. Function: Record live stream video. """ @@ -60,7 +60,8 @@ from spider import ( get_liuxing_stream_url, get_showroom_stream_data, get_acfun_stream_data, - get_huya_app_stream_url + get_huya_app_stream_url, + get_shiguang_stream_url ) from utils import ( @@ -968,6 +969,11 @@ def start_record(url_data: tuple, count_variable: int = -1): url=record_url, proxy_addr=proxy_address, cookies=acfun_cookie) port_info = get_stream_url(json_data, record_quality, url_type='flv', extra_key='url') + elif record_url.find("rengzu.com/") > -1: + platform = '时光直播' + with semaphore: + port_info = get_shiguang_stream_url( + url=record_url, proxy_addr=proxy_address, cookies=shiguang_cookie) else: logger.error(f'{record_url} 未知直播地址') return @@ -1700,6 +1706,7 @@ while True: liuxing_cookie = read_config_value(config, 'Cookie', 'liuxing_cookie', '') showroom_cookie = read_config_value(config, 'Cookie', 'showroom_cookie', '') acfun_cookie = read_config_value(config, 'Cookie', 'acfun_cookie', '') + shiguang_cookie = read_config_value(config, 'Cookie', 'shiguang_cookie', '') if len(video_save_type) > 0: if video_save_type.upper().lower() == "FLV".lower(): @@ -1794,7 +1801,9 @@ while True: 'www.7u66.com', 'wap.7u66.com', 'live.acfun.cn', - 'm.acfun.cn' + 'm.acfun.cn', + 'www.rengzu.com', + 'wap.rengzu.com', ] overseas_platform_host = [ 'www.tiktok.com', diff --git a/spider.py b/spider.py index 48c9000..b2be310 100644 --- a/spider.py +++ b/spider.py @@ -4,7 +4,7 @@ Author: Hmily GitHub: https://github.com/ihmily Date: 2023-07-15 23:15:00 -Update: 2024-07-01 23:04:00 +Update: 2024-07-05 12:33:00 Copyright (c) 2023 by Hmily, All Rights Reserved. Function: Get live stream data. """ @@ -2208,6 +2208,51 @@ def get_acfun_stream_data(url: str, proxy_addr: Union[str, None] = None, cookies return result +@trace_error_decorator +def get_shiguang_stream_url(url: str, proxy_addr: Union[str, None] = None, cookies: Union[str, None] = None) -> \ + Dict[str, Any]: + headers = { + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Mobile/15E148 Safari/604.1', + 'Accept': 'application/json, text/plain, */*', + 'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2', + 'Referer': 'https://wap.rengzu.com/122377?promoters=956629', + } + if cookies: + headers['Cookie'] = cookies + + room_id = url.split('?')[0].rsplit('/', maxsplit=1)[-1] + params = { + 'roomidx': room_id, + 'currentUrl': f'https://wap.rengzu.com/{room_id}', + } + play_api = f'https://wap.rengzu.com/api/ui/room/v1.0.0/live.ashx?{urllib.parse.urlencode(params)}' + json_str = get_req(play_api, proxy_addr=proxy_addr, headers=headers) + json_data = json.loads(json_str) + anchor_name = json_data['data']['roomInfo']['nickname'] + live_status = json_data['data']['roomInfo']['live_stat'] + + def get_live_domain(page_url): + html_str = get_req(page_url, proxy_addr=proxy_addr, headers=headers) + config_json_str = re.findall("var config = (.*?)config.webskins", + html_str, re.S)[0].rsplit(";", maxsplit=1)[0].strip() + config_json_data = json.loads(config_json_str) + stream_flv_domain = config_json_data['domainpullstream_flv'] + stream_hls_domain = config_json_data['domainpullstream_hls'] + return stream_flv_domain, stream_hls_domain + + result = {"anchor_name": anchor_name, "is_live": False} + if live_status == 1: + flv_domain, hls_domain = get_live_domain(url) + live_id = json_data['data']['roomInfo']['liveID'] + flv_url = f'{flv_domain}/{live_id}.flv' + m3u8_url = f'{hls_domain}/{live_id}.m3u8' + result["is_live"] = True + result["m3u8_url"] = m3u8_url + result["flv_url"] = flv_url + result["record_url"] = flv_url + return result + + if __name__ == '__main__': # 尽量用自己的cookie,以避免默认的不可用导致无法获取数据 # 以下示例链接不保证时效性,请自行查看链接是否能正常访问 @@ -2250,6 +2295,7 @@ if __name__ == '__main__': # room_url = 'https://www.showroom-live.com/room/profile?room_id=511033' # showroom # room_url = 'https://www.showroom-live.com/r/TPS0728' # showroom # room_url = 'https://live.acfun.cn/live/17912421' # Acfun + # room_url = 'https://www.rengzu.com/180778' # 时光直播 print(get_douyin_stream_data(room_url, proxy_addr='')) # print(get_douyin_app_stream_data(room_url, proxy_addr='')) @@ -2282,4 +2328,5 @@ if __name__ == '__main__': # print(get_huajiao_stream_url(room_url, proxy_addr='')) # print(get_liuxing_stream_url(room_url, proxy_addr='')) # print(get_showroom_stream_data(room_url, proxy_addr='')) - # print(get_acfun_stream_data(room_url, proxy_addr='')) \ No newline at end of file + # print(get_acfun_stream_data(room_url, proxy_addr='')) + # print(get_shiguang_stream_url(room_url, proxy_addr='')) \ No newline at end of file