tristan-tyler / Humbler-Unbundler

Grabs keys from Humble Bundle and redeems them on Steam
MIT License
7 stars 1 forks source link

Currently does not seem to redeem - stops at registerkey page #1

Open MSDNAndi opened 1 year ago

MSDNAndi commented 1 year ago

Currently the script does not seem to redeem codes.

Lands on "registerkey" page, does not fill anything, does not select subscriber agreement agreement.

image

(used firefox).

I have a very large library with a mix of monthly bundles (some not even opened), not-requested, and requested keys.

It seems that it would be beneficial to wait after login until the browser had a chance to load the full library.

tristan-tyler commented 1 year ago

If you open the browser console (F12 for firefox) and go to the network tab, it will be hitting the frontend api used by this page. If the output is nothing please let me know. If practical, send a screenshot of the network tab from as early on in the process as you can as well as a screenshot of the python output.

I should note that even though the agreement isn't checked you are implicitly agreeing by redeeming games.

MSDNAndi commented 1 year ago

Chrome version failed for me btw. Firefox, I see indeed it made some requests. I think I was thrown off by the long delay in retry counts.

I am not sure if you start by the oldest or the newest key in the library - maybe it would be nice to have the alternate option.

Haven't a successful redeem so far since I have 1000s of games in the library but I see a "already redeemed" message for some now. Will let it run longer and report back.

MSDNAndi commented 1 year ago

Also, if you have multiple copies of the same game, which happens if you get a lot of bundles- besides of "already redeemed" there is the "you already own" status, I think. I do not know the status code though. Would be nice to capture those separately since those could be given away to folks.

tristan-tyler commented 1 year ago

If in your output you see "The following response was not handled" that might give me the code I need. I am also unsure what code that would be and I don't have anything to test with unfortunately.

MSDNAndi commented 1 year ago

It stopped after a while and I had to re-login. Made 248 requests until then, 246 of those "already redeemed", 1 "successfully redeemed", and one "owned by a different account" - have to look into that if I was giving away the key or if it was guessed by someone and stolen.

MSDNAndi commented 1 year ago

Got this in the log, but not sure which key it is. The following response was not handled {'success': 21}, could make sense to store the unhandled keys with the code and the product name somewhere.

For the "other software required", it could make sense to put them in a re-try queue to try after ALL keys that have been retrieved were tried. If you get DLC and the main software in a bundle or across various bundles, if it tries to activate it in the wrong order. To take that thought further, it could make sense to extract all keys first, write them (add them) to a file of keys to try, then work on that file. And on a restart, optionally process the file first before trying to log into humble bundle at all.

tristan-tyler commented 1 year ago

Sorry, I'm going to leave the more complex logic to the user. I'm intentionally keeping it as simple as possible. If you re-run the script and look at the request made to the redeem api you can get the key in question and manually figure out what is going on. I also updated the script to create logs (which outputs keys in debug mode) if you'd like to run that instead.

In the updated script I actually made it NOT store the keys that need other software anymore, so that if one were to run it again it would redeem it if you obtained the required software.

Thank you for all your feedback

MSDNAndi commented 1 year ago

Fair enough, if someone wants to improve further they can also fork or make a pull request.

MSDNAndi commented 1 year ago

It's not really an issue at this point, and did not want to create one for it, hence adding it as feedback as something to perhaps have an eye on: saw an output sequence in the terminal that I cannot quite explain, where Terminal output and Log File differ. As if the Terminal output ignored some output. (I replaced the actual game names with AAAA, BBBB, ....) Terminal:

Checking for key in .used_keys
Attempting to redeem key
AAAA is already redeemed to this account
**Checking for key in .used_keys
Checking for key in .used_keys**
Attempting to redeem key
Steam is disallowing redeem due to too many requests, waiting for a while (10 min) and will continue...
Writing keys to file
Finished writing keys to file

Compare with the log file:

