最近突然有了个需求,需要下载钉钉回放视频。
钉钉回放管理员默认设置不能下载,于是写了个小脚本用于视频下载。
python 库
1
| beautifulsoup4、mitmproxy、python-ffmpeg
|
mitmproxy 安装https证书,钉钉设置本地代理,启动脚本,依次点击需要下载的视频就好了。
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
| from mitmproxy import ctx from bs4 import BeautifulSoup from threading import Thread import ffmpeg import re
data = {}
def downloadvideo(url, keyname): filename = data.get(keyname) stream = ffmpeg.input(url) stream = ffmpeg.output(stream, filename + '.mp4') ffmpeg.run(stream)
def request(flow): global key_tmp global video request = flow.request info = ctx.log.info url = request.url path = request.path info(request.host) if request.host == "h5.dingtalk.com": pattern = re.compile("liveUuid=(.*)&") re_liveUuid = pattern.findall(path) re_liveUuid = "".join(re_liveUuid) key_tmp = re_liveUuid info(re_liveUuid) if key_tmp: re_live_hp = re.search("live_hp/" + key_tmp + "_merge.m3u8", path) if re_live_hp: video = url t1 = Thread(target=downloadvideo, args=(video, key_tmp)) t1.start()
def response(flow): global data info = ctx.log.info response = flow.response soup = BeautifulSoup(response.text, 'html.parser') pattern = re.compile("<meta content=\"(.*)\" property=\"og:title\"") meta = soup.find_all(attrs={"property": "og:title"}) title = pattern.findall(str(meta)) if title: title = "".join(title) tmp = {key_tmp: title} data.update(tmp) info(data)
|
