Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] API broke again #31

Closed
Eniterusx opened this issue Nov 15, 2024 · 5 comments
Closed

[BUG] API broke again #31

Eniterusx opened this issue Nov 15, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@Eniterusx
Copy link

Looks like howlongtobeat changed the api yet again, despite them changing it like 2 days ago...

First of all, they returned to the api_key solution, however this time it consists of two concats instead of one.
/api/search/".concat("7b0f03b2").concat("54cc3099")
Here's the quick code I whipped to make the send_website_request_getcode retriever work again:

if script_resp.status_code == 200 and script_resp.text is not None:
    pattern = r'\/api\/search\/"(?:\.concat\("[^"]*"\))*'
    matches = re.findall(pattern, script_resp.text)
    matches = str(matches).split('.concat')
    matches = [re.sub(r'["\(\)\[\]\']', '', match) for match in matches[1:]]
    key = ''.join(matches)
    return key

Also the headers and payload changed ever so slightly. Those worked for me:

headers = {
    'Host': 'howlongtobeat.com',
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0',
    'Accept': '*/*',
    'Accept-Language': 'en-US,en;q=0.5',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Referer': 'https://howlongtobeat.com',
    'Content-Type': 'application/json',
    'Origin': 'https://howlongtobeat.com',
    'Connection': 'keep-alive'
}

payload = {
    'searchType': "games",
    'searchTerms': game_name.split(),
    'searchPage': page,
    'size': 20,
    'searchOptions': {
        'games': {
            'userId': 0,
            'platform': "",
            'sortCategory': "popular",
            'rangeCategory': "main",
            'rangeTime': {
                'min': 0,
                'max': 0
            },
            'gameplay': {
                'perspective': "",
                'flow': "",
                'genre': "",
                'subGenre': ""
            },
            'modifier': search_modifiers.value,
        },
        'users': {
            'sortCategory': "postcount"
        },
        'lists': {
            'sortCategory': "follows"
        },
        'filter': "",
        'sort': 0,
        'randomizer': 0
    }
}

I guess the freshly added solution should still be kept, in case they change the api yet again. Possibly first try the api key, then the custom userId in case the key doesn't work?

@ScrappyCocco
Copy link
Owner

It's starting to get a little bothering that they keep changing the format, I'll have a look as soon as I have time guys, sorry for the wait

@thebobbyboy420
Copy link

i give up with this game of cat and mouse....screw hltb its clear they do not like your project and this will keep on happening...

@rarDevelopment
Copy link
Contributor

rarDevelopment commented Nov 16, 2024

This is where I end up when I'm trying to find out why my code broke. I'm not even using this library (my stuff isn't in Python), I'm just playing the same cat and mouse game 😅 godspeed, keep fighting the good fight

@ScrappyCocco
Copy link
Owner

Hello everyone, the issue should be fixed in 1.0.11
Hopefully it will work for a while now
If it breaks again and you already investigated the fix feel free to open a PR to a different branch so you can submit it yourself and maybe we edit it together (for example @Eniterusx )
Thanks everyone

PS: It would be nice to find out how the Windows Xbox App gets data, but with a web debugger app it doesn't seems to make requests to hltb so they probably already gather data on their side

@godver3
Copy link

godver3 commented Nov 17, 2024

Confirmed working - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants