javascript 下载诸如 mega.co.nz 之类的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15994554/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 02:51:23  来源:igfitidea点击:

Download files like mega.co.nz

javascriptflashdownload

提问by Amir Molaa

Today i checked mega.co.nz and i'm excited about some features. for example in download page it will download files on browser and after that decrypt them with javascript.

今天我查看了 mega.co.nz,我对一些功能感到很兴奋。例如在下载页面,它会在浏览器上下载文件,然后用 javascript 解密它们。

for example see this link to download a png file :

例如,请参阅此链接以下载 png 文件:

https://mega.co.nz/#!7JRgFJzJ!efpJGWuPhYczLexY19ex82nuwfs4sR_DG4JXddeClH4

https://mega.co.nz/#!7JRgFJzJ!efpJGWuPhYczLexY19ex82nuwfs4sR_DG4JXddeClH4

in this link it will start the download inside the browser. i checked network tab in inspect element it will download parts of file with AJAX after that completed all parts of file, will save all of them in one file on computer automatically!

在此链接中,它将在浏览器中开始下载。我检查了检查元素中的网络选项卡,它会在完成文件的所有部分后用 AJAX 下载文件的部分,将它们全部保存在计算机上的一个文件中!

i want to know what they do? can you explain or link to some resource about download files inside browser like that?

我想知道他们是做什么的?你能解释或链接到一些关于在浏览器中下载文件的资源吗?

also can done it only with javascript or should use some flash plugins or something like that?

也可以只用javascript来完成还是应该使用一些flash插件或类似的东西?

回答by roberto

Mega uses several different methods to do this: (as of 27 Nov 2013)

Mega 使用几种不同的方法来做到这一点:(截至 2013 年 11 月 27 日)

  1. Filesystem API(Chrome/Firefox Extension polyfill)
  2. Adobe Flash SWF Filewriter (old browsers fallback)
  3. BlobBuilder(IE10/IE11)
  4. MEGA Firefox Extension (deprecated)
  5. Arraybuffer/Blob (in memory) + a[download](for browsers that support a[download])
  6. MediaSource(experimental streaming solution)
  7. Blob stored in IndexedDB storage + a[download](Firefox 20+, improvement over the in-memory Blob method)
  1. 文件系统 API(Chrome/Firefox 扩展 polyfill)
  2. Adobe Flash SWF Filewriter(旧浏览器后备)
  3. BlobBuilder(IE10/IE11)
  4. MEGA Firefox 扩展(已弃用)
  5. Arraybuffer/Blob(在内存中)+ a[download](对于支持 a[download] 的浏览器)
  6. MediaSource(实验性流媒体解决方案)
  7. Blob 存储在 IndexedDB 存储中 + a[download](Firefox 20+,对内存中 Blob 方法的改进)

(source: https://eu.static.mega.co.nz/js/download_6.js)

(来源:https: //eu.static.mega.co.nz/js/download_6.js

回答by Ebrahim Byagowi

A basic implementation of multipart in-browser downloader using Blob and URL APIs is brought here. It downloads a file on 4 concurrent requests and shows the progress also. Please note that it seems setting rangeheader might generally not a good idea on XHR requests, have a look at this topic.

此处提供了使用 Blob 和 URL API 的多部分浏览器内下载器的基本实现。它下载 4 个并发请求的文件并显示进度。请注意,似乎range在 XHR 请求上设置标头通常不是一个好主意,请查看此主题

While downloading:

下载时:

While downloading

下载时

After the download:

下载后:

After the download

下载后

Another interesting topic would be implementing Pause/Resume functionality from Mega. XHR API of current browsers doesn't offer that capability so the only chance you have is to do multiple small sized chunks downloading and giving up on the downloaded part of your small chunks, the way it seems is done on Mega also. But fetchstreaming feature can be used for that purpose, I didn't explore that yet well enough but it is documented here.

另一个有趣的话题是从 Mega 实现暂停/恢复功能。当前浏览器的 XHR API 不提供该功能,因此您唯一的机会是下载多个小块并放弃小块的下载部分,Mega 上似乎也是这样做的。但是fetch流式传输功能可用于此目的,我还没有对此进行足够的探索,但已记录在此处

Btw, have a look at these awesome projects:

顺便说一句,看看这些很棒的项目:

回答by ccpizza

MEGAcmd

MEGA命令

There is megacmd, the official command line interface. You can also build it from sources on github at https://github.com/meganz/MEGAcmd

megacmd,官方命令行界面。您也可以在https://github.com/meganz/MEGAcmd上从 github 上的源构建它

megacmdis a wrapper around Mega SDK and if you decide to compile it on your own you'll need the same dependencies (on ubuntu) as the ones listed below for Mega SDK.

megacmd是 Mega SDK 的包装器,如果您决定自己编译它,您将需要与下面列出的 Mega SDK 相同的依赖项(在 ubuntu 上)。

For details on usage see the MEGAcmd User Guide.

有关使用的详细信息,请参阅MEGAcmd 用户指南

Mega SDK

超级SDK

Mega SDK which can be compiled by following the steps on the githubpage. It includes the megacliutility which is an interactive shell for synching and downloading/uploading.

Mega SDK,可以按照github页面上的步骤进行编译。它包括megacli实用程序,它是一个用于同步和下载/上传的交互式 shell。

## compilation steps for ubuntu
git clone --depth 1 https://github.com/meganz/sdk megasdk
cd megasdk
sudo apt install libcurl4-openssl-dev  libc-ares-dev libssl-dev libcrypto++-dev  zlib1g-dev libsqlite3-dev  libfreeimage-dev libswscale-dev
autogen.sh
./configure
make -j 8  ## pass the number of CPUs you have to speed up compilation
sudo make install

mega.py python module (deprecated)

mega.py python 模块(已弃用)

For those who found this question searching for an actual recipe to download a link in text mode here is a simple python script that uses the mega.pymodule (install it with sudo pip install mega.py):

对于那些在文本模式下搜索实际配方以下载链接的问题发现此问题的人,这里是一个使用mega.py模块的简单 python 脚本(使用 安装它sudo pip install mega.py):

import sys
import getpass
#install the module with: 'sudo pip install mega.py'
from mega import Mega

email = '[email protected]'
password = getpass.getpass(prompt='Mega password for {}:'.format(email))

mega = Mega({'verbose': True})
m = mega.login(email, password)
m.download_url(sys.argv[1])

The script works with python 2.7 and takes the URL of the mega.nz link.

该脚本适用于 python 2.7 并采用 mega.nz 链接的 URL。

getpassis used for securely entering the password in the console in order to avoid storing the password in the script — if you are comfortable hardcoding the password then set it in line #7.

getpass用于在控制台中安全地输入密码,以避免将密码存储在脚本中 - 如果您愿意对密码进行硬编码,则在第 7 行中设置它。

megatools

megatools

On most Linux/posix boxes you can install megatoolsfrom standard repositories, i.e.

在大多数 Linux/posix 机器上,您可以从标准存储库安装megatools,即

On ubuntu/debian:

在 ubuntu/debian 上:

apt install megatools

On MacOS:

在 MacOS 上:

brew install megatools

Once installed you will find a number of command line utilities, among which megadlwhich can download both shared files and your own files. See megadl -hfor details.

安装后,您会发现许多命令行实用程序,megadl其中可以下载共享文件和您自己的文件。详情请参阅megadl -h