Created
January 14, 2016 10:50
-
-
Save marc0der/1fc036ba6ed164de0a42 to your computer and use it in GitHub Desktop.
Mines Chromecast Images
This file contains hidden or 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
#!/usr/bin/env groovy | |
@Grab("org.codehaus.geb:geb-core:0.7.2") | |
@Grab("org.seleniumhq.selenium:selenium-chrome-driver:2.48.2") | |
import geb.* | |
import java.security.MessageDigest | |
import static java.net.URLDecoder.decode | |
def images = new HashSet() | |
def userHome = System.getProperty('user.home') | |
def pictureFolder = "${userHome}/Dropbox/Images/ChromecastHD" | |
def history = new File("${userHome}/.chromecast") | |
if(history.exists()) history.eachLine { images.add it } | |
println "Loaded up ${images.size()} images from ${history.toString()}" | |
System.setProperty('webdriver.chrome.driver', "${userHome}/bin/chromedriver") | |
System.setProperty('geb.env', 'phantomjs') | |
def md5( obj ) { | |
def hash = MessageDigest.getInstance( 'MD5' ).with { | |
obj.eachByte( 8192 ) { bfr, num -> | |
update bfr, 0, num | |
} | |
it.digest() | |
} | |
new BigInteger( 1, hash ).toString( 16 ).padLeft( 32, '0' ) | |
} | |
def correctResolution = { | |
it?.replace('s1280', 's2880').replace('w1280', 'w2880').replace('h720', 'h1620') | |
} | |
def download = { address -> | |
def fullFilename = "/tmp/${UUID.randomUUID()}.jpg" | |
def file = fullFilename as File | |
def fos = new FileOutputStream(fullFilename) | |
def out = new BufferedOutputStream(fos) | |
out << new URL(address).openStream() | |
out.flush() | |
out.close() | |
file | |
} | |
Browser.drive { | |
go "https://clients3.google.com/cast/chromecast/home" | |
while(true) { | |
def src = $(".S9aygc-AHe6Kc")."@ng-src" | |
def imageURL = correctResolution(decode(src)) | |
if(imageURL) { | |
def file = download(imageURL) | |
def hash = md5(file) | |
if(images.contains(hash)) { | |
file.delete() | |
} else { | |
def fileName = "${pictureFolder}/${hash}.jpg" | |
def newFile = fileName as File | |
newFile.bytes = file.bytes | |
images.add(hash) | |
history.append("${hash}\n") | |
println("(${images.size()}) New image found and stored: file://${fileName}") | |
} | |
} | |
sleep 120000 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment