All Projects → danielnieto → electron-download-manager

danielnieto / electron-download-manager

Licence: MIT license
Manage downloadItems from Electron's BrowserWindows without user interaction, allowing single file download and bulk downloading

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to electron-download-manager

Fetch
The best file downloader library for Android
Stars: ✭ 1,124 (+894.69%)
Mutual labels:  downloadmanager
Rxdownloader
Demo of Downloading Songs/Images through Android Download Manager using RxJava2
Stars: ✭ 166 (+46.9%)
Mutual labels:  downloadmanager
scihub
Copernicus Sentinel Science Hub rolling archive downloader
Stars: ✭ 28 (-75.22%)
Mutual labels:  downloadmanager
Updater
基于DownloadManager封装的更新器,使用超简单!
Stars: ✭ 82 (-27.43%)
Mutual labels:  downloadmanager
Appupdate
🔥原生DownloadManager实现版本的检测更新,完美适配Android M/N/O/P/Q,兼容AndroidX
Stars: ✭ 125 (+10.62%)
Mutual labels:  downloadmanager
Hwifiledownload
HWIFileDownload simplifies file download with NSURLSession on iOS.
Stars: ✭ 209 (+84.96%)
Mutual labels:  downloadmanager
Downloader
Downloader for android with pause, resume, cancel, queue options
Stars: ✭ 40 (-64.6%)
Mutual labels:  downloadmanager
BloomR
Portable R for Bloomberg and Refinitiv Eikon
Stars: ✭ 15 (-86.73%)
Mutual labels:  bulk-download
Psdle
Improving everyone's favorite online download list, one loop at a time.
Stars: ✭ 141 (+24.78%)
Mutual labels:  downloadmanager
DownloadManagerPlus
Using faster and easier than Android Download Manager
Stars: ✭ 80 (-29.2%)
Mutual labels:  downloadmanager
Docker Jdownloader
JDownloader 2 Docker Image (Multiarch) - Passed 40M Downloads
Stars: ✭ 85 (-24.78%)
Mutual labels:  downloadmanager
Android Download Manager Pro
Android/Java download manager library help you to download files in parallel mechanism in some chunks.
Stars: ✭ 1,568 (+1287.61%)
Mutual labels:  downloadmanager
Mr.Dclutterer
A minimal looking cross-platform desktop application made with Electron that handles quick file aggregation and bulk renaming.
Stars: ✭ 32 (-71.68%)
Mutual labels:  bulk
Uget Chrome Wrapper
Moved to https://github.com/ugetdm/uget-integrator and https://github.com/ugetdm/uget-extension
Stars: ✭ 74 (-34.51%)
Mutual labels:  downloadmanager
android-downloader
An powerful download library for Android.
Stars: ✭ 375 (+231.86%)
Mutual labels:  downloadmanager
Mzdownloadmanager
This download manager uses NSURLSession api to download files. It can download multiple files at a time. It can download large files if app is in background. It can resume downloads if app was quit.
Stars: ✭ 1,061 (+838.94%)
Mutual labels:  downloadmanager
Pyload
The free and open-source Download Manager written in pure Python
Stars: ✭ 2,393 (+2017.7%)
Mutual labels:  downloadmanager
ARF-Converter
Bulk ARF file converter
Stars: ✭ 15 (-86.73%)
Mutual labels:  bulk
WPWatcher
Wordpress Watcher is a wrapper for WPScan that manages scans on multiple sites and reports by email and/or syslog. Schedule scans and get notified when vulnerabilities, outdated plugins and other risks are found.
Stars: ✭ 34 (-69.91%)
Mutual labels:  bulk
wordpress-plugin
Speed up your WordPress website. Optimize your JPEG and PNG images automatically with TinyPNG.
Stars: ✭ 78 (-30.97%)
Mutual labels:  bulk

electron-download-manager

Manage downloadItems from Electron's BrowserWindows without user interaction, allowing single file download and bulk downloading asynchronously

Why?

  • Register global listener that attaches to all newly created BrowserWindow instances
  • Automatically download the file to a given folder, without user prompt
  • Callback when download has completed (or failed)
  • Bulk download: pass a bunch of links and all will get downloaded, with a callback once they're all done.

Install

$ npm install electron-download-manager

Usage

Register it for all windows

Register the listener (that will catch all DownloadItems)

const electron = require("electron");
const { app, BrowserWindow } = electron;

const DownloadManager = require("electron-download-manager");

DownloadManager.register();

app.on("ready", () => {
    let mainWindow = new BrowserWindow();
});

Examples

After registering you must wait until at least 1 window is created to call DownloadManager.download function

Single file download from the Main Process

const electron = require("electron");
const { app, BrowserWindow } = electron;

const DownloadManager = require("electron-download-manager");

DownloadManager.register({
    downloadFolder: app.getPath("downloads") + "/my-app"
});

app.on("ready", () => {

    let mainWindow = new BrowserWindow();

    mainWindow.loadURL(`file://${__dirname}/app/index.html`);

    //Single file download
    DownloadManager.download({
        url: "https://i.imgur.com/H124sSq.jpg"
    }, function (error, info) {
        if (error) {
            console.log(error);
            return;
        }

        console.log("DONE: " + info.url);
    });

});

