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

Fix for newly broken #16

Open
felixhirschfeld opened this issue Nov 22, 2024 · 22 comments
Open

Fix for newly broken #16

felixhirschfeld opened this issue Nov 22, 2024 · 22 comments

Comments

@felixhirschfeld
Copy link

felixhirschfeld commented Nov 22, 2024

Hey everyone. Unfortunately I don't have a development environment for Decky plugins so I'll just paste some code here.

This should fix the plugin theoritically:

async function fetchSearchKey() {
    try {
        const url = 'https://howlongtobeat.com';
        const response = await fetchNoCors(url);

        if (response.status === 200) {
            const html = await response.text();
            const parser = new DOMParser();
            const doc = parser.parseFromString(html, 'text/html');
            const scripts = doc.querySelectorAll('script');

            for (const script of scripts) {
                if (script.src.includes('_app-')) {
                    const scriptUrl = url + new URL(script.src).pathname;
                    const scriptResponse = await fetchNoCors(scriptUrl);

                    if (scriptResponse.status === 200) {
                        const scriptText = await scriptResponse.text();
                        
                        // Updated pattern to match multiple .concat calls
                        const pattern =
                            /\/api\/search\/"\.concat\("([a-zA-Z0-9]+)"\)\.concat\("([a-zA-Z0-9]+)"\)/;
                        const matches = scriptText.match(pattern);

                        if (matches && matches[1] && matches[2]) {
                            // Combine key fragments from matches
                            const apiKey = `${matches[1]}${matches[2]}`;
                            console.log('HLTB API Key:', apiKey);
                            return apiKey;
                        }
                    }
                }
            }

            console.error('HLTB - failed to get API key!');
        } else {
            console.error('HLTB', response);
        }
    } catch (error) {
        console.error('Error fetching HLTB API key:', error);
    }

    return null;
}

@subnebula
Copy link

Hey @felixhirschfeld

Thanks for this code! I've tested it on my Deck and it looks to work and I've made a PR for the changes (#17)

@felixhirschfeld
Copy link
Author

@subnebula cool. Glad it still works I thought they changed it again.

@subnebula
Copy link

Potentially, I did have to modify the request body as well to get the queries working.

I will test over the next couple of days and see if the API calls still work, maybe they have something else that changes daily as well

@danigarvire
Copy link

How does one use this code? Is it just via konsole on linux? Is it more complicated? Please provide the steps for a newbie!

@subnebula
Copy link

@danigarvire not that simple I'm afraid. Decky plugins require a bit of experience working with node. If you don't already know how to develop and build a node app it is likely a bit too complicated and not something I can provide steps for.

You'd be best to wait until the fix is merged in and then you can install it from the decky store as usual.

@rastorguevia
Copy link

@subnebula hi, can you build it for us? and pack it to zip? so we can install it from decky manually?

@danigarvire
Copy link

@subnebula Oh! After googling for a little while i understand that it might be a bit too hard for someone inexperienced. Hopefully the newly broken HLTB can be fixed! Please update us and let us know if we can help in any way!

@Baggio94
Copy link

Hello,
This is my favorite plugin and I can think of many others.
Do you think you will be able to publish a fix soon?
Thank you very much

@Pirateguybrush
Copy link

@subnebula I manually edited /home/deck/homebrew/plugins/hltb-for-deck/dist/index.js to incorporate your changes, and it worked for a few days. But it seems to be broken again.

@subnebula
Copy link

Yep, looks like they have changed the api again, the requests now go to /find instead of /search, and there might be a bunch of other changes as well. In my brief testing just now I've not been able to make a successful api call to the new endpoint. Looks like we're out of luck with this fix

@morwy
Copy link

morwy commented Dec 14, 2024

I opened new PR #18 for syncing up with the latest HLTB API changes. I had to peek on ScrappyCocco/HowLongToBeat-PythonAPI#35 PR to find new changes they added to API.

@FF7CloudsNobody
Copy link

Can confirm that PR 18 works after editing the existing json to match the changes

@Baggio94
Copy link

Can confirm that PR 18 works after editing the existing json to match the changes

Hello
I tried to make the changes, but I couldn't manage since it's all new to me.
Could you send me the entire text or the json file itself?

Thank you

@gwynbleidddracke
Copy link

gwynbleidddracke commented Dec 21, 2024

@Baggio94 You can take the zip file in the PR #18 and use it to install the plug in with decky in dev mod, it's easier than editing the json.

It work for me.

@morwy
Copy link

morwy commented Dec 21, 2024

Can confirm that PR 18 works after editing the existing json to match the changes

Hello I tried to make the changes, but I couldn't manage since it's all new to me. Could you send me the entire text or the json file itself?

Thank you

I added ZIP and TAR archives to the MR. You can try installing them via Developer Mode of Decky (Decky Settings -> General -> Enable Developer Mode. Then in Settings go to Developer -> Install Plugin from ZIP File and select the ZIP archive. After installing go to Plugins in Settings, select HLTB for Desk settings and then Reload).

@morwy
Copy link

morwy commented Dec 21, 2024

I do not mind taking responsibility for this plugin, since I like it and use it a lot on Steam Deck.
However, I am not sure if I shall fork this repository under a new name or under the same name and overwrite a link in https://github.com/SteamDeckHomebrew/decky-plugin-database. Or shall I continue pushing PRs to this repository?

@safijari, your opinion is greatly appreciated regarding the matter.

@Baggio94
Copy link

It worked !!
Thanks a lot 🙏🏼

@danigarvire
Copy link

Does this mean we can update the plug in now and it will work?

@boivinx7
Copy link

I do not mind taking responsibility for this plugin, since I like it and use it a lot on Steam Deck. However, I am not sure if I shall fork this repository under a new name or under the same name and overwrite a link in https://github.com/SteamDeckHomebrew/decky-plugin-database. Or shall I continue pushing PRs to this repository?

@safijari, your opinion is greatly appreciated regarding the matter.

You should just fork and republish, this fork seems dead

@morwy
Copy link

morwy commented Dec 29, 2024

The API has changed again and PR #18 stopped working while still being not merged.

I will publish future fixes under my fork: https://github.com/morwy/hltb-for-deck/releases.
It is simply more convenient for me rather than waiting for the PRs to approved and merged.

@syrnyk
Copy link

syrnyk commented Dec 29, 2024

The API has changed again and PR #18 stopped working while still being not merged.

I will publish future fixes under my fork: https://github.com/morwy/hltb-for-deck/releases. It is simply more convenient for me rather than waiting for the PRs to approved and merged.

@morwy Thanks for the fix, it works well (for now...) If the API keeps changing this often, changing the name manually everytime is not very efficient. Using "//api/[a-zA-Z]*" or something similar might be more robust when checking for the pattern in the initial script. It will not cover possible changes they might make on the concatenation part that contains the key, but it'll at least help for future url name changes. The actual API name could be retrieved using the aforementioned pattern in the initial script and re-used dynamically when needed to get game data instead of copying manually the api name everywhere.

@syrnyk
Copy link

syrnyk commented Dec 29, 2024

@morwy And since I was able to test the plugin for the first time thanks to your fix, I found a small bug on some games containing special chars. I added the details there if you feel like taking a look. I added some input that might be useful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests