New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

electron-widevinecdm

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-widevinecdm - npm Package Compare versions

Comparing version

to
4.0.0

.npmignore

140

lib/index.js
'use strict';
const extract = require('extract-zip');
const fs = require('fs-extra');
const https = require('follow-redirects').https;
const path = require('path');
const rp = require('request-promise');
const { WIDEVINECDM_VERSION } = require('./constants');
const compareVersions = (v1, v2) => {
const v1Nums = v1.split('.').map(num => parseInt(num, 10));
const v2Nums = v2.split('.').map(num => parseInt(num, 10));
for (let i = 0; i < v1Nums.length; i += 1) {
if (v1Nums[i] > v2Nums[i]) return 1;
if (v1Nums[i] < v2Nums[i]) return -1;
}
return 0;
};
const extractZipAsync = (source, target) => new Promise((resolve, reject) => {
extract(source, { dir: target }, err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
const downloadSingleFileAsync = (url, dest) => new Promise((resolve, reject) => {
const file = fs.createWriteStream(dest);
https.get(url, response => {
response.pipe(file);
file.on('finish', () => {
file.close(() => resolve()); // close() is async, call cb after close completes.
});
}).on('error', err => {
// Handle errors
fs.unlink(dest); // Delete the file async. (But we don't check the result)
reject(err);
});
});
const downloadAsync = (app, dest, platform = process.platform, arch = process.arch) => {
const libFileName = `widevinecdm_${platform}_${arch}.zip`;
const jsonFileName = 'latest.json';
const rpOpts = {
uri: 'https://api.github.com/repos/webcatalog/electron-widevinecdm/releases/latest',
headers: {
'User-Agent': 'Request-Promise',
Accept: 'application/vnd.github.v3+json'
},
json: true
};
return rp(rpOpts).then(({ assets }) => {
const tmpLibPath = path.join(app.getPath('temp'), `widevinecdm-${process.pid}-${Date.now()}.zip`);
const localJsonPath = path.join(dest, 'latest.json');
let libUrl;
let jsonUrl;
for (let i = 0; i < assets.length; i += 1) {
if (assets[i].name === libFileName) {
libUrl = assets[i].browser_download_url;
}
if (assets[i].name === jsonFileName) {
jsonUrl = assets[i].browser_download_url;
}
}
return downloadSingleFileAsync(libUrl, tmpLibPath).then(() => extractZipAsync(tmpLibPath, dest)).then(() => downloadSingleFileAsync(jsonUrl, localJsonPath));
});
};
const checkForUpdateAsync = dest => Promise.resolve().then(() => {
const rpOpts = {
uri: 'https://api.github.com/repos/webcatalog/electron-widevinecdm/releases/latest',
headers: {
'User-Agent': 'Request-Promise',
Accept: 'application/vnd.github.v3+json'
},
json: true
};
return rp(rpOpts);
}).then(({ tag_name }) => {
const rpOpts = {
// eslint-disable-next-line camelcase
uri: `https://github.com/webcatalog/electron-widevinecdm/releases/download/${tag_name}/latest.json`,
headers: {
'User-Agent': 'Request-Promise',
Accept: 'application/vnd.github.v3+json'
},
json: true
};
return rp(rpOpts);
}).then(latestJson => {
const localJsonPath = path.join(dest, 'latest.json');
return fs.pathExists(localJsonPath).then(exists => {
if (exists) {
return fs.readJson(localJsonPath).then(localJson => {
const localVersion = localJson.version;
const latestVersion = latestJson.version;
return compareVersions(latestVersion, localVersion) > 0;
});
}
return true; // hasUpdate = true;
});
});
const isDownloaded = dest => {
const load = app => {
let widevineCdmPluginFilename;

@@ -135,23 +21,4 @@ switch (process.platform) {

const pluginPath = path.join(dest, widevineCdmPluginFilename);
const pluginPath = path.join(__dirname, '..', 'widevine', widevineCdmPluginFilename);
return fs.existsSync(pluginPath);
};
const load = (app, dest) => {
let widevineCdmPluginFilename;
switch (process.platform) {
case 'darwin':
widevineCdmPluginFilename = 'widevinecdmadapter.plugin';
break;
case 'linux':
widevineCdmPluginFilename = 'libwidevinecdmadapter.so';
break;
default:
case 'win32':
widevineCdmPluginFilename = 'widevinecdmadapter.dll';
}
const pluginPath = path.join(dest, widevineCdmPluginFilename);
app.commandLine.appendSwitch('widevine-cdm-path', pluginPath);

@@ -163,6 +30,3 @@

module.exports = {
checkForUpdateAsync,
downloadAsync,
isDownloaded,
load
};

@@ -9,2 +9,3 @@ 'use strict';

const execFile = require('child_process').execFile;
const extract = require('extract-zip');

@@ -17,2 +18,12 @@ const { WIDEVINECDM_VERSION } = require('./constants');

const extractAsync = (source, target) => new Promise((resolve, reject) => {
extract(source, { dir: target }, err => {
if (err) {
reject(err);
return;
}
resolve();
});
});
const getChromePath = () => {

@@ -116,6 +127,7 @@ switch (process.platform) {

}).then(() => {
const outputPath = path.resolve(__dirname, '..', 'dist');
const outputPath = path.resolve(__dirname, '..', 'widevine');
const archivePath = path.resolve(outputPath, `widevinecdm_${process.platform}_x64.zip`);
const latestJsonPath = path.join(outputPath, 'latest.json');
const latestJson = path.join(outputPath, 'latest.json');
return fs.ensureFile(latestJson).then(() => fs.writeJson(latestJson, { version: WIDEVINECDM_VERSION })).then(() => {
return fs.ensureFile(latestJsonPath).then(() => fs.writeJson(latestJsonPath, { version: WIDEVINECDM_VERSION })).then(() => {
if (!fs.existsSync(outputPath)) {

@@ -125,5 +137,6 @@ fs.mkdirSync(outputPath);

const archive = archiver(`${outputPath}/widevinecdm_${process.platform}_x64.zip`, { store: true });
const archive = archiver(archivePath, { store: true });
// append a file
archive.file(latestJsonPath, { name: 'latest.json' });
pluginPaths.forEach(filePath => {

@@ -134,3 +147,3 @@ archive.file(filePath, { name: path.basename(filePath) });

return archive.finalize();
});
}).then(() => extractAsync(archivePath, outputPath));
}).catch(err => {

@@ -137,0 +150,0 @@ console.log(err);

{
"name": "electron-widevinecdm",
"version": "3.2.5",
"version": "4.0.0",
"description": "WidevineCDM for Electron",

@@ -10,2 +10,3 @@ "main": "lib/index.js",

"scripts": {
"postinstall": "node install.js",
"build": "babel src --out-dir lib",

@@ -30,6 +31,4 @@ "lint": "eslint ./src --ext js",

"follow-redirects": "^1.2.4",
"fs-extra": "^3.0.1",
"request": "^2.81.0",
"request-promise": "^4.2.1"
"fs-extra": "^3.0.1"
}
}

@@ -7,3 +7,2 @@ # electron-widevinecdm

[![MIT License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/webcatalog/electron-widevinecdm/blob/master/LICENSE)
[![Donate with Paypal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=JZ2Y4F47ZMGHE&lc=US&item_name=electron-widevinecdm&item_number=webcatalog&currency_code=USD)

@@ -25,45 +24,6 @@ WidevineCDM for Electron - Allows you to run Netflix and other streaming websites in your Electron apps.

```js
const { app, dialog } = require('electron');
const { app } = require('electron');
const widevine = require('electron-widevinecdm');
// location to store widevine files
const widevinePath = path.join(app.getPath('appData'), 'widevine');
// widevineCDM needs to start running before the ready event
// try to load widevine from widevinePath
// it will return a boolean to tell you if the files exist or not.
const widevineExists = widevine.isDownloaded(widevinePath);
if (widevineExists) {
widevine.load(app, widevinePath);
}
app.on('ready', () => {
// when the app is ready
// try to download widevine files if they don't exist.
if (!widevineExists) {
widevine.downloadAsync(widevinePath)
.then(() => {
// the user needs to relaunch the app
app.relaunch();
dialog.showMessageBox({
message: 'You need to relaunch the app to use widevineCDM',
buttons: [
'Relaunch now',
'Cancel',
],
defaultId: 0,
cancelId: 1,
}, (response) => {
if (response === 0) {
app.quit();
}
});
})
.catch((err) => {
console.log(err);
});
}
});
widevine.load(app);
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet