fix: update twitcast live parse (#1177)

This commit is contained in:
Hmily 2025-08-12 16:11:36 +08:00 committed by GitHub
parent 199186fb09
commit c7e3cf47ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 5 deletions

View File

@ -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',

View File

@ -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