spotify-local-control
Advanced tools
Comparing version 1.0.0 to 1.0.1
37
index.js
@@ -6,2 +6,3 @@ const https = require('https') | ||
const randomString = require('random-string') | ||
const portscanner = require('portscanner') | ||
@@ -52,6 +53,4 @@ module.exports = connect | ||
function localApi () { | ||
const endpoint = `https://${randomString({length: 10})}.spotilocal.com:4370` | ||
var csrfAndOuathAndEndpoints | ||
var csrfAndOuath | ||
return { | ||
@@ -61,8 +60,18 @@ // send request to local spotify client | ||
get (path, query = {}) { | ||
csrfAndOuath = csrfAndOuath || Promise.all([ | ||
getCsrfToken(), | ||
getOauthToken() | ||
]) | ||
csrfAndOuathAndEndpoints = csrfAndOuathAndEndpoints || Promise.all([ | ||
getOauthToken(), | ||
findPort() | ||
]) | ||
.then(function ([oauth, port]) { | ||
const endpoint = `https://${randomString({length: 10})}.spotilocal.com:${port}` | ||
return csrfAndOuath.then(([csrf, oauth]) => get(endpoint + path, { | ||
return Promise.all([ | ||
oauth, | ||
getCsrfToken({endpoint: endpoint}), | ||
endpoint | ||
]) | ||
}) | ||
return csrfAndOuathAndEndpoints.then(([oauth, csrf, endpoint]) => get(endpoint + path, { | ||
headers: { | ||
@@ -76,5 +85,15 @@ 'Origin': 'https://open.spotify.com' | ||
// find port sportify webhelper is running on | ||
// null -> int | ||
function findPort () { | ||
return new Promise(function (resolve, reject) { | ||
portscanner.findAPortInUse(4370, 4380, '127.0.0.1', function(error, port) { | ||
error ? reject(error) : resolve(port) | ||
}) | ||
}) | ||
} | ||
// fetch csrf token | ||
// null -> promise | ||
function getCsrfToken () { | ||
function getCsrfToken ({endpoint: endpoint}) { | ||
return get(endpoint + '/simplecsrf/token.json', { | ||
@@ -81,0 +100,0 @@ headers: { |
{ | ||
"name": "spotify-local-control", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Control a local spotify client via spotify-webhelper", | ||
@@ -20,4 +20,5 @@ "main": "index.js", | ||
"random-string": "^0.1.2", | ||
"url-parse-lax": "^1.0.0" | ||
"url-parse-lax": "^1.0.0", | ||
"portscanner": "^2.1.1" | ||
} | ||
} |
@@ -38,2 +38,5 @@ # spotify-local-control [![stability][0]][1] | ||
## See Also | ||
- [spotify-find](https://github.com/f-mer/spotify-find) - get spotify catalog information | ||
## License | ||
@@ -40,0 +43,0 @@ [MIT](https://tldrlegal.com/license/mit-license) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6678
118
55
4
+ Addedportscanner@^2.1.1
+ Addedasync@2.6.4(transitive)
+ Addedis-number-like@1.0.8(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlodash.isfinite@3.3.2(transitive)
+ Addedportscanner@2.2.0(transitive)