#函数名必须这样写 这是mitmdump规则
def response(flow):
if 'aweme/v1/aweme/post/?' in flow.request.url:
for video in json.loads(flow.response.text)['aweme_list']:
video_info={}
video_info['date']=custom_time(video['create_time']) #发布时间
video_info['name']=video_info['date'] if video['desc']=='' else restr(video['desc']) #视频说明
video_info['id']=video['aweme_id'] #视频ID
video_info['user']=restr(video['author']['nickname']) #作者
filename='d:\\video\\'+video_info['user']+'\\'+video_info['name']+'\\'
is_exists = os.path.exists(filename)
if not is_exists:
os.makedirs(filename)
else:
filename='d:\\video\\'+video_info['user']+'\\'+video_info['name']+video_info['id']+'\\'
os.makedirs(filename)
imgurl=video['video']['cover']['url_list'] #图片地址
if len(imgurl)>0:
video_info['imgurl']=imgurl[0]
t = threading.Thread(target=down, args=(imgurl[0],filename+video_info['name']+'.jpg'))
t.setDaemon(True)
t.start()
downurl=video['video']['play_addr']['url_list'] #无水印视频地址
if len(downurl)>0:
video_info['downurl']=downurl[0]
k = threading.Thread(target=down2, args=(downurl[0],filename+video_info['name']+'.mp4',filename))
k.setDaemon(True)
k.start()
print(video_info)