Skip to content

feat(youtube): add cookiePath config support#203

Open
doyimmiuink wants to merge 1 commit intoPerformanC:devfrom
doyimmiuink:feat/youtube-cookie-path
Open

feat(youtube): add cookiePath config support#203
doyimmiuink wants to merge 1 commit intoPerformanC:devfrom
doyimmiuink:feat/youtube-cookie-path

Conversation

@doyimmiuink
Copy link
Copy Markdown

Summary

Adds support for a cookiePath (Netscape cookies.txt) to NodeLink's YouTube source, allowing operators to provide real account cookies for authenticated YouTube requests.

Motivation

  • Age-restricted videos fail without authentication
  • Bot detection is significantly reduced when using real account cookies
  • This matches the cookie support available in other Lavalink-compatible audio sources

Changes

config.default.js

youtube: {
  cookiePath: '', // path to Netscape cookies.txt
  ...
}

src/typings/sources/youtube.types.ts

  • YouTubeSourceConfig: added cookiePath? field with JSDoc.

src/sources/youtube/YouTube.ts

  • Parses cookiePath at startup (supports both Netscape tab-separated format and inline key=value; key=value format).
  • Uses the parsed cookie header in _fetchVisitorData() instead of the hardcoded scraping cookie.
  • Falls back to hardcoded cookie if cookiePath is not set or fails to parse.

Flow

# config.js
youtube:
  cookiePath: '/app/cookies.txt'

Checkmarks

  • The modified endpoints have been tested.
  • Used the same indentation as the rest of the project.
  • Still compatible with LavaLink clients.

@doyimmiuink
Copy link
Copy Markdown
Author

I forgot to include the other one, but basically I'll send the ones that only do that: one is httpProxies and the other is cookiesPath.
1000214769
1000214768
1000214770

@1Lucas1apk
Copy link
Copy Markdown
Member

I want the terms and conditions, like the step-by-step process and which clients this bypassed, and also what types of cookies are valid for this, are they incognito cookies? Those without rotation? Even if you're already logged into the account without being in incognito mode, how long does it last? Do they expire? Is there a way to fix it if it expires? And for debugging, add detailed debug logs if possible.

@doyimmiuink
Copy link
Copy Markdown
Author

Regarding cookiePath:
Valid cookies are in Netscape format (.txt), exported using extensions like EditThisCookie or Get cookies.txt LOCALLY from a Chrome/Firefox session logged into a real YouTube account — incognito does not work since the cookies need to come from a persistent authenticated session
No rotation is implemented — these are static cookies. They typically last 1–2 years (LOGIN_INFO), though session cookies like SID/HSID may expire sooner. When they expire, the operator needs to re-export and restart NodeLink
The clients that benefit depend on which ones pass the Cookie header in their requests — primarily Web, Music, and TV clients
I can add debug logs in _fetchVisitorData() to log when the cookie header is being applied if that would help review
Regarding httpProxy:
Step-by-step: the operator sets server.httpProxy.enabled: true and provides a proxy URL (supports http, https, socks5). All outbound requests made through makeRequest() are then automatically routed through it — per-request proxy always takes precedence
Main use case is hiding the server IP from sources like YouTube, Deezer and Spotify to reduce bot detection and bypass regional blocks
I can add more detailed debug logs per-request if needed

@1Lucas1apk
Copy link
Copy Markdown
Member

That's very interesting. One thing you mentioned was that you have to restart to update cookies if something specific expires. Would it be possible to add a parameter to an existing endpoint, where we can basically send the refreshToken via patch, and perhaps add a parameter to send the new cookies?

@doyimmiuink
Copy link
Copy Markdown
Author

The problem is that the patch I made didn't upload either. Could I use --force to send it here? And about the refreshtoken, I'll review the entire code and see if I can add that part.

@ToddyTheNoobDud
Copy link
Copy Markdown
Collaborator

Very interesting to me, but, on the common.ts file, can you add support for itags 774 and 141 ?
since its adding support for cookies, users can put premium accounts which return these formata
774 is a high quality opus file (260-360kbps ?)
141 is high audio/mp4 quality file

but Thats just my opinion ^^, everything else looks interesting :)

@doyimmiuink
Copy link
Copy Markdown
Author

Sure

@doyimmiuink doyimmiuink force-pushed the feat/youtube-cookie-path branch from 3db12c9 to 3e6a2a8 Compare April 23, 2026 20:53
@doyimmiuink
Copy link
Copy Markdown
Author

done

@doyimmiuink
Copy link
Copy Markdown
Author

Look at the files in the new --force

@doyimmiuink doyimmiuink force-pushed the feat/youtube-cookie-path branch 2 times, most recently from b3a218d to 4148522 Compare April 24, 2026 02:03
@1Lucas1apk
Copy link
Copy Markdown
Member

These changes don't match the title.

Copy link
Copy Markdown
Member

@1Lucas1apk 1Lucas1apk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes don't match the title.

…/141

