forked from xiyaowong/spiders
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsohuTV.py
More file actions
61 lines (51 loc) · 1.73 KB
/
Copy pathsohuTV.py
File metadata and controls
61 lines (51 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import re
import requests
def get(url: str) -> dict:
"""
title、videoName、videos
"""
data = {}
session = requests.Session()
ERROR = {"msg": "获取失败"}
headers = {
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"
}
videoInfo_url = "https://my.tv.sohu.com/play/videonew.do"
playInfo_url = "https://data.vod.itc.cn/ip"
with session.get(url, headers=headers, timeout=10) as rep_html:
if rep_html.status_code != 200:
return ERROR
vid = re.findall(r",vid: '(\d+)'", rep_html.text)
if not vid:
return ERROR
vid = vid[0]
videoInfo_params = {
"vid": vid,
"ver": 31,
"ssl": 1,
"referer": url
}
with session.get(videoInfo_url, params=videoInfo_params, timeout=10) as videoInfo_rep:
if videoInfo_rep.status_code != 200:
return ERROR
videoInfo = videoInfo_rep.json()["data"]
tvName = videoInfo["tvName"]
data["title"] = data["videoName"] = tvName
video_path = videoInfo["su"][0]
key = videoInfo["hc"][0] if videoInfo.get("hc") else videoInfo["ck"][0]
if not video_path or not key:
return ERROR
playInfo_params = {
"new": video_path,
"num": 1,
"key": key,
}
with session.get(playInfo_url, params=playInfo_params, timeout=10) as playInfo_rep:
if playInfo_rep.status_code != 200:
return ERROR
play_url = playInfo_rep.json()["servers"][0]["url"]
data["videos"] = [play_url]
return data
if __name__ == "__main__":
url = input("url: ")
print(get(url))