summaryrefslogtreecommitdiff
path: root/discover-url.coffee
blob: 4dbc66b24ac3b0abe459c1d294fc2df16d5676f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
system = require 'system'
[_, listing_page, filename, username, password] = system.args

util = require './util'
page = util.page

util.log "Opening listing page..."
page.open listing_page, (status) ->
  util.log "Opened 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