diff --git a/main.py b/main.py index 3d89982..2313813 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-06-12 12:41:00 +Update: 2024-06-13 21:33:10 Copyright (c) 2023-2024 by Hmily, All Rights Reserved. Function: Record live stream video. """ @@ -891,7 +891,8 @@ def start_record(url_data: tuple, count_variable: int = -1): port_info = get_bilibili_stream_url(json_data, record_quality) elif record_url.find("https://www.redelight.cn/") > -1 or \ - record_url.find("https://www.xiaohongshu.com/") > -1: + record_url.find("https://www.xiaohongshu.com/") > -1 or \ + record_url.find("http://xhslink.com/") > -1: platform = '小红书直播' if retry > 0: time.sleep(7200) @@ -1862,6 +1863,7 @@ while True: 'live.bilibili.com', 'www.redelight.cn', 'www.xiaohongshu.com', + 'xhslink.com', 'www.bigo.tv', 'app.blued.cn', 'cc.163.com', diff --git a/spider.py b/spider.py index 75eb0c1..d2272c3 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-06-12 12:35:17 +Update: 2024-06-13 21:19:48 Copyright (c) 2023 by Hmily, All Rights Reserved. Function: Get live stream data. """ @@ -45,7 +45,8 @@ def get_req( json_data: Union[dict, list, None] = None, timeout: int = 20, abroad: bool = False, - content_conding: str = 'utf-8' + content_conding: str = 'utf-8', + redirect_url: bool = False, ) -> Union[str, Any]: if headers is None: headers = {} @@ -60,6 +61,8 @@ def get_req( timeout=timeout) else: response = requests.get(url, headers=headers, proxies=proxies, timeout=timeout) + if redirect_url: + return response.url resp_str = response.text else: if data and not isinstance(data, bytes): @@ -74,6 +77,8 @@ def get_req( response = urllib.request.urlopen(req, timeout=timeout) else: response = opener.open(req, timeout=timeout) + if redirect_url: + return response.url content_encoding = response.info().get('Content-Encoding') try: if content_encoding == 'gzip': @@ -514,7 +519,11 @@ def get_xhs_stream_url(url: str, proxy_addr: Union[str, None] = None, cookies: U if cookies: headers['Cookie'] = cookies - appuid = re.search('appuid=(.*?)(?=&|$)', url).group(1) + 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) 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}' @@ -527,7 +536,7 @@ def get_xhs_stream_url(url: str, proxy_addr: Union[str, None] = None, cookies: U "is_live": False, } - # 这个判断不准确,无论是否在直播status都为0 + # 这个判断不准确,无论是否在直播status都为0,暂无法判断 if live_status == 0: flv_url = f'http://live-play.xhscdn.com/live/{room_id}.flv?uid={appuid}' result['flv_url'] = flv_url @@ -2039,6 +2048,7 @@ if __name__ == '__main__': # room_url = 'https://live.bilibili.com/21593109' # b站直播 # room_url = 'https://live.bilibili.com/23448867' # b站直播 # 小红书直播 + # room_url = 'http://xhslink.com/O9f9fM' # room_url = 'https://www.redelight.cn/hina/livestream/569077534207413574?appuid=5f3f478a00000000010005b3&' # room_url = 'https://www.xiaohongshu.com/hina/livestream/569098486282043893?appuid=5f3f478a00000000010005b3&' # room_url = 'https://www.bigo.tv/cn/716418802' # bigo直播 @@ -2094,4 +2104,4 @@ if __name__ == '__main__': # print(get_liveme_stream_url(room_url, proxy_addr='')) # 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_showroom_stream_data(room_url, proxy_addr='')) \ No newline at end of file