[YouTube / Self-Hosting] Cookie question
Question
Has anyone succeeded in setting up own instance with custom cookie for YouTube?
What I tried
Self hosted instance behind residential proxy, see Instance configuration.
I exported cookies from private browser session using this fork https://github.com/sertraline/Get-cookies.txt-LOCALLY-Cobalt?tab=readme-ov-file
And got a cookies.json with something like
{
"youtube":[
"PREF=xxxxxxxxx;SOCS=xxxxxxxxx;VISITOR_INFO1_LIVE=xxxxxxxxx;__Secure-1PSIDTS=xxxxxxxxxxx;__Secure-3PSIDTS=xxxxxxx;<OTHER_COOKIES>"
]
}
When I try to download any video using this setup I receive
{
"status": "error",
"error": {
"code": "error.api.youtube.api_error"
}
}
Container output
cobalt API ^ω^
~~~~~~
version: 10.9.4
commit: 4b9644ebdfbfe7bc6f7ec2d476692e3619cb59bd
branch: main
remote: imputnet/cobalt
start time: Fri, 02 May 2025 20:15:46 GMT
~~~~~~
url: <OMIT>
port: 9000
[✓] api keys loaded successfully!
[✓] cookies loaded successfully!
[✓] poToken & visitor_data loaded successfully!
If I remove cookies (comment out COOKIE_PATH) - everything works just fine. Am I missing something?
Note: I used the same approach with yt-dlp and everything has worked. So I assume there's an issue in youtube.js or the cookie handling in cobalt, not sure.
Instance configuration
services:
cobalt-api:
image: ghcr.io/imputnet/cobalt
init: true
read_only: true
restart: unless-stopped
container_name: cobalt-api
ports:
- 9000:9000/tcp
environment:
API_URL: "<OMIT>"
API_KEY_URL: "file:///keys.json"
API_AUTH_REQUIRED: 1
API_EXTERNAL_PROXY: "<OMIT>"
YOUTUBE_SESSION_SERVER: "http://host.docker.internal:8080/token"
COOKIE_PATH: "/cookies.json"
labels:
- com.centurylinklabs.watchtower.scope=cobalt
volumes:
- ./keys.json:/keys.json:ro
- ./cookies.json:/cookies.json:ro
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
yt-session-generator:
condition: service_started
watchtower:
image: ghcr.io/containrrr/watchtower
restart: unless-stopped
command: --cleanup --scope cobalt --interval 900 --include-restarting
volumes:
- /var/run/docker.sock:/var/run/docker.sock
yt-session-generator:
image: ghcr.io/imputnet/yt-session-generator:webserver
init: true
restart: unless-stopped
container_name: yt-session-generator
ports:
- 8080:8080/tcp
according to the latest commit logs YouTube cookies don't work anymore, I'm also using a residential proxy and get api.fetch.fail errors when using a session server hosted on my own computer so I'm also actively looking for a solution.
I'm also using a residential proxy and get api.fetch.fail errors when using a session server hosted on my own computer so I'm also actively looking for a solution.
I see that original session generator is deprecated as YouTube has changed the validation. https://github.com/iv-org/youtube-trusted-session-generator?tab=readme-ov-file#tool-is-deprecated
I'm also using a residential proxy and get api.fetch.fail errors when using a session server hosted on my own computer so I'm also actively looking for a solution.
I see that original session generator is deprecated as YouTube has changed the validation. https://github.com/iv-org/youtube-trusted-session-generator?tab=readme-ov-file#tool-is-deprecated
you just saved my life. invidious companion works with my proxy!
@ansharyan03 do you mind sharing the instance configuration you used?
@ansharyan03 do you mind sharing the instance configuration you used?
i'm actually no longer using the same configuration since we have to use invidious companion now, i'm backlogged with other stuff but currently trying to figure out how to load in bytes from the mp4 audio in a reasonable amount of time since the links you get from invidious companion seem to be optimal for loading chunks in parallel which i'm trying to figure out.
using invidious companion with a server api key and my https url for my proxy as the proxy environment variable, running deno dev server for now but will look into building the container with docker compose later when i actually figure out the link streaming
info here https://github.com/iv-org/invidious-companion/wiki
@ansharyan03 do you mind sharing the instance configuration you used?
before i had a session server and a proxy configured with env variables in my docker compose and the proxy would make it fail and i was tunneling my session server with http using ngrok to help my teammates access it temporarily
I had a quick look on companion but didn't find any easy way to get po_token, so there is no direct replacement session generator -> companion.
Another (potentially) working replacement for session generator is https://github.com/Brainicism/bgutil-ytdlp-pot-provider. It's mentioned on yt-dlp guide on PO token and provides docker container with API for PO Token generation. The only thing - it needs VISITOR_DATA / video id to correctly generate token. So might also not work without an additional changes on cobalt side.
same issue
Since the original session generator is deprecated, does anyone know what cobat tools is currently using to get these PO tokens? Or who we can ask to figure this out?
cobalt is still using the same session generator, you can use our fork without any changes, if you wish: https://github.com/imputnet/yt-session-generator
The YT Session Generator seems not to be working perfectly, though.
services:
cobalt-api:
image: ghcr.io/imputnet/cobalt:11
init: true
read_only: true
restart: unless-stopped
container_name: cobalt
ports:
- 8088:9000/tcp
environment:
API_URL: "https://cobalt.website.com/"
API_AUTH_REQUIRED: 1
API_KEY_URL: "file:///keys.json"
TURNSTILE_SITEKEY: "0xxxxxxxxxxxxxxxxxxxxxxP" # use your key
TURNSTILE_SECRET: "0xxxxxxxxxxxxxxxxxxxxxx4" # use your key
JWT_SECRET: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
YOUTUBE_SESSION_SERVER: "http://host.docker.internal:8089/token"
COOKIE_PATH: "/cookies.json"
labels:
- com.centurylinklabs.watchtower.scope=cobalt
volumes:
- ./cookies.json:/cookies.json
- ./keys.json:/keys.json:ro
extra_hosts:
- "host.docker.internal:host-gateway"
depends_on:
yt-session-generator:
condition: service_started
watchtower:
image: ghcr.io/containrrr/watchtower
restart: unless-stopped
command: --cleanup --scope cobalt --interval 900 --include-restarting
volumes:
- /var/run/docker.sock:/var/run/docker.sock
yt-session-generator:
image: ghcr.io/imputnet/yt-session-generator:webserver
init: true
restart: unless-stopped
container_name: yt-session-generator
ports:
- 8089:8080/tcp
With the above setup i keep getting this error
yt-session-generator | 2025/05/29 21:48:30.487 [extractor] [INFO] update was succeessful
yt-session-generator | 2025/05/29 21:53:30.543 [extractor] [INFO] update started
yt-session-generator | 2025/05/29 21:53:34.606 [extractor] [INFO] new token: {"updated": 1748555614, "potoken": "MnSgFL75bMJwSqAsz5vDWEk6ePgSajdHGZguip0H1kHbhFoYsq9aoG0oDTdzQE_7A-Ib23nMKhX7x_3zfqzVeo6kN2Og76TI2cqx2qhqR15W4rHwpBmx4o9EsHYdnD7z_sEfazrQRSUjtcnHrBxrV2myHPrkYA==", "visitor_data": "CgtjeVcyTERsYmRTUSjcruPBBjIKCgJHQhIEGgAgMQ%3D%3D"}
yt-session-generator | 2025/05/29 21:53:34.607 [extractor] [INFO] update was succeessful
cobalt |
cobalt | cobalt API ^ω^
cobalt | ~~~~~~
cobalt | version: 11.0.1
cobalt | commit: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
cobalt | branch: main
cobalt | remote: imputnet/cobalt
cobalt | start time: Thu, 29 May 2025 21:33:08 GMT
cobalt | ~~~~~~
cobalt | url: https://website.com/
cobalt | port: 9000
cobalt |
cobalt | [✓] internal tunnel handler running on 127.0.0.1:46297
cobalt | [✓] api keys loaded successfully!
cobalt | [✓] cookies loaded successfully!
cobalt | [!] Failed loading poToken & visitor_data at 2025-05-29T21:33:18.557Z.
cobalt | Error: TypeError: fetch failed
cobalt | at node:internal/deps/undici/undici:13510:13
cobalt | at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
cobalt | at async loadSession (file:///app/src/processing/helpers/youtube-session.js:38:24) {
cobalt | [cause]: ConnectTimeoutError: Connect Timeout Error
cobalt | at onConnectTimeout (/app/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/connect.js:186:24)
cobalt | at /app/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/connect.js:133:46
cobalt | at Immediate._onImmediate (/app/node_modules/.pnpm/[email protected]/node_modules/undici/lib/core/connect.js:174:9)
cobalt | at process.processImmediate (node:internal/timers:505:21) {
cobalt | code: 'UND_ERR_CONNECT_TIMEOUT'
cobalt | }
cobalt | }
cobalt | [!] Failed loading poToken & visitor_data at 2025-05-29T21:38:18.596Z.
c
Having the same issue on my instance, set up the session token generator & imported cookies, but still getting the API error described above. I'm using a DigitalOcean VPS without a residential proxy (yet), but it's showing the API error instead of login error, so I doubt that's the issue here.
Having the same issue on my instance, set up the session token generator & imported cookies, but still getting the API error described above. I'm using a DigitalOcean VPS without a residential proxy (yet), but it's showing the API error instead of login error, so I doubt that's the issue here.
Try this YAML
I'm also using a residential proxy and get api.fetch.fail errors when using a session server hosted on my own computer so I'm also actively looking for a solution.
I see that original session generator is deprecated as YouTube has changed the validation. https://github.com/iv-org/youtube-trusted-session-generator?tab=readme-ov-file#tool-is-deprecated
you just saved my life. invidious companion works with my proxy!
what proxy provider are you using, also how much trafic is going thru your proxy