[英]Download Video from URL without opening in chrome browser
I have registered for a course that has roughly 150 videos.我注册了一个包含大约 150 个视频的课程。
What I have done Uptil NOW:我所做的直到现在:
There is no download button available right now.目前没有可用的下载按钮。 In order to get the URL of each video file, I have created the script which I run through Console as below:
为了获取每个视频文件的 URL,我创建了通过控制台运行的脚本,如下所示:
The site where I am watching these videos is different than the xxxxx marked site.
我正在观看这些视频的网站与带有 xxxxx 标记的网站不同。 eg I am watching on linkedin learning and video is on lynda,etc.
例如,我在 linkedin learning 上观看视频,而视频在 lynda 等上。
console.log(("<h2>"+ document.title)+"</h2>"
+
"<a href=\""+document.getElementsByClassName("video-tech")[0].getAttribute("src")+"> click here </a>");
document.getElementsByClassName("video-next-button")[0].click();
an example of output from above code is:上面代码的输出示例是:
<h2>Overview of QGIS features: Learning QGIS (2015)</h2>
<a href="https://files3.xxxxx.com/secure/courses/383524/VBR_MP4h264_main_SD/383524_01_01_XR15_Overview.mp4?V0lIWk4afWPs3ejN5lxsCi1SIkGKYcNR_F7ijKuQhDmS1sYUK7Ps5TYBcV-MHzdVTujT5p03HP10F_kqzhwhqi38fhOAPnNJz-dMyvA2-YIpBOI-wGtuOjItlVbRUDn6QUWpwe1sRoAl__IA1zmJn3gPvC7Fu926GViqVdLa3oLB0mxRGa7i> click here </a>
I have replaced domain name with xxxxx
我已经用xxxxx替换了域名
This way I can get cover all videos without clicking next (I would like to know if I can automate this process by using some timeout techniques as well) each of this link, when clicked, chrome window looks like below:这样我就可以在不点击下一步的情况下覆盖所有视频(我想知道我是否可以通过使用一些超时技术来自动化这个过程)每个链接,当点击时,chrome 窗口如下所示:
this way after clicking 3dots -> Download, I can save video individually.
这样点击 3dots -> 下载后,我可以单独保存视频。
What I want: Method to save all videos without the need to open individually.我想要的是:无需单独打开即可保存所有视频的方法。
To begin with, fetching and saving large binary files is possible when:首先,在以下情况下可以获取和保存大型二进制文件:
Okay, this would reason why your anchor attempt did not work, in fact, accessing the host's network from your localhost will deny you from accessing the resource's content unless the host server's CORS support is enabled which is unlikely.好的,这就是为什么您的锚点尝试不起作用的原因,事实上,从您的本地主机访问主机的网络将拒绝您访问资源的内容,除非启用了主机服务器的 CORS 支持,这不太可能。
Alternatively, this will leave us with the other two options, accessing from the same site-origin in particular due to its simplicity, the strategy lies in executing the fetching/saving script from the browser itself, thus, the host server will be gentle with the requests, since they are very similar to the ones coming from the same site.或者,这将留给我们其他两个选项,特别是由于它的简单性,从同一站点来源访问,策略在于从浏览器本身执行获取/保存脚本,因此,主机服务器将对请求,因为它们与来自同一站点的请求非常相似。
const downloadVideos = (videos, marker) => {
// it's important to throttle between requests to dodge performance or network issues
const throttleTime = 10000; // in milliseconds; adjust it to suit your hardware/network capabilities
const domain = 'https://www.sample-videos.com'; // site's domain
if (marker < videos.length) {
console.log(`Download initiated for video ${videos[marker].name} @ marker:${marker}`);
const anchorElement = document.createElement('a');
anchorElement.setAttribute('href', `${domain}${videos[marker].src}`);
anchorElement.setAttribute('download', videos[marker].name);
document.body.appendChild(anchorElement);
// trigger download manually
anchorElement.click();
anchorElement.remove();
marker += 1;
setTimeout(downloadVideos, throttleTime, videos, marker);
}
};
// assuming all videos are stored in an array, each video must have 'src' and 'name' attributes
const videos = [
{ src: '/video123/mp4/480/big_buck_bunny_480p_30mb.mp4', name: 'video_480p.mp4' },
{ src: '/video123/mp4/720/big_buck_bunny_720p_1mb.mp4', name: 'video_720p.mp4' }
];
// fireup
downloadVideos(videos, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.