简体   繁体   English

从 URL 下载视频而无需在 chrome 浏览器中打开

[英]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.我想要的是:无需单独打开即可保存所有视频的方法。

Challenge挑战

To begin with, fetching and saving large binary files is possible when:首先,在以下情况下可以获取和保存大型二进制文件:

  • The host server's CORS support is enabled.主机服务器的CORS支持已启用。
  • Accessing the host's network from the same site-origin .从同一个site-origin访问主机的网络。
  • Server-to-Server.服务器到服务器。

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 支持,这不太可能。

Workaround解决方法

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.或者,这将留给我们其他两个选项,特别是由于它的简单性,从同一站点来源访问,策略在于从浏览器本身执行获取/保存脚本,因此,主机服务器将对请求,因为它们与来自同一站点的请求非常相似。

Steps脚步

  1. Go to the site you wish to download the files from (I used https://www.sample-videos.com ).转到您希望从中下载文件的站点(我使用了https://www.sample-videos.com )。
  2. Right-click the web page and select 'Inspect' ( Ctrl + Shift + I ).右键单击网页并选择“检查”( Ctrl + Shift + I )。
  3. Finally, switch to the 'Console' tab to start coding.最后,切换到“控制台”选项卡开始编码。

Code代码

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);

... ahem! ……咳咳!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无需在浏览器中打开即可下载pdf - Download pdf without opening in browser 禁止从Chrome移动浏览器下载jwplayer视频 - Prevent jwplayer video to download from chrome mobile browser 在不打开新页面的情况下从浏览器调用客户端 URL - Calling client side URL from browser without opening new page 如何在不打开浏览器的情况下下载pdf文件 - How to download pdf file without opening the browser 阻止谷歌浏览器下载视频 - Android Chrome浏览器 - prevent google chrome to download video - Android Chrome browser 如何在不使用浏览器播放的情况下下载外部视频? - How to download external video without playing in browser? 在Javascript / Jquery中不在浏览器上打开它来执行URL - Executing a url without opening it on the browser in Javascript / Jquery 从Chrome浏览器网址打开应用程序或使用javascript重定向到谷歌播放 - Opening application from chrome browser url or redirect to google play using javascript 如何在网站中使用 jquery/javascript 检测从 web 浏览器(chrome)或 webview(移动应用程序)打开的 url? - How to detect the url opening from web browser(chrome) or webview(mobile app) using jquery/javascript in the website? 如何在不打开新标签的情况下在Google Chrome扩展程序中下载文件 - How to download file in google chrome extension without opening a new tab
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM