From c7e3cf47ce55d0c8792d24ad83110a2e8e9ea8d7 Mon Sep 17 00:00:00 2001 From: Hmily <114978440+ihmily@users.noreply.github.com> Date: Tue, 12 Aug 2025 16:11:36 +0800 Subject: [PATCH] fix: update twitcast live parse (#1177) --- main.py | 4 +++- src/spider.py | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 6878e4f..b763160 100644 --- a/main.py +++ b/main.py @@ -721,7 +721,7 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None: elif record_url.find("twitcasting.tv/") > -1: platform = 'TwitCasting' with semaphore: - port_info = asyncio.run(spider.get_twitcasting_stream_url( + json_data = asyncio.run(spider.get_twitcasting_stream_url( url=record_url, proxy_addr=proxy_address, cookies=twitcasting_cookie, @@ -729,6 +729,8 @@ def start_record(url_data: tuple, count_variable: int = -1) -> None: username=twitcasting_username, password=twitcasting_password )) + port_info = asyncio.run(stream.get_stream_url(json_data, record_quality, spec=False)) + if port_info and port_info.get('new_cookies'): utils.update_config( file_path=config_file, section='Cookie', key='twitcasting_cookie', diff --git a/src/spider.py b/src/spider.py index d0aaed5..036682e 100644 --- a/src/spider.py +++ b/src/spider.py @@ -1758,7 +1758,7 @@ async def get_twitcasting_stream_url( "configuration file is correct") print("TwitCasting login successful! Starting to fetch data...") headers['Cookie'] = new_cookie - anchor_name, live_status, live_title = get_data(headers) + anchor_name, live_status, live_title = await get_data(headers) except AttributeError: print("Failed to retrieve TwitCasting data, attempting to log in...") new_cookie = await login_twitcasting( @@ -1772,8 +1772,17 @@ async def get_twitcasting_stream_url( result["anchor_name"] = anchor_name if live_status == 'true': - play_url = f'https://twitcasting.tv/{anchor_id}/metastream.m3u8/?video=1&mode=source' - result |= {'title': live_title, 'is_live': True, "m3u8_url": play_url, "record_url": play_url} + url_streamserver = f"https://twitcasting.tv/streamserver.php?target={anchor_id}&mode=client&player=pc_web" + stream_data = await async_req(url_streamserver, proxy_addr=proxy_addr, headers=headers) + json_data = json.loads(stream_data) + if not json_data.get('tc-hls') or not json_data['tc-hls'].get("streams"): + raise RuntimeError("No m3u8_url,please check the url") + + stream_dict = json_data['tc-hls']["streams"] + quality_order = {"high": 0, "medium": 1, "low": 2} + sorted_streams = sorted(stream_dict.items(), key=lambda item: quality_order[item[0]]) + play_url_list = [url for quality, url in sorted_streams] + result |= {'title': live_title, 'is_live': True, "play_url_list": play_url_list} result['new_cookies'] = new_cookie return result @@ -3221,4 +3230,4 @@ async def get_picarto_stream_url(url: str, proxy_addr: OptionalStr = None, cooki title = json_data['channel']['title'] m3u8_url = f"https://1-edge1-us-newyork.picarto.tv/stream/hls/golive+{anchor_name}/index.m3u8" result |= {'is_live': True, 'title': title, 'm3u8_url': m3u8_url, 'record_url': m3u8_url} - return result + return result \ No newline at end of file