钉钉视频下载-2023年9月py代码

文章参考

https://www.bilibili.com/read/cv20472358/
https://blog.csdn.net/weixin_43594279/article/details/107444501
https://zyy0911.github.io/2022/01/12/%E9%92%89%E9%92%89%E7%9B%B4%E6%92%AD%E5%9B%9E%E6%94%BE%E4%B8%8B%E8%BD%BD.html#h-%E6%9C%AC%E6%95%99%E7%A8%8B%E4%BB%85%E4%BE%9B%E5%AD%A6%E4%B9%A0%E7%A0%94%E7%A9%B6%E4%BD%BF%E7%94%A8
https://github.com/Tencent/vConsole

代码参考

https://blog.csdn.net/Caiqiudan/article/details/109190522
https://wenku.csdn.net/answer/00a8bbd92b934f51a46f83da9dcd17eb

使用的js

https://cdn.bootcss.com/vConsole/3.14.0/vconsole.min.js
  static function OnBeforeResponse(oSession: Session) {
    
    
        if (m_Hide304s && oSession.responseCode == 304) {
    
    
            oSession["ui-hide"] = "true";
        }
        var sToInsert = "<script src='https://cdn.bootcss.com/vConsole/3.14.0/vconsole.min.js'></script><script>var vConsole = new VConsole();</script>"
        oSession.utilDecodeResponse();
        oSession.utilReplaceOnceInResponse('</head>', sToInsert + '</head>', 0);

    }

mm.m3u8 信息

#EXTM3U
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-TARGETDURATION:34
#EXTINF:32.458,
9145a060-e7be-4457-b460-ecd9ec9d2c31/1.ts?auth_key=1695430249-0-0-8def38160d814974e4748d24f23d9029
#EXTINF:32.000,
9145a060-e7be-4457-b460-ecd9ec9d2c31/2.ts?auth_key=1695430249-0-0-5b4457330b144a9452b5d8005c387a3a
#EXTINF:32.833,
9145a060-e7be-4457-b460-ecd9ec9d2c31/3.ts?auth_key=1695430249-0-0-e734adc7cce7e0e1dad8d6fe062ca5ce
#EXTINF:30.334,
9145a060-e7be-4457-b460-ecd9ec9d2c31/4.ts?auth_key=1695430249-0-0-a8d02d9fb046d35f759df8154547e21e
#EXTINF:32.000,
9145a060-e7be-4457-b460-ecd9ec9d2c31/5.ts?auth_key=1695430249-0-0-29ce4961af88d5b2d324ba188b032e74
#EXTINF:32.000,
9145a060-e7be-4457-b460-ecd9ec9d2c31/6.ts?auth_key=1695430249-0-0-6542f8e9bd15b732ee4eb626b54cc274
#EXTINF:32.000,
9145a060-e7be-4457-b460-ecd9ec9d2c31/7.ts?auth_key=1695430249-0-0-cfbef11865f88c5a5e91e0c6f7706699
#EXTINF:32.000,
9145a060-e7be-4457-b460-ecd9ec9d2c31/8.ts?auth_key=1695430249-0-0-5f484c8e517b604eb8a6fb26f19f3f43
#EXTINF:32.000,
9145a060-e7be-4457-b460-ecd9ec9d2c31/9.ts?auth_key=1695430249-0-0-86905ee3c5baecbdc2128be0329d0270

python代码

import subprocess
import requests
import os
import re

# my_list = ["1.ts","2.ts"]
my_list = []
patternnum = r'(\b\d{1,3}\.ts\b)'
# m3u8 = "https://dtliving-sh.dingtalk.com/live_hp/xxx_normal.m3u8?auth_key=1695468415-0-0-6b2fbe41c139bbbc549ce3d83428f4d6"
video_file_path = os.getcwd() + r'\ddvideo'
# 创建一个名叫video的文件夹用来存放一堆ts视频
if os.path.exists(video_file_path) == False:
    os.mkdir(video_file_path)
with open("mm.m3u8", 'r') as f:  # 读取网址文件
    for line in f:  # 遍历文件里的网址
        line = line.replace('\n', '')
        match = re.search(patternnum, line)
        if match:
            url = f'https://dtliving-sz.dingtalk.com/live_hp/{line}'  # 注意用.rstrip()方法去掉\n这个字符,如果时打印出来时发现不了这个问题的
            r2 = requests.get(url, verify=False)  # 爬取数据
            my_list.append(match.group(1))
            with open(fr'.\ddvideo\{match.group(1)}', 'wb', ) as f:  # 保存到video文件夹里的ts文件,wb:覆盖写入
                f.write(r2.content)  # 写入数据
            print(url)


# 再cmd端用ffmpeg执行ts合并为mp4命令
def concat_video():
    print('合并视频中...')
    # 输入.ts文件的路径和输出.mp4文件的路径
    output_file = 'output.mp4'
    # 切换到指定目录
    os.chdir('ddvideo')
    # 构建FFmpeg命令
    ffmpeg_cmd = ['ffmpeg', '-y', '-i', 'concat:' + '|'.join(my_list), '-c', 'copy', output_file]
    # 执行FFmpeg命令
    result = subprocess.run(ffmpeg_cmd, capture_output=True, text=True)
    # 打印命令的输出结果
    print(result.stdout)
    print(result.stderr)
    print('视频合并完成...')

if __name__ == '__main__':
    concat_video()

猜你喜欢

转载自blog.csdn.net/qq_41638872/article/details/132858647