forked from hexianglong/o.nmgjg.com.cn
refactor(videos): 优化视频下载功能
- 移除了使用 fetch API 下载视频的复杂逻辑 - 采用直接创建 <a> 元素并触发点击的方法简化下载过程 - 修改了下载文件名的生成逻辑,使用 URL 的最后一部分作为文件名
This commit is contained in:
@@ -98,18 +98,12 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
function downloadVideo() {
|
function downloadVideo() {
|
||||||
fetch(videoUrl)
|
var link = document.createElement('a');
|
||||||
.then(response => response.blob())
|
link.href = videoUrl;
|
||||||
.then(blob => {
|
link.download = videoUrl.split('/').pop();
|
||||||
const link = document.createElement('a');
|
|
||||||
link.href = URL.createObjectURL(blob);
|
|
||||||
link.download = videoTitle + '.mp4'; // 设置下载文件名
|
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
URL.revokeObjectURL(link.href);
|
|
||||||
})
|
|
||||||
.catch(error => console.error('Error downloading the video:', error));
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user