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

Investigate need to clear youtube.js cache when rotating #44

Open
unixfox opened this issue Jan 5, 2025 · 5 comments
Open

Investigate need to clear youtube.js cache when rotating #44

unixfox opened this issue Jan 5, 2025 · 5 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@unixfox
Copy link
Member

unixfox commented Jan 5, 2025

image

@unixfox unixfox added bug Something isn't working enhancement New feature or request labels Jan 5, 2025
@unixfox unixfox changed the title Investigate need to clear youtube.js when rotating Investigate need to clear youtube.js cache when rotating Jan 5, 2025
@absidue
Copy link

absidue commented Jan 5, 2025

As those are my messages in the screenshot and the title of the issue implies that there is a misunderstanding of what I said. All you need to change is to add enable_session_cache: false when calling Innertube.create() that will make YouTube.js ignore the existing session cache and prevent it from writing a new one. You still want to keep the caching for the player.js for example.

If you really want to go with the approach of clearing the cache every time you rotate, there is no point creating the cache in the first place. The whole point of the cache is to remember things for the next time you call Innertube.create() so if you clear it each time before you call Innertube.create(), there will be nothing for it to read, because you deleted what the previous Innertube instance wrote to the cache.

@unixfox
Copy link
Member Author

unixfox commented Jan 5, 2025

Thanks for the message. Indeed that's much clearer.

It's just an issue to remind myself to investigate.

@artshevtsov
Copy link

So, about 4 days ago I completely rebuilt the images on the servers with cache cleanup (docker compose build --no-cache) and I again caught a moment when invidious-campanion doesn't return streamingData. This time I manually edited the main.ts file, added enable_session_cache: false to the await Innertube.create({ ... }) constructor, then ran the docker compose build && docker compose up command. Everything is working fine again. I'll wait another 4 days and report back with the results. I don't know exactly how to check that po_token and visitorData are not cached now. But supposedly they should be updated every 5 minutes now, if I understood everything correctly.

@unixfox
Copy link
Member Author

unixfox commented Jan 9, 2025

thanks @artshevtsov. there are multiple Innertube.create, which one did you modify?

@artshevtsov
Copy link

artshevtsov commented Jan 9, 2025

thanks @artshevtsov. there are multiple Innertube.create, which one did you modify?

The first one, at line 53, is then passed to the poTokenGenerate function, now I see that the Innertube client is being recreated inside it, so I need to modify it also at poTokenGenerate...
I think that I need to modify this lines
if (innertubeClient.session.po_token) {
innertubeClient = await Innertube.create({ retrieve_player: false });
}

like that:

if (innertubeClient?.session?.po_token) {
    innertubeClient = await Innertube.create({ retrieve_player: false, enable_session_cache: false });
}

but it's better to define clientOptions object somewhere at main.ts, import it at potoken.ts and use at poTokenGenerate function and merge it like this using a spread operator {...clientOptions, retrieve_player: false}

if (innertubeClient?.session?.po_token) {
    innertubeClient = await Innertube.create({...clientOptions,  retrieve_player: false});
}

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

No branches or pull requests

3 participants