feat(youtube): cookiePath config support
  src/typings/sources/youtube.types.ts: add cookiePath? with JSDoc
  config.default.js: add cookiePath to youtube block
  src/sources/youtube/YouTube.ts:
    - import readFileSync from node:fs
    - add private cookieHeader field
    - constructor: init cookieHeader = null
    - initialize: parse Netscape or inline cookie format
    - _fetchVisitorData: use this.cookieHeader ?? hardcoded fallback

feat(server): global httpProxy config
  config.default.js: add httpProxy to server block
  src/typings/config/config.types.ts: add httpProxy? to ServerConfig
  src/typings/utils.types.ts: add options?.server?.httpProxy
  src/utils.ts: makeRequest falls back to server.httpProxy
  src/index.ts: import makeRequest + _testProxyConnectivity

feat(youtube): HQ audio format tags 774 and 141
  src/sources/youtube/common.ts: add 774/141 to high/medium priority
@doyimmiuink doyimmiuink force-pushed the feat/youtube-cookie-path branch from 4148522 to 7b83ef0 Compare April 24, 2026 02:18
@doyimmiuink
Copy link
Copy Markdown
Author

The title was updated to reflect all three changes included in this push: cookiePath, global httpProxy, and HQ audio tags 774/141. All three are present in the latest commit (7b83ef0) — you can check the Files changed tab to confirm.

@doyimmiuink doyimmiuink requested a review from 1Lucas1apk April 24, 2026 02:21
Comment thread config.default.js
Comment on lines +7 to +12
httpProxy: {
enabled: false, // route all outbound HTTP requests through a proxy
url: '', // e.g. 'http://user:pass@host:3128' or 'socks5://host:1080'
username: '',
password: ''
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not accept a global proxy; there are already separate systems for that.

Comment thread src/index.ts
Comment on lines +599 to +618

// global-http-proxy: log proxy and test connectivity at startup
const proxyCfg = options?.server?.httpProxy
if (proxyCfg?.enabled && proxyCfg.url) {
logger('info', 'Proxy', `HTTP proxy enabled: ${proxyCfg.url}`)
this._testProxyConnectivity(proxyCfg.url)
}
}

/** @internal */
private _testProxyConnectivity(proxyUrl: string): void {
makeRequest('http://connectivitycheck.gstatic.com/generate_204', {
proxy: { url: proxyUrl }
})
.then(() => {
logger('info', 'Proxy', `Connected successfully via ${proxyUrl}`)
})
.catch((err: Error) => {
logger('warn', 'Proxy', `Proxy connectivity check failed (${proxyUrl}): ${err.message}`)
})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad practices

Comment on lines +356 to +366
/** Global HTTP proxy server options. */
options?: {
server?: {
httpProxy?: {
enabled: boolean
url: string
username?: string
password?: string
}
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not accept a global proxy; there are already separate systems for that.

Comment on lines +35 to +45

/**
* Global HTTP proxy for all outbound NodeLink requests.
* Supports http, https, and socks5 URLs.
*/
httpProxy?: {
enabled: boolean
url: string
username?: string
password?: string
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will not accept a global proxy; there are already separate systems for that.

Comment on lines +3117 to +3118
high: [774, 141, 251, 250, 140],
medium: [141, 251, 250, 140],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A question was raised about ITAgs; it doesn't mean they should be added as a standard feature, it's something that only appears on YouTube Premium accounts to complete the setup, and NodeLink already has a system for selecting the best ITAgs, so this is redundant.

@1Lucas1apk
Copy link
Copy Markdown
Member

It's all nonsensical, to be honest, it seems like it was done without any research whatsoever.

@doyimmiuink
Copy link
Copy Markdown
Author

The 774/141 tags were added based on a direct suggestion from @ToddyTheNoobDud in this same PR thread. The httpProxy mirrors Lavalink's existing httpConfig proxy behaviour, which is well documented. Both changes were made in response to feedback, not without research.

@doyimmiuink
Copy link
Copy Markdown
Author

But do you only want the cookiepath?

@1Lucas1apk
Copy link
Copy Markdown
Member

Yes, it's a lack of study. If you had analyzed it, you would have realized that NodeLink already has a way to add this itag indirectly. Even though Toddy mentioned it, it was just feedback that could possibly be added, not directly to the code—that would be redundant. And HTTP proxy wasn't requested and won't be accepted, and we're not here to exactly follow LavaLink! This is NodeLink; client compatibility is one thing.

@1Lucas1apk
Copy link
Copy Markdown
Member

And the pull request title simply says "supports cookie path," that's all.

@doyimmiuink
Copy link
Copy Markdown
Author

Cansei de falar inglês, serei brevemente no português!! Por que mais que a língua seja minha abordagem, atualmente eu estou pegando ideias e totalmente trazida do lavalink e mudando algumas coisa para o nodeLink, isso é fato!! Porém eu não sabia que já tinha itag no código, e sobre o HttpProxy eu apenas usei como inspiração, mas ok. Só quer o CookiePath no código então? Psoso fazer um último pull resquest adicionando só ele? Ou ele já foi aceito?

@1Lucas1apk
Copy link
Copy Markdown
Member

This idea will still need to be tested in the long term; I will analyze it myself when I have time. Just correct what was requested.

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

Successfully merging this pull request may close these issues.

3 participants