fix: xhs live room url parse

This commit is contained in:
ihmily 2024-09-01 19:04:29 +08:00
parent 8f11402c53
commit 81fee01a04
2 changed files with 7 additions and 10 deletions

View File

@ -4,7 +4,7 @@
Author: Hmily
GitHub: https://github.com/ihmily
Date: 2023-07-17 23:52:05
Update: 2024-07-20 20:41:12
Update: 2024-09-01 19:02:12
Copyright (c) 2023-2024 by Hmily, All Rights Reserved.
Function: Record live stream video.
"""
@ -1809,8 +1809,7 @@ while True:
url = url.split('?')[0]
if url_host in ['www.xiaohongshu.com', 'www.redelight.cn']:
if 'share_source' in url:
xhs_url_h, xhs_url_t, = url.split('?')
new_xhs_url = xhs_url_h + '?appuid=' + xhs_url_t.split('&appuid=')[1].split('&')[0]
new_xhs_url = url.split('?')[0]
update_file(url_config_file, url, new_xhs_url)
url = new_xhs_url
@ -1865,4 +1864,4 @@ while True:
first_run = False
time.sleep(3)
time.sleep(3)

View File

@ -4,7 +4,7 @@
Author: Hmily
GitHub: https://github.com/ihmily
Date: 2023-07-15 23:15:00
Update: 2024-09-01 17:04:00
Update: 2024-09-01 19:02:00
Copyright (c) 2023 by Hmily, All Rights Reserved.
Function: Get live stream data.
"""
@ -663,10 +663,8 @@ def get_xhs_stream_url(url: str, proxy_addr: Union[str, None] = None, cookies: U
if 'xhslink.com' in url:
url = get_req(url, proxy_addr=proxy_addr, headers=headers, redirect_url=True)
appuid = re.search('host_id=(.*?)(?=&|$)', url).group(1)
else:
appuid = re.search('appuid=(.*?)(?=&|$)', url).group(1)
room_id = re.search('/livestream/(.*?)(?=/|\?)', url).group(1)
room_id = re.search('/livestream/(.*?)(?=/|\?|$)', url).group(1)
app_api = f'https://www.xiaohongshu.com/api/sns/red/live/app/v1/ecology/outside/share_info?room_id={room_id}'
# app_api = f'https://www.redelight.cn/api/sns/red/live/app/v1/ecology/outside/share_info?room_id={room_id}'
json_str = get_req(url=app_api, proxy_addr=proxy_addr, headers=headers)
@ -680,7 +678,7 @@ def get_xhs_stream_url(url: str, proxy_addr: Union[str, None] = None, cookies: U
# 这个判断不准确无论是否在直播status都为0,暂无法判断
if live_status == 0:
flv_url = f'http://live-play.xhscdn.com/live/{room_id}.flv?uid={appuid}'
flv_url = f'http://live-play.xhscdn.com/live/{room_id}.flv'
result['flv_url'] = flv_url
result['is_live'] = True
result['record_url'] = flv_url