Skip to content

Instantly share code, notes, and snippets.

@Ingramz
Forked from anonymous/castpaperer
Created July 16, 2014 11:42
Show Gist options
  • Save Ingramz/eccf10643a446709e1f8 to your computer and use it in GitHub Desktop.
Save Ingramz/eccf10643a446709e1f8 to your computer and use it in GitHub Desktop.
Quick and dirty script to download Chromecast wallpapers.
var https = require('https');
var fs = require('fs');
var request = require('request');
var crypto = require('crypto');
function nothing(){}
function download(uri, filename, callback)
{
fs.exists(filename, function(exists)
{
if(!exists)
{
request.head(uri, function(err, res, body)
{
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
}
});
}
https.get("https://clients3.google.com/cast/chromecast/home", function(response)
{
var str = "";
response.on('data', function(chunk)
{
str += chunk;
});
response.on('end', function()
{
var sub = str.substring(str.indexOf("JSON.parse"));
sub = sub.substring(0, sub.indexOf(")")+1);
var pictures = eval(sub);
fs.mkdir("pictures", function() {});
for(var i=0;i<pictures[0].length;i++)
{
var shasum = crypto.createHash('sha1');
// Google scales pictures to 1280x720, this will request a 1920x1080 resize
var url = pictures[0][i][0].replace("s1280-w1280-c-h720-k-no", "s1920-w1920-c-h1080-k-no");
shasum.update(url);
download(url, "pictures/"+shasum.digest("hex")+".jpg", nothing);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment