diff --git a/main.js b/main.js index 911ee30..981f279 100644 --- a/main.js +++ b/main.js @@ -1,13 +1,25 @@ const cheerio = require('cheerio'); const electron = require('electron'); +const downloadManager = require("electron-download-manager"); const { autoUpdater } = require('electron-updater'); const { app, BrowserWindow, dialog, ipcMain, Menu, shell } = electron; +const fs = require("fs"); const isOnline = require('is-online'); const path = require('path'); const request = require('request'); +const unzip = require('unzipper'); const url = require('url'); let mainWindow; +const downloadFolder = app.getPath('downloads') + '/bandcamp-desktop/'; + +if(!fs.existsSync(downloadFolder)){ + fs.mkdirSync(downloadFolder); +} + +downloadManager.register({ + downloadFolder: downloadFolder +}); app.setName('Bandcamp Desktop'); app.allowRendererProcessReuse = true; @@ -45,12 +57,15 @@ function createWindow(){ autoUpdater.checkForUpdatesAndNotify(); +function openDialog(title, message){ + const response = dialog.showMessageBox(mainWindow, + { + title: title, + message: message + }); +} function about(){ - const response = dialog.showMessageBox(mainWindow, - { - title: 'Bandcamp Desktop - About', - message: 'Bandcamp Desktop is a crossplatform desktop application which allows you to use bandcamp.com in an easy and quick way.\n\nVersion: v' + app.getVersion() + '\nDeveloped by: Giulio De Matteis \n\nBuilt using cheerio, electron framework, electron-builder, electron-updater, is-online, request and url packages with their dependecies.' - }); + openDialog('Bandcamp Desktop - About', 'Bandcamp Desktop is a crossplatform desktop application which allows you to use bandcamp.com in an easy and quick way.\n\nVersion: v' + app.getVersion() + '\nDeveloped by: Giulio De Matteis \n\nBuilt using cheerio, electron framework, electron-builder, electron-download-manager, electron-updater, fs, is-online, request, unzipper and url packages with their dependecies.'); } function tag(tag){ @@ -134,6 +149,13 @@ function createWindow(){ player.setResizable(false); } }); + }, + }, + { + label: 'Library', + accelerator: process.platform == 'darwin' ? 'Command+L' : 'Ctrl+L', + click(){ + shell.openPath(downloadFolder) } }, { type: 'separator' }, @@ -151,7 +173,7 @@ function createWindow(){ label: 'Search', submenu:[ { - label: 'Filters', + label: 'Tags', submenu:[ { label: 'Acoustic', @@ -281,6 +303,18 @@ function createWindow(){ } }, ] + }, + { + label: 'Filters', + accelerator: process.platform == 'darwin' ? 'Command+F' : 'Ctrl+F', + click(){ + mainWindow.loadURL(require('url').format({ + pathname: 'bandcamp.com', + hash: '#discover', + protocol: 'https:', + slashes: true + })); + } } ] }, @@ -328,8 +362,6 @@ function createWindow(){ ...(isMac ? [ { type: 'separator' }, { role: 'front' }, - /*{ type: 'separator' }, - { role: 'window' }*/ ] : [ { role: 'close' } ]) @@ -368,9 +400,31 @@ const menu = Menu.buildFromTemplate(template) }) mainWindow.webContents.on('will-navigate', (event, url) => { - if(!require('url').parse(url).hostname.includes('bandcamp.com')){ - shell.openExternal(url) - event.preventDefault() + var domain = require('url').parse(url).hostname; + if(!domain.includes('bandcamp.com') && !domain.includes('bcbits.com')){ + shell.openExternal(url); + event.preventDefault(); + }else if(domain.includes('bcbits.com')){ + openDialog('Bandcamp Desktop - Download Manager', 'Bandcamp Desktop is downloading and extracting your music...') + downloadManager.download({ + url: url + }, function (error, info) { + if (error) { + console.log(error); + return; + } + console.log("DONE: " + info.url); + fs.readdir(downloadFolder, (err, files) => { + files.forEach(file => { + fs.createReadStream(downloadFolder + file).pipe(unzip.Extract({ path: downloadFolder })); + if(file.includes('.png') || file.includes('.zip')){ + fs.unlinkSync(downloadFolder + file); + } + }); + }); + openDialog('Bandcamp Desktop - Download Manager', 'The download is complete! You can find your music in File > Library'); + }); + event.preventDefault(); } }) diff --git a/package-lock.json b/package-lock.json index 7f727ca..17d26dd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -292,8 +292,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "bcrypt-pbkdf": { "version": "1.0.2", @@ -303,6 +302,20 @@ "tweetnacl": "^0.14.3" } }, + "big-integer": { + "version": "1.6.48", + "resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz", + "integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==" + }, + "binary": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/binary/-/binary-0.3.0.tgz", + "integrity": "sha1-n2BVO8XOjDOG87VTz/R0Yq3sqnk=", + "requires": { + "buffers": "~0.1.1", + "chainsaw": "~0.1.0" + } + }, "bluebird": { "version": "3.7.2", "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", @@ -368,7 +381,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -386,6 +398,16 @@ "integrity": "sha1-MnE7wCj3XAL9txDXx7zsHyxgcO8=", "dev": true }, + "buffer-indexof-polyfill": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-indexof-polyfill/-/buffer-indexof-polyfill-1.0.1.tgz", + "integrity": "sha1-qfuAbOgUXVQoUQznLyeLs2OmOL8=" + }, + "buffers": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz", + "integrity": "sha1-skV5w77U1tOWru5tmorn9Ugqt7s=" + }, "builder-util": { "version": "22.8.0", "resolved": "https://registry.npmjs.org/builder-util/-/builder-util-22.8.0.tgz", @@ -487,6 +509,14 @@ "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" }, + "chainsaw": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz", + "integrity": "sha1-XqtQsor+WAdNDVgpE4iCi15fvJg=", + "requires": { + "traverse": ">=0.3.0 <0.4" + } + }, "chalk": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", @@ -595,8 +625,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "concat-stream": { "version": "1.6.2", @@ -844,6 +873,14 @@ "integrity": "sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==", "dev": true }, + "duplexer2": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/duplexer2/-/duplexer2-0.1.4.tgz", + "integrity": "sha1-ixLauHjA1p4+eJEFFmKjL8a93ME=", + "requires": { + "readable-stream": "^2.0.2" + } + }, "duplexer3": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz", @@ -930,6 +967,11 @@ } } }, + "electron-download-manager": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/electron-download-manager/-/electron-download-manager-2.1.2.tgz", + "integrity": "sha512-9v8aeMVZTX69NjEveKlKfTlJY74twpKktTXrmDI+UcQHZg7FtwuqxWw0ZNrjtVAOBcVNKzwG4ekn44B+xhz1tg==" + }, "electron-publish": { "version": "22.8.0", "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-22.8.0.tgz", @@ -1177,6 +1219,22 @@ "universalify": "^0.1.0" } }, + "fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "fstream": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/fstream/-/fstream-1.0.12.tgz", + "integrity": "sha512-WvJ193OHa0GHPEL+AycEJgxvBEwyfRkN1vhjca23OaPVMCaLCXTd5qAu82AjTcgP1UJmytkOKb63Ypde7raDIg==", + "requires": { + "graceful-fs": "^4.1.2", + "inherits": "~2.0.0", + "mkdirp": ">=0.5 0", + "rimraf": "2" + } + }, "get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -1199,6 +1257,19 @@ "assert-plus": "^1.0.0" } }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, "global-agent": { "version": "2.1.12", "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-2.1.12.tgz", @@ -1371,6 +1442,15 @@ "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==" }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -1468,8 +1548,7 @@ "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true + "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=" }, "isbinaryfile": { "version": "4.0.6", @@ -1637,6 +1716,11 @@ "resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.4.tgz", "integrity": "sha1-iCY2pyRcLP5uCk47psXWihN+XGU=" }, + "listenercount": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/listenercount/-/listenercount-1.0.1.tgz", + "integrity": "sha1-hMinKrWcRyUyFIDJdeZQg0LnCTc=" + }, "locate-path": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", @@ -1725,7 +1809,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1733,14 +1816,12 @@ "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI=", - "dev": true + "integrity": "sha1-Z9ZgFLZqaoqqDAg8X9WN9OTpdgI=" }, "mkdirp": { "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "integrity": "sha1-2Rzv1i0UNsoPQWIOJRKI1CAJne8=", - "dev": true, "requires": { "minimist": "^1.2.5" } @@ -1934,6 +2015,11 @@ "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", "dev": true }, + "path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" + }, "path-parse": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", @@ -1966,8 +2052,7 @@ "process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha1-eCDZsWEgzFXKmud5JoCufbptf+I=", - "dev": true + "integrity": "sha1-eCDZsWEgzFXKmud5JoCufbptf+I=" }, "progress": { "version": "2.0.3", @@ -2059,7 +2144,6 @@ "version": "2.3.7", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, "requires": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -2144,6 +2228,14 @@ "lowercase-keys": "^1.0.0" } }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "requires": { + "glob": "^7.1.3" + } + }, "roarr": { "version": "2.15.3", "resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.3.tgz", @@ -2228,6 +2320,11 @@ "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", "dev": true }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, "signal-exit": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", @@ -2429,6 +2526,11 @@ } } }, + "traverse": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/traverse/-/traverse-0.3.9.tgz", + "integrity": "sha1-cXuPIgzAu3tE5AUUwisui7xw2Lk=" + }, "truncate-utf8-bytes": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", @@ -2495,6 +2597,30 @@ "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", "dev": true }, + "unzipper": { + "version": "0.10.11", + "resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.10.11.tgz", + "integrity": "sha512-+BrAq2oFqWod5IESRjL3S8baohbevGcVA+teAIOYWM3pDVdseogqbzhhvvmiyQrUNKFUnDMtELW3X8ykbyDCJw==", + "requires": { + "big-integer": "^1.6.17", + "binary": "~0.3.0", + "bluebird": "~3.4.1", + "buffer-indexof-polyfill": "~1.0.0", + "duplexer2": "~0.1.4", + "fstream": "^1.0.12", + "graceful-fs": "^4.2.2", + "listenercount": "~1.0.1", + "readable-stream": "~2.3.6", + "setimmediate": "~1.0.4" + }, + "dependencies": { + "bluebird": { + "version": "3.4.7", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.4.7.tgz", + "integrity": "sha1-9y12C+Cbf3bQjtj66Ysomo0F+rM=" + } + } + }, "update-notifier": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/update-notifier/-/update-notifier-4.1.0.tgz", diff --git a/package.json b/package.json index c1bfdd3..a195b27 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bandcamp-desktop", "productName": "Bandcamp Desktop", - "version": "2.0.0-beta.2", + "version": "2.0.0-beta.3", "description": "bandcamp Desktop is a desktop application written by Giulio De Matteis.\r It allows you to use bandcamp.com in an easy and quick way.", "main": "main.js", "scripts": { @@ -21,9 +21,11 @@ "homepage": "https://github.com/themagiulio/bandcamp-desktop#readme", "dependencies": { "cheerio": "^1.0.0-rc.3", + "electron-download-manager": "^2.1.2", "electron-updater": "^4.3.4", "is-online": "^8.4.0", "request": "^2.88.2", + "unzipper": "^0.10.11", "url": "^0.11.0" }, "devDependencies": {