forked from dconnolly/chromecast-backgrounds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·28 lines (24 loc) · 881 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
var Q = require('q');
var request = Q.denodeify(require('request'));
var chromecastHomeURL = 'https://clients3.google.com/cast/chromecast/home';
var initJSONStateRegex = /(JSON\.parse\('.+'\))\)\./;
var parseChromecastHome = function(htmlString) {
var matches = htmlString.match(initJSONStateRegex);
var JSONParse = matches[1];
var initState = eval(JSONParse); // I don't know why this is ok but JSON.parse fails.
var parsedBackgrounds = [];
for (var i in initState[0]) {
var backgroundEntry = {
url: initState[0][i][0],
author: initState[0][i][1]
};
parsedBackgrounds.push(backgroundEntry);
}
return parsedBackgrounds;
};
module.exports = function() {
return request(chromecastHomeURL).then(function(requestResult) {
return parseChromecastHome(requestResult[1]);
});
};