summaryrefslogtreecommitdiff
path: root/discover-url.coffee
diff options
context:
space:
mode:
authorYaohan Chen <yaohan.chen@gmail.com>2014-04-01 01:21:59 -0400
committerYaohan Chen <yaohan.chen@gmail.com>2014-04-01 01:31:53 -0400
commit23fcf1acc62e0f32f479c12c1916b2b1dd922199 (patch)
tree96ddaf09bb3cb901a9d9a0300bf2c14a37586de9 /discover-url.coffee
parentbb224302e1720bf7119c5b3a2e3c394ce989ecc7 (diff)
downloadhib-dlagent-23fcf1acc62e0f32f479c12c1916b2b1dd922199.tar.gz
hib-dlagent-23fcf1acc62e0f32f479c12c1916b2b1dd922199.zip
Support the new Humble Bundle page
Use PhantomJS to handle the dynamically generated page and captchas. Add options to specify the location of PhantomJS scripts and configuration file. Update README on requirements, usage, and debugging information. Update CHANGELOG.
Diffstat (limited to 'discover-url.coffee')
-rw-r--r--discover-url.coffee21
1 files changed, 21 insertions, 0 deletions
diff --git a/discover-url.coffee b/discover-url.coffee
new file mode 100644
index 0000000..cf8627d
--- /dev/null
+++ b/discover-url.coffee
@@ -0,0 +1,21 @@
+system = require 'system'
+[_, listing_page, filename, username, password] = system.args
+
+util = require './util'
+page = util.page
+
+page.open listing_page, (status) ->
+ util.log "Open listing page: #{status}"
+ util.handle_login_captcha ->
+ util.log 'Searching URLs...'
+ url = page.evaluate (filename) ->
+ # Characters in filename may need to be escaped for use in a selector
+ found = document.querySelector ".downloads.linux a[href*='#{filename}']"
+ found and found.getAttribute('href')
+ , filename
+ util.log "Found URL: #{url}"
+ if url
+ system.stdout.writeLine url
+ phantom.exit()
+ , username, password
+