-
Notifications
You must be signed in to change notification settings - Fork 1
/
videoDownloader.py
168 lines (140 loc) · 5.7 KB
/
videoDownloader.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import requests
import re
import sys
import getopt
opts, args = getopt.getopt(sys.argv[1:], '-h-g-d:-n:', ['help','generate', 'dir=', 'name='])
def GetInfo(Vid):
print("正在获取课程信息...")
data={'callCount':1,
'scriptSessionId':'${scriptSessionId}190',
'c0-scriptName':'PlanNewBean',
'c0-methodName':'getPlanCourseDetail',
'c0-id':'0',
'c0-param0':'string:'+Vid,
'c0-param1':'number:0',
'c0-param2':'null:null',
'batchId':"1506324769538"}
html=requests.post('http://study.163.com/dwr/call/plaincall/PlanNewBean.getPlanCourseDetail.dwr?1506324769538',data=data,headers=headers)
#s16.lessonName="\u8BBE\u7F6E\u5750\u6807\u8F741";s16.leve
LessonName=re.findall(r's\w*?\.id=(.*?);.*?s(\w*?)\.lessonName="(.*?)";',html.text)
return LessonName
def GetVideoUrl(LessonName, Vid):
print("正在获取课件信息:")
Lists = []
for i in range(0,len(LessonName)):
Vnum = LessonName[i][0]
VName = LessonName[i][2].encode('utf-8').decode('unicode_escape','ignore')
print(VName)
data={'callCount':'1',
'scriptSessionId':'${scriptSessionId}190',
'c0-scriptName':'LessonLearnBean',
'c0-methodName':'getVideoLearnInfo',
'c0-id':'0',
'c0-param0':'string:'+ Vnum,
'c0-param1':'string:'+ Vid,
'batchId':'1506324769538'}
video=requests.post("http://study.163.com/dwr/call/plaincall/LessonLearnBean.getVideoLearnInfo.dwr?1506327358812",data=data,headers=headers)
try:
Vurl = re.findall(r'flvHdUrl="(.*?)"',video.text)[0]
except:
pass
Value = [VName,Vurl]
Lists.append(Value)
return Lists
def MakeTxt(Lists):
print("正在生成视频地址...")
AllLinks = ""
for i in range(0,len(Lists)):
# Lists[i][1] = Lists[i][1].replace("http://","")
Links = '<div class="down"><a href="'+Lists[i][1]+'">'+Lists[i][0]+'</a></div>'+"\n"
AllLinks = AllLinks + Links
filename = Vid+".html"
with open(filename,'w',encoding='utf-8') as f:
f.write("""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="x-ua-compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>视频下载页面</title>
<link rel="stylesheet" type="text/css" href="http://www.lz1y.cn/css/download.css">
</head>
<body>
<div class="download">
<div class="head">
<div class="logo"><img src="http://www.lz1y.cn/wordpress/wp-content/uploads/2017/06/cropped-C977239D-7B8E-2709-E8CB-A03DD1E6FAF9.png@236w_0e_1l-180x180.png" alt="logo"></div>
<div class="logo-title">网易云课堂视频下载 <br /> Author: Lz1y</div>
</div><br/><br/><br/><br/><br/><br/><br/>
<div class="down-column">
<div class="down1"><a href="">课程下载</a></div>
"""+AllLinks+"""
</div>
<div class="foot"><p><a href="http://www.lz1y.cn/wordpress" target="_blank"><font color="black">Lz1y'Blog | Coding My world</a></p>
</div>
</div>
</body>
</html>
""")
def MakeHtml(Lists):
print(Lists[i][1])
AllLinks = ""
filename = Vid + "_name.txt"
for i in range(0,len(Lists)):
Links = '<div class ="down"><font color="black"><a href="'+Lists[i][1]+'"> '+Lists[i][0]+' </font></a></div>'
AllLinks = AllLinks + Links
with open(filename,'a',encoding='utf-8') as f:
f.write(Lists[i][0])
html = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>视频下载页面</title>
<link rel="stylesheet" type="text/css" href="http://www.lz1y.cn/css/download.css">
</head>
<body>
<div class="app-download">
<div class="logo"><img src="//www.lz1y.cn/wordpress/wp-content/uploads/2017/06/cropped-C977239D-7B8E-2709-E8CB-A03DD1E6FAF9.png@236w_0e_1l-180x180.png" alt="logo"></div>
<div class="logo-title">网易云课堂视频下载 <br /> Author: Lz1y</div><br>"""+AllLinks+"""
<br><p><a href="http://www.lz1y.cn/wordpress" target="_blank"><font color="black">Lz1y'Blog | Coding My world</a></p>
</div>
</body>
</html>
"""
filename = Vid+".html"
with open(filename,'w',encoding='utf-8') as f:
f.write(html)
if __name__ == "__main__":
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"}
print("网易云课堂视频下载工具 V1.2 beta1")
print("Author:Lz1y")
print("Blog:http://www.lz1y.cn/wordpress/")
print("\033[0;31mTips:如何获取CourseId")
print(" example:一个课程的网址是 http://study.163.com/course/introduction.htm?courseId=320022")
print(" 320022就是CourseId,输入到下方即可\033[0m!")
Vid = input("\n请输入CourseId:\n")
LessonName = GetInfo(Vid)
Lists = GetVideoUrl(LessonName, Vid)
MakeTxt(Lists)
"""
for opt_name, opt_value in opts:
if opt_name in ('-d', '--dir'):
dir = opt_value
if opt_name in ('-n', '--name'):
name = opt_value
with open(name,'w',encoding='utf-8') as f:
names = f.readlines()
files = os.listdir(dir)
for i in range(0,len(files)):
os.rename(dir+"/"+files[i],dir+"/"+names[i])
if opt_name in ('-g','--generate'):
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0"}
Vid = input("请输入CourseId:\n")
LessonName = GetInfo(Vid)
Lists = GetVideoUrl(LessonName, Vid)
MakeTxt(Lists)
if opt_name in ('-h', '--help'):
print("-g --generate 生成web页面")
# MakeHtml(Lists)
"""