mirror of
https://github.com/ihmily/DouyinLiveRecorder.git
synced 2025-12-26 05:48:32 +08:00
Fix bugs and update dependencies
This commit addresses several issues and updates dependencies related to the video recording and data fetching functionality: - Fix a bug causing recording errors when switching video resolutions on Douyin. - Update the Cookie for mobile authentication on the Kuaishou platform. - Fix an error occurring during data retrieval from TikTok. - Resolve recording issues caused by recent updates on Douyu. Files affected: - main.py: Bug fix related to video resolution switching on Douyin. - spider.py: -Fix Tiktok code error that lead to do not get the stream data. -Update Kuaishou Cookie for mobile authentication. -Fix Douyu parse data.
This commit is contained in:
parent
6f2ab1a9c8
commit
ea87f98bb0
79
main.py
79
main.py
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Author: Hmily
|
Author: Hmily
|
||||||
Github: https://github.com/ihmily
|
GitHub: https://github.com/ihmily
|
||||||
Date: 2023-07-17 23:52:05
|
Date: 2023-07-17 23:52:05
|
||||||
Update: 2023-09-30 00:39:17
|
Update: 2023-10-30 02:31:35
|
||||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||||
Function: Record live stream video.
|
Function: Record live stream video.
|
||||||
"""
|
"""
|
||||||
@ -26,7 +26,7 @@ from web_rid import *
|
|||||||
from msg_push import *
|
from msg_push import *
|
||||||
|
|
||||||
# 版本号
|
# 版本号
|
||||||
version = "v2.0.1"
|
version = "v2.0.2"
|
||||||
platforms = "抖音|Tiktok|快手|虎牙|斗鱼|YY|B站"
|
platforms = "抖音|Tiktok|快手|虎牙|斗鱼|YY|B站"
|
||||||
|
|
||||||
# --------------------------log日志-------------------------------------
|
# --------------------------log日志-------------------------------------
|
||||||
@ -264,23 +264,27 @@ def get_douyin_stream_url(json_data):
|
|||||||
flv_url_list = stream_url['flv_pull_url']
|
flv_url_list = stream_url['flv_pull_url']
|
||||||
m3u8_url_list = stream_url['hls_pull_url_map']
|
m3u8_url_list = stream_url['hls_pull_url_map']
|
||||||
|
|
||||||
video_qualities = {
|
# video_qualities = {
|
||||||
"原画": "FULL_HD1",
|
# "原画": "FULL_HD1",
|
||||||
"蓝光": "FULL_HD1",
|
# "蓝光": "FULL_HD1",
|
||||||
"超清": "HD1",
|
# "超清": "HD1",
|
||||||
"高清": "SD1",
|
# "高清": "SD1",
|
||||||
"标清": "SD2",
|
# "标清": "SD2",
|
||||||
}
|
# }
|
||||||
|
|
||||||
quality_key = video_qualities.get(video_quality)
|
quality_list = list(m3u8_url_list.keys())
|
||||||
if quality_key:
|
while len(quality_list) < 4:
|
||||||
m3u8_url = m3u8_url_list.get(quality_key)
|
quality_list.append(quality_list[-1])
|
||||||
flv_url = flv_url_list.get(quality_key)
|
video_qualities = {"原画": 0, "蓝光": 0, "超清": 1, "高清": 2, "标清": 3}
|
||||||
|
quality_index = video_qualities.get(video_quality)
|
||||||
|
quality_key = quality_list[quality_index]
|
||||||
|
m3u8_url = m3u8_url_list.get(quality_key)
|
||||||
|
flv_url = flv_url_list.get(quality_key)
|
||||||
|
|
||||||
result['m3u8_url'] = m3u8_url
|
result['m3u8_url'] = m3u8_url
|
||||||
result['flv_url'] = flv_url
|
result['flv_url'] = flv_url
|
||||||
result['is_live'] = True
|
result['is_live'] = True
|
||||||
result['record_url'] = m3u8_url # 使用 m3u8 链接进行录制
|
result['record_url'] = m3u8_url # 使用 m3u8 链接进行录制
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -307,24 +311,18 @@ def get_tiktok_stream_url(json_data):
|
|||||||
stream_data = live_room.get('liveRoom', {}).get('streamData', {}).get('pull_data', {}).get('stream_data', '{}')
|
stream_data = live_room.get('liveRoom', {}).get('streamData', {}).get('pull_data', {}).get('stream_data', '{}')
|
||||||
stream_data = json.loads(stream_data).get('data', {})
|
stream_data = json.loads(stream_data).get('data', {})
|
||||||
|
|
||||||
video_qualities = {
|
quality_list = list(stream_data.keys()) # ["origin","uhd","sd","ld"]
|
||||||
"原画": "origin",
|
while len(quality_list) < 4:
|
||||||
"蓝光": "origin",
|
quality_list.append(quality_list[-1])
|
||||||
"超清": "uhd",
|
video_qualities = {"原画": 0,"蓝光": 0,"超清": 1,"高清": 2,"标清": 3}
|
||||||
"高清": "sd",
|
quality_index = video_qualities.get(video_quality)
|
||||||
"标清": "ld",
|
quality_key = quality_list[quality_index]
|
||||||
}
|
video_quality_urls = get_video_quality_url(stream_data, quality_key)
|
||||||
|
result['flv_url'] = video_quality_urls['flv']
|
||||||
quality_key = video_qualities.get(video_quality)
|
result['m3u8_url'] = video_quality_urls['hls']
|
||||||
if quality_key:
|
result['is_live'] = True
|
||||||
video_quality_urls = get_video_quality_url(stream_data,quality_key)
|
result['record_url'] = result['flv_url'] if result['flv_url'] else result['m3u8_url']
|
||||||
result['flv_url'] = video_quality_urls['flv']
|
result['record_url'] = re.sub("only_audio=1", "only_audio=0", result['record_url'])
|
||||||
result['m3u8_url'] = video_quality_urls['hls']
|
|
||||||
result['is_live'] = True
|
|
||||||
if result['m3u8_url']:
|
|
||||||
result['record_url'] = video_quality_urls['hls']
|
|
||||||
else:
|
|
||||||
result['record_url'] = video_quality_urls['flv']
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@ -444,10 +442,11 @@ def get_douyu_stream_url(json_data, cookies):
|
|||||||
rid = str(room_info['rid'])
|
rid = str(room_info['rid'])
|
||||||
rate = video_quality_options.get(video_quality, '0') # 默认为原画
|
rate = video_quality_options.get(video_quality, '0') # 默认为原画
|
||||||
flv_data = get_douyu_stream_data(rid, rate, cookies)
|
flv_data = get_douyu_stream_data(rid, rate, cookies)
|
||||||
flv_url = flv_data['data']['url']
|
flv_url = flv_data['data'].get('url', None)
|
||||||
result['flv_url'] = flv_url
|
if flv_url:
|
||||||
result['is_live'] = True
|
result['flv_url'] = flv_url
|
||||||
result['record_url'] = flv_url # 斗鱼目前只能使用flv视频流录制
|
result['is_live'] = True
|
||||||
|
result['record_url'] = flv_url # 斗鱼目前只能使用flv视频流录制
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
spider.py
11
spider.py
@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Author: Hmily
|
Author: Hmily
|
||||||
Github:https://github.com/ihmily
|
GitHub:https://github.com/ihmily
|
||||||
Date: 2023-07-15 23:15:00
|
Date: 2023-07-15 23:15:00
|
||||||
Update: 2023-09-30 00:39:17
|
Update: 2023-10-30 01:58:23
|
||||||
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
Copyright (c) 2023 by Hmily, All Rights Reserved.
|
||||||
Function: Get live stream data.
|
Function: Get live stream data.
|
||||||
"""
|
"""
|
||||||
@ -72,7 +72,7 @@ def get_tiktok_stream_data(url, proxy_addr=None, cookies=None):
|
|||||||
if cookies:
|
if cookies:
|
||||||
headers['Cookie'] = cookies
|
headers['Cookie'] = cookies
|
||||||
|
|
||||||
if not proxy_addr:
|
if proxy_addr:
|
||||||
proxies = {
|
proxies = {
|
||||||
'http': proxy_addr,
|
'http': proxy_addr,
|
||||||
'https': proxy_addr
|
'https': proxy_addr
|
||||||
@ -123,7 +123,7 @@ def get_kuaishou_stream_data2(url, cookies=None):
|
|||||||
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
|
'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
|
||||||
'Referer': "https://www.kuaishou.com/short-video/3x224rwabjmuc9y?fid=1712760877&cc=share_copylink&followRefer=151&shareMethod=TOKEN&docId=9&kpn=KUAISHOU&subBiz=BROWSE_SLIDE_PHOTO&photoId=3x224rwabjmuc9y&shareId=17144298796566&shareToken=X-6FTMeYTsY97qYL&shareResourceType=PHOTO_OTHER&userId=3xtnuitaz2982eg&shareType=1&et=1_i/2000048330179867715_h3052&shareMode=APP&originShareId=17144298796566&appType=21&shareObjectId=5230086626478274600&shareUrlOpened=0×tamp=1663833792288&utm_source=app_share&utm_medium=app_share&utm_campaign=app_share&location=app_share",
|
'Referer': "https://www.kuaishou.com/short-video/3x224rwabjmuc9y?fid=1712760877&cc=share_copylink&followRefer=151&shareMethod=TOKEN&docId=9&kpn=KUAISHOU&subBiz=BROWSE_SLIDE_PHOTO&photoId=3x224rwabjmuc9y&shareId=17144298796566&shareToken=X-6FTMeYTsY97qYL&shareResourceType=PHOTO_OTHER&userId=3xtnuitaz2982eg&shareType=1&et=1_i/2000048330179867715_h3052&shareMode=APP&originShareId=17144298796566&appType=21&shareObjectId=5230086626478274600&shareUrlOpened=0×tamp=1663833792288&utm_source=app_share&utm_medium=app_share&utm_campaign=app_share&location=app_share",
|
||||||
'content-type': 'application/json',
|
'content-type': 'application/json',
|
||||||
'Cookie': 'did=web_5653f81a4c4c41b6a0bc08e99df82009; didv=1696004011000',
|
'Cookie': 'did=web_e988652e11b545469633396abe85a89f; didv=1696004001000',
|
||||||
}
|
}
|
||||||
if cookies:
|
if cookies:
|
||||||
headers['Cookie'] = cookies
|
headers['Cookie'] = cookies
|
||||||
@ -206,7 +206,8 @@ def get_douyu_info_data(url):
|
|||||||
response = opener.open(req, timeout=15)
|
response = opener.open(req, timeout=15)
|
||||||
|
|
||||||
html_str = response.read().decode('utf-8')
|
html_str = response.read().decode('utf-8')
|
||||||
json_str = re.search('ssr_pageContext" type="application\/json">(.*?)<\/script>', html_str).group(1)
|
json_str = re.search('\<script id\=\"vike_pageContext\" type\=\"application\/json\"\>(.*?)<\/script>',
|
||||||
|
html_str).group(1)
|
||||||
json_data = json.loads(json_str)
|
json_data = json.loads(json_str)
|
||||||
return json_data
|
return json_data
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user