今天想下载 IG 的一个视频, 于是打开了网页端, 找到视频标签, 查看是 blob, 于是去 Network 里找 m3u8, 但是没有找到.
测试链接: https://www.instagram.com/reel/CdYOo_QIB5L/
video 标签:
<video class="tWeCl" crossorigin="anonymous" playsinline="" poster="https://scontent-hkt1-2.cdninstagram.com/v/t51.2885-15/280525371_399280442062025_5345542004741217395_n.jpg" preload="none" type="video/mp4" src="blob:https://www.instagram.com/4feb10a9-7a9d-4d3c-b63a-6773a391bded" loop="" style="display: block;"></video>
于是就很好奇, 查看了一下, 它使用分段的 mp4 进行拼接成的视频, 视频链接如下:
links = [
'https://scontent-hkt1-2.cdninstagram.com/v/t66.30100-16/48765482_566184564823119_7249730986057316274_n.mp4?_nc_ht=scontent-hkt1-2.cdninstagram.com&_nc_cat=1&_nc_ohc=4Ba61mlOYE4AX9Ym6rG&edm=APfKNqwBAAAA&ccb=7-4&oh=00_AT-ddAJEjKnOOOGslcGOVkxctcfcao29aLwNDjjWSC7d5g&oe=627D7BBA&_nc_sid=74f7ba&bytestart=0&byteend=782',
'https://scontent-hkt1-2.cdninstagram.com/v/t66.30100-16/48765482_566184564823119_7249730986057316274_n.mp4?_nc_ht=scontent-hkt1-2.cdninstagram.com&_nc_cat=1&_nc_ohc=4Ba61mlOYE4AX9Ym6rG&edm=APfKNqwBAAAA&ccb=7-4&oh=00_AT-ddAJEjKnOOOGslcGOVkxctcfcao29aLwNDjjWSC7d5g&oe=627D7BBA&_nc_sid=74f7ba&bytestart=783&byteend=970',
'https://scontent-hkt1-2.cdninstagram.com/v/t66.30100-16/48765482_566184564823119_7249730986057316274_n.mp4?_nc_ht=scontent-hkt1-2.cdninstagram.com&_nc_cat=1&_nc_ohc=4Ba61mlOYE4AX9Ym6rG&edm=APfKNqwBAAAA&ccb=7-4&oh=00_AT-ddAJEjKnOOOGslcGOVkxctcfcao29aLwNDjjWSC7d5g&oe=627D7BBA&_nc_sid=74f7ba&bytestart=971&byteend=22557',
'https://scontent-hkt1-2.cdninstagram.com/v/t66.30100-16/48765482_566184564823119_7249730986057316274_n.mp4?_nc_ht=scontent-hkt1-2.cdninstagram.com&_nc_cat=1&_nc_ohc=4Ba61mlOYE4AX9Ym6rG&edm=APfKNqwBAAAA&ccb=7-4&oh=00_AT-ddAJEjKnOOOGslcGOVkxctcfcao29aLwNDjjWSC7d5g&oe=627D7BBA&_nc_sid=74f7ba&bytestart=22558&byteend=161856',
'https://scontent-hkt1-2.cdninstagram.com/v/t66.30100-16/48765482_566184564823119_7249730986057316274_n.mp4?_nc_ht=scontent-hkt1-2.cdninstagram.com&_nc_cat=1&_nc_ohc=4Ba61mlOYE4AX9Ym6rG&edm=APfKNqwBAAAA&ccb=7-4&oh=00_AT-ddAJEjKnOOOGslcGOVkxctcfcao29aLwNDjjWSC7d5g&oe=627D7BBA&_nc_sid=74f7ba&bytestart=161857&byteend=304637',
];
于是自己写了下面这段代码, 手动拼接然后进行下载:
var blobs = await Promise.all(links.map(async link=> {
return await fetch(link).then(r=>r.blob())
}));
var combinedVideoBlob = blobs.reduce((a, b) => new Blob([a, b], { type: 'video/mp4' }));
var downloadA = document.createElement("a");
downloadA.download = "a.mp4";
downloadA.href = window.webkitURL.createObjectURL(combinedVideoBlob);
downloadA.click();
最终下载成功, 但是视频只有声音没有图像.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.