03:12:07,329 root INFO Checking for key in .used_keys
03:12:07,329 root INFO Attempting to redeem key
03:12:07,497 root INFO AAAA is already redeemed to this account
03:12:12,509 root INFO Checking for key in .used_keys
03:12:12,509 root INFO Attempting to redeem key
03:12:12,802 root INFO BBBB is already redeemed to this account
03:12:17,810 root INFO Checking for key in .used_keys
03:12:17,811 root INFO Attempting to redeem key
03:12:18,7 root INFO CCCC is already redeemed to this account
03:12:23,13 root INFO Checking for key in .used_keys
03:12:23,14 root INFO Attempting to redeem key
03:12:23,292 root INFO Steam is disallowing redeem due to too many requests, waiting for a while (10 min) and will continue...
03:12:23,292 root INFO Writing keys to file
03:12:23,294 root INFO Finished writing keys to file
MSDNAndi commented 1 year ago

Update - still going strong, according to my own counters processed 1320 of 1803 revealed steam keys. have to check what's the deal with the hand full of unrevealed keys when everything else is done. Expect to be done in the next 2-3 days (worst case, 10 keys per hour, 24 hours per day, occasional restart... so assume processing 200 keys per day)

tristan-tyler commented 1 year ago

Holy CRAP lol. Is the occasional restart because of the script failing? I'm going to look into the logging weirdness this weekend and see what's up.

MSDNAndi commented 1 year ago

The script failing is because it does e.g. crash when a non-JSON response is received (you don't handle exceptions there). e.g. when the login expired (authentication cookie), or when the internet connection goes down. Also just ran into a timeout in "attempting to redeem key" just now. Have to look if there was something funky going on.

tristan-tyler commented 1 year ago

Understood. I'll see if I can work on timeout/login expiration handling as well... though, it may not be useful to you by the time I add it.

MSDNAndi commented 1 year ago

A few "reveal key" observations. The script does not seem to trigger the action in the scenario when the key is temporary exhausted. e.g. when clicking in the UI you would get "Keys are temporarily exhausted for this product As soon as we receive more keys, we will add them to this page and send you an email. Steam will not provide extra giftable copies of games you already own."

Also it does not check for expired keys.

There are a few more edge cases, eg where the web UI still lets you click to reveal the key, but the information says that no keys can be provided and to contact customer support (publisher change).

MSDNAndi commented 1 year ago

If you want to avoid re-login into Humble Bundle, here a suggestion. (Lazy suggestion, you don't need all cookies.)

import pickle
...
#Logging in - have not tested cookie expiration.
logging.info("Initializing Browser")
driver = Browser()
logging.info("Opening login page for humble bundle")
driver.get("https://www.humblebundle.com/login")

## if cookies.pkl exists, load cookies
if path.exists("cookies.pkl"):
    logging.info("Loading cookies")
    cookies = pickle.load(open("cookies.pkl", "rb"))
    for cookie in cookies:
        logging.info("cookie domain" + cookie['domain'])
        driver.add_cookie(cookie)
    driver.get("https://www.humblebundle.com/home/library")

#After logging in:
#get cookies
cookies=driver.get_cookies()
pickle.dump(cookies, open("cookies.pkl","wb"))
MSDNAndi commented 1 year ago

For Steam this is what I came up with.

logging.info("Opening login page for Steam")
driver.get("https://steamcommunity.com/login/home/")

if path.exists("steamcookies.pkl"):
    logging.info("Loading cookies")
    driver.get(f"https://store.steampowered.com")
    cookies = pickle.load(open("steamcookies.pkl", "rb"))
    for cookie in cookies:
        logging.info("cookie domain: " + cookie['domain'])
        driver.add_cookie(cookie)
    driver.get(f"https://store.steampowered.com/account/registerkey")

logging.info("Waiting for user input")
input("Once logged in, Press Enter:")
cookies=driver.get_cookies()
pickle.dump(cookies, open("steamcookies.pkl","wb"))
driver.get(f"https://store.steampowered.com/account/registerkey")