mirror of
https://github.com/ihmily/DouyinLiveRecorder.git
synced 2025-12-26 05:48:32 +08:00
fix: add real douyu room id fetch
This commit is contained in:
parent
5369ff4ac2
commit
3d26bed37f
5
main.py
5
main.py
@ -164,7 +164,7 @@ def display_info():
|
||||
def update_file(file_path: str, old_str: str, new_str: str, start_str: str = None):
|
||||
# 如果待更新的new_str 和 已有的 old_str 没区别,并且 不需要使用注释(start_str),则直接返回
|
||||
if old_str == new_str and start_str is None:
|
||||
return
|
||||
return
|
||||
with file_update_lock:
|
||||
file_data = ""
|
||||
with open(file_path, "r", encoding="utf-8-sig") as f:
|
||||
@ -754,7 +754,8 @@ def start_record(url_data: tuple, count_variable: int = -1):
|
||||
elif record_url.find("https://www.douyu.com/") > -1:
|
||||
platform = '斗鱼直播'
|
||||
with semaphore:
|
||||
json_data = get_douyu_info_data(url=record_url, proxy_addr=proxy_address)
|
||||
json_data = get_douyu_info_data(
|
||||
url=record_url, proxy_addr=proxy_address, cookies=douyu_cookie)
|
||||
port_info = get_douyu_stream_url(
|
||||
json_data, proxy_address=proxy_address, cookies=douyu_cookie,
|
||||
video_quality=record_quality
|
||||
|
||||
20
spider.py
20
spider.py
@ -490,16 +490,26 @@ def get_token_js(rid: str, did: str, proxy_addr: Union[str, None] = None) -> Uni
|
||||
|
||||
|
||||
@trace_error_decorator
|
||||
def get_douyu_info_data(url: str, proxy_addr: Union[str, None] = None) -> Dict[str, Any]:
|
||||
def get_douyu_info_data(url: str, proxy_addr: Union[str, None] = None, cookies: Union[str, None] = None) -> Dict[str, Any]:
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Linux; Android 11; SAMSUNG SM-G973U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/14.2 Chrome/87.0.4280.141 Mobile Safari/537.36',
|
||||
'Referer': 'https://m.douyu.com/3125893?rid=3125893&dyshid=0-96003918aa5365bc6dcb4933000316p1&dyshci=181',
|
||||
'Cookie': 'dy_did=413b835d2ae00270f0c69f6400031601; acf_did=413b835d2ae00270f0c69f6400031601; Hm_lvt_e99aee90ec1b2106afe7ec3b199020a7=1692068308,1694003758; m_did=96003918aa5365bc6dcb4933000316p1; dy_teen_mode=%7B%22uid%22%3A%22472647365%22%2C%22status%22%3A0%2C%22birthday%22%3A%22%22%2C%22password%22%3A%22%22%7D; PHPSESSID=td59qi2fu2gepngb8mlehbeme3; acf_auth=94fc9s%2FeNj%2BKlpU%2Br8tZC3Jo9sZ0wz9ClcHQ1akL2Nhb6ZyCmfjVWSlR3LFFPuePWHRAMo0dt9vPSCoezkFPOeNy4mYcdVOM1a8CbW0ZAee4ipyNB%2Bflr58; dy_auth=bec5yzM8bUFYe%2FnVAjmUAljyrsX%2FcwRW%2FyMHaoArYb5qi8FS9tWR%2B96iCzSnmAryLOjB3Qbeu%2BBD42clnI7CR9vNAo9mva5HyyL41HGsbksx1tEYFOEwxSI; wan_auth37wan=5fd69ed5b27fGM%2FGoswWwDo%2BL%2FRMtnEa4Ix9a%2FsH26qF0sR4iddKMqfnPIhgfHZUqkAk%2FA1d8TX%2B6F7SNp7l6buIxAVf3t9YxmSso8bvHY0%2Fa6RUiv8; acf_uid=472647365; acf_username=472647365; acf_nickname=%E7%94%A8%E6%88%B776576662; acf_own_room=0; acf_groupid=1; acf_phonestatus=1; acf_avatar=https%3A%2F%2Fapic.douyucdn.cn%2Fupload%2Favatar%2Fdefault%2F24_; acf_ct=0; acf_ltkid=25305099; acf_biz=1; acf_stk=90754f8ed18f0c24; Hm_lpvt_e99aee90ec1b2106afe7ec3b199020a7=1694003778'
|
||||
}
|
||||
if cookies:
|
||||
headers['Cookie'] = cookies
|
||||
|
||||
match_rid = re.search('rid=(.*?)(?=&|$)', url)
|
||||
if match_rid:
|
||||
rid = match_rid.group(1)
|
||||
else:
|
||||
rid = re.search('douyu.com/(.*?)(?=\?|$)', url).group(1)
|
||||
headers = {
|
||||
'referer': 'https://www.douyu.com/7644887?dyshid=0-40f7c4a06aae9dc5bede316000031701&dyshci=181',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0',
|
||||
}
|
||||
html_str = get_req(url=f'https://m.douyu.com/{rid}', proxy_addr=proxy_addr, headers=headers)
|
||||
json_str = re.findall('<script id="vike_pageContext" type="application/json">(.*?)</script>', html_str)[0]
|
||||
json_data = json.loads(json_str)
|
||||
rid = json_data['pageProps']['room']['roomInfo']['roomInfo']['rid']
|
||||
|
||||
headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 Edg/121.0.0.0'
|
||||
url2 = f'https://www.douyu.com/betard/{rid}'
|
||||
json_str = get_req(url=url2, proxy_addr=proxy_addr, headers=headers)
|
||||
json_data = json.loads(json_str)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user