-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
抖音好像不行啦,获取real url失败 #447
Comments
class DouYin:
|
谢谢,搞定。 |
上面的又不行了,最新有效代码如下: import requests
import re
import json
class Douyin:
def __init__(self, rid, stream):
self.Rid = rid
self.Stream = stream
def get_douyin_url(self):
live_url = f"https://live.douyin.com/{self.Rid}"
session = requests.Session()
# Send initial request to obtain __ac_nonce
headers = {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36",
"Upgrade-Insecure-Requests": "1",
}
oresp = session.get(live_url, headers=headers)
oresp.close()
# Extract __ac_nonce from Set-Cookie header
ac_nonce_match = re.search(r'(?i)__ac_nonce=(.*?);', oresp.headers.get("Set-Cookie", ""))
if ac_nonce_match:
ac_nonce = ac_nonce_match.group(1)
else:
return None
# Set __ac_nonce cookie and send another request
session.cookies.set("__ac_nonce", ac_nonce)
resp = session.get(live_url, headers=headers)
# Extract ttwid from Set-Cookie header
ttwid_match = re.search(r'(?i)ttwid=.*?;', resp.headers.get("Set-Cookie", ""))
if ttwid_match:
ttwid = ttwid_match.group(0)
else:
return None
# Build URL for final request
url = f"https://live.douyin.com/webcast/room/web/enter/?aid=6383&app_name=douyin_web&live_id=1&device_platform=web&language=zh-CN&enter_from=web_live&cookie_enabled=true&screen_width=1728&screen_height=1117&browser_language=zh-CN&browser_platform=MacIntel&browser_name=Chrome&browser_version=116.0.0.0&web_rid={self.Rid}"
headers = {
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
"Cookie": ttwid,
"Accept": "*/*",
"Host": "live.douyin.com",
"Connection": "keep-alive",
}
# Send the final request
ress = session.get(url, headers=headers)
ress.close()
# Parse the JSON response
data = json.loads(ress.text)
status = data.get("data", {}).get("data", [])[0].get("status", 0)
if status != 2:
return None
real_url = ""
stream_data = data.get("data", {}).get("data", [])[0].get("stream_url", {}).get("live_core_sdk_data", {}).get("pull_data", {}).get("stream_data", {})
value = json.loads(stream_data)
if self.Stream == "flv":
real_url = value.get("data", {}).get("origin", {}).get("main", {}).get("flv", "")
elif self.Stream == "hls":
real_url = value.get("data", {}).get("origin", {}).get("main", {}).get("hls", "")
return real_url
def main():
room_url = input("请输入抖音直播间URL: ")
quality = "flv" # 或者根据需要设置hls
# Extract room ID from URL
match = re.search(r'https://live.douyin.com/(\d+)', room_url)
if not match:
return None
room_id = match.group(1)
douyin_obj = Douyin(room_id, quality)
douyin_url = douyin_obj.get_douyin_url()
print(douyin_url)
if __name__ == "__main__":
main() |
@oiuv 手机客户端分享出来的直播链接有办法吗? 像这种:https://v.douyin.com/idSEom1x/
|
大哥 有能获取高画质的吗 |
有效,感谢!@oiuv |
个人觉得应该有两种方案一种在这里 stream_data = data.get("data", {}).get("data", [])[0].get("stream_url", {}).get("live_core_sdk_data", {}).get("pull_data", {}).get("stream_data", {})打印data看看里面有没有分辨率更低的流进行切换,另一种使用opencv读取最后获取的flv流并进行cv2.resize()来强制降低分辨率 |
多谢指导! |
@shixiuhai 你好!再请教一下 |
列举两种替换方案方案一: live_url = "https://live.douyin.com/{}".format(self.Rid) 方案二live_url = "https://live.douyin.com/%s" % self.Rid |
介于gpt是免费的,这类基础语法替换你可以尝试gpt https://chat.openai.com/ 或者文心一言讯飞这些都是可以直接获取答案的 |
@shixiuhai 高手啊!两种方案都有效,感谢你的热心指导! |
@shixiuhai 有没有快手的类似功能的py代码?网上找半天,没找到正常可用的 |
有没有获取非直播间的普通抖音视频实际下载链接的脚本?能选择视频清晰度 |
请输入抖音直播链接或19位room_id:7267533488792980261
room_id 7267533488792980261
获取real url失败
The text was updated successfully, but these errors were encountered: