-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade some node libs, fix java.nullPointer stuff with Spotify
- Loading branch information
1 parent
486ac89
commit 1e632ee
Showing
7 changed files
with
171 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "sonos-controller-unofficial", | ||
"description": "Unoffical sonos controller for linux.", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"author": "Pascal Opitz <[email protected]>", | ||
"main": "main.js", | ||
"dependencies": { | ||
|
@@ -14,7 +14,7 @@ | |
"lodash": "^4.17.4", | ||
"moment": "^2.18.1", | ||
"omit-keys": "^0.1.0", | ||
"preact": "^7.2.1", | ||
"preact": "^8.1.0", | ||
"preact-virtual-list": "^0.3.1", | ||
"request": "^2.81.0", | ||
"uuid": "^3.0.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// import _ from 'lodash'; | ||
|
||
// import moment from 'moment'; | ||
|
||
import crypto from 'crypto'; | ||
import requestHelper from 'request'; | ||
// import xml2json from 'jquery-xml2json'; | ||
|
||
// import SonosService from '../services/SonosService'; | ||
|
||
// const NS = 'http://www.sonos.com/Services/1.1'; | ||
// const deviceProviderName = 'SonosControllerForChrome'; | ||
// const RUNTIME_ID = 'pascal-sonos-app'; | ||
|
||
const PARTNER_USERNAME = 'iphone'; | ||
const PARTNER_PASSWORD = 'P2E4FC0EAD3*878N92B2CDp34I0B1@388137C'; | ||
const PARTNER_DEVICEID = 'IP01'; | ||
const API_VERSION = '5'; | ||
|
||
const ENCRYPTION_PASSWORD = '721^26xE22776'; | ||
const DECRYPTION_PASSWORD = '20zE1E47BE57$51'; | ||
|
||
function pandoraEncode(str) { | ||
const buf = Buffer.from(ENCRYPTION_PASSWORD, "base64"); | ||
let cipher = crypto.createCipheriv('bf-ecb', buf, Buffer.alloc(0)); | ||
|
||
let encrypted = cipher.update(str, 'utf8', 'hex'); | ||
encrypted += cipher.final('hex'); | ||
console.log(encrypted); | ||
|
||
return encrypted; | ||
} | ||
|
||
function pandoraDecode(str) { | ||
const buf = Buffer.from(DECRYPTION_PASSWORD, "base64"); | ||
const decipher = crypto.createDecipheriv('bf-ecb', buf, Buffer.alloc(0)); | ||
|
||
var decrypted = decipher.update(str, 'hex', 'utf8'); | ||
decrypted += decipher.final('utf8'); | ||
console.log(decrypted); | ||
|
||
return decrypted; | ||
} | ||
|
||
class PandoraServiceClient { | ||
|
||
constructor(serviceDefinition) { | ||
this._serviceDefinition = serviceDefinition; | ||
|
||
this.name = serviceDefinition.Name; | ||
this.auth = serviceDefinition.Auth; | ||
} | ||
|
||
_getPartnerCode() { | ||
return new Promise((resolve, reject) => { | ||
requestHelper({ | ||
method: 'POST', | ||
uri: this._serviceDefinition.SecureUri + '?method=auth.partnerLogin', | ||
json: { | ||
username: PARTNER_USERNAME, | ||
password: PARTNER_PASSWORD, | ||
deviceModel: PARTNER_DEVICEID, | ||
version: API_VERSION, | ||
} | ||
}, (err, res, body) => { | ||
if(err) { | ||
reject(err); | ||
} else if (res.statusCode != 200) { | ||
reject(body); | ||
} else { | ||
this.partnerAuthToken = body.result.partnerAuthToken; | ||
this.partnerId = body.result.partnerId; | ||
resolve(body); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
_userLogin(username, password) { | ||
|
||
let params = { | ||
username, | ||
password, | ||
partnerAuthToken: this.partnerAuthToken, | ||
loginType: 'user', | ||
returnStationList: true, | ||
}; | ||
let body = pandoraEncode(JSON.stringify(params)); | ||
|
||
return new Promise((resolve, reject) => { | ||
requestHelper({ | ||
method: 'POST', | ||
uri: this._serviceDefinition.SecureUri + '?method=auth.userLogin&partner_id=' + this.partnerId + '&partner_auth_token=' + escape(this.partnerAuthToken), | ||
body, | ||
}, (err, res, body) => { | ||
if(err) { | ||
reject(err); | ||
} else if (res.statusCode != 200) { | ||
reject(body); | ||
} else { | ||
resolve(body); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
getSessionId(username, password) { | ||
return Promise.resolve() | ||
.then(() => { | ||
return this._getPartnerCode(); | ||
}) | ||
.then(() => { | ||
return this._userLogin(username, password); | ||
}); | ||
} | ||
|
||
|
||
} | ||
|
||
export default PandoraServiceClient; |