import json
import requests
import os
url=‘‘;
func_list=‘/getCurriculum?page=1&limit=30&userId&majorname_id=‘
func_details=‘/getCurriculumDetail?id=108&userId‘
response=requests.get(url+func_list)
js=json.loads(response.text)
path="/usr/local/var/python/zj/PythonApplication1/PythonApplication1/videos/"
for tes in js[‘data‘]:
upath=path+tes[‘name‘]
url=""
isExists=os.path.exists(upath)
if not isExists:
os.mkdir(upath)
write=upath+‘/video.txt‘
for tes1 in tes[‘video‘]:
url+=tes1[‘title‘]+"|"+tes1[‘video_url‘]+"\r\n"
with open(write, ‘w‘,encoding=‘utf-8‘) as f:
f.write(url)
import os
import urllib.request
from urllib.parse import urlparse, parse_qs, parse_qsl
path="/usr/local/var/python/zj/PythonApplication1/PythonApplication1/videos/"
file_list_er=os.listdir(path)
def cbk(a,b,c):
‘‘‘回调函数
@a:已经下载的数据块
@b:数据块的大小
@c:远程文件的大小
‘‘‘
per=100.0*a*b/c
if per>100:
per=100
print(‘%.2f%%‘ % per)
def geturl(filenames):
with open(filenames, "r") as f: # 打开文件
results = f.read() # 读取文件
data = results.split(‘\n‘)
return data
for tes in file_list_er:
pa=path+tes+"/video.txt"
dat2=geturl(pa)
for ta in dat2:
rea=ta.split(‘|‘)
if len(rea)>1:
if os.path.exists(path+tes+"/"+rea[0]+‘.mp4‘):
continue
urllib.request.urlretrieve(rea[1],path+tes+"/"+rea[0]+‘.mp4‘,cbk)
原文:https://www.cnblogs.com/mengluo/p/14179091.html