mirror of
https://github.com/ihmily/DouyinLiveRecorder.git
synced 2025-12-26 05:48:32 +08:00
fix: update twitcast live parse (#1177)
This commit is contained in:
parent
199186fb09
commit
c7e3cf47ce
4
main.py
4
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',
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user