This example downloads https://i.imgur.com/H124sSq.jpg file to user-downloads-folder/my-app/H124sSq.jpg

Bulk file download from the Main Process

const electron = require("electron");
const {app, BrowserWindow} = electron;

const DownloadManager = require("electron-download-manager");

DownloadManager.register({downloadFolder: app.getPath("downloads") + "/my-app"});;

app.on("ready", () => {
    let mainWindow = new BrowserWindow();

    mainWindow.loadURL(`file://${__dirname}/app/index.html`);

    var links = [
        "https://i.imgur.com/xineeuw.jpg",
        "https://i.imgur.com/RguiWa6.jpg",
        "https://i.imgur.com/JR4Z0aD.jpg",
        "https://i.imgur.com/ccvEJO1.jpg",
        "https://i.imgur.com/yqZoShd.jpg"
    ];

    //Bulk file download    
    DownloadManager.bulkDownload({
        urls: links,
        path: "bulk-download"
    }, function (error, finished, errors) {
        if (error) {
            console.log("finished: " + finished);
            console.log("errors: " + errors);
            return;
        }

        console.log("all finished");
    });

});

This example downloads 5 files to user-downloads-folder/my-app/bulk-downloads

Use from Renderer Process

Once you've registered the listener on the Main process at any time you can call the download function through electron's remote

require("electron").remote.require("electron-download-manager").download({
    url: "https://i.imgur.com/H124sSq.jpg"
}, function (error, info) {
    if (error) {
        console.log(error);
        return;
    }

    console.log("DONE: " + info.url);
});

API

DownloadManager.register([options])

options

downloadFolder

Type: string
Default: app.getPath("downloads")]

Set a folder where all downloadItems will be downloaded to. It will also be the parent folder for individual folders of each download. Explained below in Download function.

By default, this "root" folder will be user's OS downloads folder (read about this)

If the file already exists in the location it will check the file's size against the size on the server, if it is lower than the server it will attempt to resume downloading the file. This is good for downloading large files. E.G Downloading a 200MB file and only 100MB downloaded (app closed/crashed) it will resume the download from where it left off automatically.

If the file size on the disk is the same as the server it will not download and return a successful callback.

DownloadManager.download(options, callback(error, {url, filePath}))

options

url

Type: string

The url of the file to be downloaded

path

Type: string
Default: ""

Set a folder where this downloadItems will be downloaded to. This folder is relative to downloadFolder location set in the register function. By default it will be downloaded to root of downloadFolder which would be user download's folder.

onLogin(authInfo, callback)

Type: function

Emitted when an authenticating proxy is asking for user credentials.

    DownloadManager.download({
        url: "https://i.imgur.com/H124sSq.jpg",
        onLogin: (authInfo, callback) => {
            callback('username', 'password');
        },
    }, function (error, info) {
        if (error) {
            console.log(error);
            return;
        }

        console.log("DONE: " + info.url);
    });

Please see Class ClientRequest's 'login' event for detail.

onProgress(progress, item)

Type: function

A function to be called whenever the file being downloaded progresses, this function will be constantly called with the updated value.

progress an object with various metrics for the downloading file

{
    downloaded          // downloaded amount in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
    downloadedBytes     // same as previous only in bytes for calculation if required (eg. 4061073)
    progress            // float progress of downloaing file (0 to 100)
    remaining           // remaining amount of file download in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] (eg. 28.36 MB)
    remainingBytes      // same as previous only in bytes for calculation if required (eg. 28360919)
    speed               // download speed (eg. 311.3 KB/sec)
    speedBytes          // same as previous only in bytes for calculation if required (eg. 311296)
    total               // file size in ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] (eg. 32.42 MB)
    totalBytes          // same as previous only in bytes for calculation if required (eg. 32421992)
    }

item instance of DownloadItem class. Useful for pausing and cancelling among other things.

This feature currently exists only for single file downloads and hasn't been implemented (yet) for bulk processing.

callback(error, {url, filePath})

Callback to be called when the download has reached a "done" state, which could mean two things either it was successful, or it failed.

if the download was successful the callback's error will be null, otherwise it will contain the error message

url returns the url of the downloaded file
filePath location of where the file was saved

DownloadManager.bulkDownload(options, callback(error, finished, failed))

options

urls

Type: array

Array of url strings of the files to be downloaded

path

Type: string
Default: ""

Set a path to save all the bulk downloaded files. This folder is relative to downloadFolder location set in the register function. By default it will be downloaded to root of downloadFolder which would be user download's folder.

onResult(finishedCount, errorsCount, itemUrl)

Type: function

A function to be called whenever a file has been downloaded or whenever a download failed.

finishedCount integer. Represents the number of file successfully downloaded. example: 4

errorsCount integer. Represents the number of file that couldn't be downloaded. example: 5

itemUrl string. Represents the url of the item.

This feature is really different as the onProgress feature for single files as it doesn't take the size in the calculation.

callback(error, finished, failed)

Callback to be executed when all downloadItems in this bulk process have been completed

error will be null if everything was successful
finished is an array containing the url of successfully downloaded items
failed is an array containing the url of failed downloaded items (if any)

Questions

Feel free to open Issues to ask questions about using this module, PRs are very welcome and encouraged.

License

MIT © Daniel Nieto, loosely based on code from Sindre Sorhus

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].