diff options
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | README | 32 | ||||
-rw-r--r-- | discover-url.coffee | 24 | ||||
-rwxr-xr-x | discover-url.py | 23 | ||||
-rwxr-xr-x | hib-dlagent | 14 | ||||
-rwxr-xr-x | install.sh | 5 | ||||
-rw-r--r-- | phantomjs-config.json | 5 | ||||
-rw-r--r-- | util.coffee | 71 |
8 files changed, 38 insertions, 139 deletions
@@ -1,3 +1,6 @@ +Version 0.7 - 2015/04/16 + * Handles the new Humble Bundle page again using humblebundle-python + Version 0.6 - 2014/04/01 * Handles the new Humble Bundle page using PhantomJS @@ -15,39 +15,23 @@ It also manages a storage directory where already downloaded file can be found. Installation and Usage ====================== -This utility currently requires PhantomJS in order to extract links on Humble -Bundle's dynamically generated webpages. It also uses 'display', part of -ImageMagick, to handle any captchas. (It does not solve captchas for you, but -only displays a screenshot of the web page and asks you to enter the answers.) +This utility currently requires humblebundle-python to query HumbleBundle's API. It uses curl to download the file, or can simply provide the URL needed to download the file so a different HTTP downloader such a Wget can be used. -To run hib-dlagent without installating it, add parameters '-S. -c.', which -tells it to look for scripts and the configuration file in the current -directory. +To run hib-dlagent without installating it, add parameters '-S.', which +tells it to look for helper script(s) in the current directory. -By default hib-dlagent assumes the .coffee scripts are installed in -/usr/share/hib-dlagent, and the .json configuration file is installed in -/etc/hib-dlagent. The provided install.sh will install files into these -locations. If they are installed elsewhere, it is necessary to either run -hib-dlagent with the corresponding -S and -c parameters, or edit the variables +By default hib-dlagent assumes the helper script is installed in +/usr/share/hib-dlagent. The provided install.sh will install files into this +location. If they are installed elsewhere, it is necessary to either run +hib-dlagent with the corresponding -S parameters, or edit the variables SCRIPT_PATH and CONFIG_PATH in hib-dlagent. To use as a DLAGENT for the 'hib' scheme, you can modify makepkg.conf: DLAGENTS=(... - 'hib::/usr/bin/hib-dlagent -k 1a2b3c -o %o %u' + 'hib::/usr/bin/hib-dlagent -u user@example.org -o %o %u' ...) Run with the -h argument for more information. -Troubleshooting -=============== - -Extracting URLs from Humble Bundle's mostly dynamically-generated website can be -error-prone, and time consuming. Currently it can take about 20 seconds for the -script to run. If the script fails or gets stuck, it may help to turn on logging -by with the -l option. - -It is also possible to turn on PhantomJS's debug output with '-j --debug=true', -but note that this output is very verbose and targeted to developers, and it may -contain your Humble Bundle login information in plain text. diff --git a/discover-url.coffee b/discover-url.coffee deleted file mode 100644 index bd64ffd..0000000 --- a/discover-url.coffee +++ /dev/null @@ -1,24 +0,0 @@ -system = require 'system' -[_, listing_page, filename, username] = system.args -password = system.env.PASSWORD -system.env.PASSWORD = '' - -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?.getAttribute('href') - , filename - util.log "Found URL: #{url}" - if url - system.stdout.writeLine url - phantom.exit() - , username, password - diff --git a/discover-url.py b/discover-url.py new file mode 100755 index 0000000..b60d608 --- /dev/null +++ b/discover-url.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python + +import humblebundle +import sys +import os + +filename = sys.argv[2] +username = sys.argv[3] +password = os.environ['PASSWORD'] + +client = humblebundle.HumbleApi() +client.login(username, password) + +order_list = client.order_list() +for order in order_list: + for subproduct in order.subproducts: + for download in subproduct.downloads: + for download_struct in download.download_struct: + url = download_struct.url.web + if filename in url: + print(url) + exit() + diff --git a/hib-dlagent b/hib-dlagent index 2d293cd..55f7f17 100755 --- a/hib-dlagent +++ b/hib-dlagent @@ -19,9 +19,7 @@ STORAGE= discover_url() { local LISTING_PAGE="$1" # Running a new shell in order to split PHANTOM_JS_OPTIONS into multiple arguments - PASSWORD="$PASSWORD" \ - sh -c "phantomjs --config='$CONFIG_PATH'/phantomjs-config.json $PHANTOM_JS_OPTIONS \ - '$SCRIPT_PATH'/discover-url.coffee '$LISTING_PAGE' '$FILE' '$USERNAME'" + PASSWORD="$PASSWORD" "$SCRIPT_PATH"/discover-url.py "$LISTING_PAGE" "$FILE" "$USERNAME" } usage() { @@ -41,10 +39,8 @@ Options: -s Print URL to stdout instead of downloading. Incompatible with -d -u <user> Use user to login. Search account's files. If specified multiple times, the last is used - -S <dir> Directory where PhantomJS scripts are located. + -S <dir> Directory where helper scripts are located. -c <dir> Directory where configuration files are located. - -j <options> Additional options passed to PhantomJS - -l Turn on logging If you specify -u, then all of that account's bundles are searched. If a key is associated with a HIB account then you must use -u/-p, since that key only works @@ -134,12 +130,6 @@ main() { c) CONFIG_PATH="$OPTARG" ;; - j) - PHANTOM_JS_OPTIONS="$OPTARG" - ;; - l) - export LOG=1 - ;; esac done @@ -2,6 +2,5 @@ install -D -m755 hib-dlagent "$DEST/usr/bin/hib-dlagent" install -D -m644 README "$DEST/usr/share/doc/hib-dlagent/README" -install -D -m644 discover-url.coffee "$DEST/usr/share/hib-dlagent/discover-url.coffee" -install -D -m644 util.coffee "$DEST/usr/share/hib-dlagent/util.coffee" -install -D -m644 phantomjs-config.json "$DEST/etc/hib-dlagent/phantomjs-config.json" +install -D -m644 discover-url.py "$DEST/usr/share/hib-dlagent/discover-url.py" + diff --git a/phantomjs-config.json b/phantomjs-config.json deleted file mode 100644 index f32e571..0000000 --- a/phantomjs-config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "webSecurityEnabled": false, - "ignoreSslErrors": true, - "diskCacheEnabled": true, -} diff --git a/util.coffee b/util.coffee deleted file mode 100644 index e0ddb33..0000000 --- a/util.coffee +++ /dev/null @@ -1,71 +0,0 @@ -system = require('system') - -# prints a log message if the LOG environment variable is set -if system.env.LOG? - exports.log = log = (message) -> - system.stderr.writeLine "#{new Date().toString()} #{message}" -else - exports.log = log = -> - -# prints a message to stderr, reads a line of input, and returns the input -exports.ask = ask = (message) -> - system.stderr.write message - system.stdin.readLine() - -# a page that directs its console messages to exportss.log -exports.page = page = require('webpage').create() -page.onConsoleMessage = log - -child_process = require('child_process') - -# displays a screenshot of the page, and returns the 'display' process object -exports.display_screenshot = display_screenshot = -> - # FIXME use mktemp, or write to display process directly - screenshot = '/tmp/hib-dlagent-phantomjs.png' - page.render screenshot - child_process.spawn 'display', [screenshot] - -# checks if there is a login form, and if so, completes it and returns true -exports.handle_login = handle_login = (username, password) -> - if page.evaluate(-> document.querySelector 'input[name="username"]') - log 'Entering login information...' - page.evaluate (username, password) -> - username_box = document.querySelector 'input[name="username"]' - password_box = document.querySelector 'input[name="password"]' - username_box?.value = username - password_box?.value = password - (username_box or password_box)? - , username, password - -# checks if there is captcha, and if so, handles it and returns true -exports.handle_captcha = handle_captcha = -> - if page.evaluate(-> document.querySelector '#recaptcha_response_field') - log 'Humble Bundle wants you to solve a captcha. Displaying screenshot...' - display_process = display_screenshot() - input = ask 'Enter the captcha solution, or press Enter to get a new challenge: ' - display_process.kill() - - page.evaluate (input)-> - if input is '' - Recaptcha.reload() - else - captcha_box = document.querySelector '#recaptcha_response_field' - captcha_box?.value = input - , input - -# handles login/captcha, repeating if necessary, and performs the action -exports.handle_login_captcha = handle_login_captcha = (action, username, password) -> - entered_login = handle_login(username, password) - entered_captcha = handle_captcha() - if entered_login or entered_captcha - # Entered information, submit and check for captcha/login again after load finishes - log 'Submitting login information and/or captcha response...' - page.onLoadFinished = -> handle_login_captcha action, username, password - page.evaluate -> - # FIXME make sure we're submitting the right form - form = document.querySelector('form') - form?.submit() - else - log 'Logged in...' - action() - |