feat: add cookies file support in settings and download engine, enhance i18n with new cookie-related translations

This commit is contained in:
Nexmoe
2025-10-27 22:01:11 +08:00
parent 5246ab8369
commit a7e4eb865b
5 changed files with 105 additions and 14 deletions

View File

@@ -90,6 +90,11 @@ export const buildDownloadArgs = (
args.push('--cookies-from-browser', settings.browserForCookies)
}
const cookiesPath = settings.cookiesPath?.trim()
if (cookiesPath) {
args.push('--cookies', cookiesPath)
}
if (settings.proxy) {
args.push('--proxy', settings.proxy)
}

View File

@@ -61,6 +61,11 @@ class DownloadEngine extends EventEmitter {
args.push('--cookies-from-browser', settings.browserForCookies)
}
const cookiesPath = settings.cookiesPath?.trim()
if (cookiesPath) {
args.push('--cookies', cookiesPath)
}
// Add config file if configured
if (settings.configPath) {
args.push('--config-location', `"${settings.configPath}"`)
@@ -130,6 +135,11 @@ class DownloadEngine extends EventEmitter {
args.push('--cookies-from-browser', settings.browserForCookies)
}
const cookiesPath = settings.cookiesPath?.trim()
if (cookiesPath) {
args.push('--cookies', cookiesPath)
}
args.push(url)
return new Promise((resolve, reject) => {

View File

@@ -255,6 +255,14 @@
"audio": "Audio Preferences",
"browserForCookies": "Select browser to use cookies from",
"browserForCookiesDescription": "Browser to extract cookies from for authentication",
"cookiesFile": "Cookies file",
"cookiesFileDescription": "Netscape formatted cookies file to load for authentication",
"clearCookiesFile": "Clear",
"cookiesHelpTitle": "Using cookies",
"cookiesHelpBrowser": "Pick your browser above to reuse its signed-in session automatically.",
"cookiesHelpFile": "Export a Netscape cookies file (see the yt-dlp FAQ) and select it here when needed.",
"cookiesHelpFaq": "Open yt-dlp cookies FAQ",
"openLinkError": "Failed to open link",
"browserOptions": {
"brave": "Brave",
"chrome": "Chrome",

View File

@@ -71,6 +71,31 @@ export function Settings() {
}
}
const handleSelectCookiesFile = async () => {
try {
const { ipcServices } = await import('../lib/ipc')
const path = await ipcServices.fs.selectFile()
if (path) {
await handleSettingChange('cookiesPath', path)
}
} catch (error) {
console.error('Failed to select cookies file:', error)
toast.error(t('settings.fileSelectError'))
}
}
const handleOpenCookiesFaq = async () => {
try {
const { ipcServices } = await import('../lib/ipc')
await ipcServices.fs.openExternal(
'https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp'
)
} catch (error) {
console.error('Failed to open cookies FAQ:', error)
toast.error(t('settings.openLinkError'))
}
}
const handleThemeChange = async (value: 'light' | 'dark' | 'system') => {
const currentTheme = (theme ?? settings.theme ?? 'system') as 'light' | 'dark' | 'system'
if (currentTheme === value) {
@@ -269,6 +294,38 @@ export function Settings() {
<ItemSeparator />
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.proxy')}</ItemTitle>
<ItemDescription>{t('settings.proxyDescription')}</ItemDescription>
</ItemContent>
<ItemActions>
<Input
placeholder={t('settings.proxyPlaceholder')}
value={settings.proxy}
onChange={(e) => handleSettingChange('proxy', e.target.value)}
className="w-64"
/>
</ItemActions>
</Item>
<ItemSeparator />
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.configFile')}</ItemTitle>
<ItemDescription>{t('settings.configFileDescription')}</ItemDescription>
</ItemContent>
<ItemActions>
<div className="flex gap-2 w-full max-w-md">
<Input value={settings.configPath} readOnly className="flex-1" />
<Button onClick={handleSelectConfigFile}>{t('settings.selectPath')}</Button>
</div>
</ItemActions>
</Item>
</ItemGroup>
<ItemGroup>
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.browserForCookies')}</ItemTitle>
@@ -300,16 +357,21 @@ export function Settings() {
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.proxy')}</ItemTitle>
<ItemDescription>{t('settings.proxyDescription')}</ItemDescription>
<ItemTitle>{t('settings.cookiesFile')}</ItemTitle>
<ItemDescription>{t('settings.cookiesFileDescription')}</ItemDescription>
</ItemContent>
<ItemActions>
<Input
placeholder={t('settings.proxyPlaceholder')}
value={settings.proxy}
onChange={(e) => handleSettingChange('proxy', e.target.value)}
className="w-64"
/>
<div className="flex gap-2 w-full max-w-md">
<Input value={settings.cookiesPath ?? ''} readOnly className="flex-1" />
<Button onClick={handleSelectCookiesFile}>{t('settings.selectPath')}</Button>
<Button
variant="secondary"
onClick={() => void handleSettingChange('cookiesPath', '')}
disabled={!settings.cookiesPath}
>
{t('settings.clearCookiesFile')}
</Button>
</div>
</ItemActions>
</Item>
@@ -317,14 +379,18 @@ export function Settings() {
<Item variant="muted">
<ItemContent>
<ItemTitle>{t('settings.configFile')}</ItemTitle>
<ItemDescription>{t('settings.configFileDescription')}</ItemDescription>
<ItemTitle>{t('settings.cookiesHelpTitle')}</ItemTitle>
<ItemDescription>
<ul className="list-disc list-inside space-y-1">
<li>{t('settings.cookiesHelpBrowser')}</li>
<li>{t('settings.cookiesHelpFile')}</li>
</ul>
</ItemDescription>
</ItemContent>
<ItemActions>
<div className="flex gap-2 w-full max-w-md">
<Input value={settings.configPath} readOnly className="flex-1" />
<Button onClick={handleSelectConfigFile}>{t('settings.selectPath')}</Button>
</div>
<Button variant="link" className="px-0" onClick={handleOpenCookiesFaq}>
{t('settings.cookiesHelpFaq')}
</Button>
</ItemActions>
</Item>
</ItemGroup>

View File

@@ -146,6 +146,7 @@ export interface AppSettings {
showMoreFormats: boolean
maxConcurrentDownloads: number
browserForCookies: string
cookiesPath: string
proxy: string
configPath: string
betaProgram: boolean
@@ -163,6 +164,7 @@ export const defaultSettings: AppSettings = {
showMoreFormats: false,
maxConcurrentDownloads: 5,
browserForCookies: 'none',
cookiesPath: '',
proxy: '',
configPath: '',
betaProgram: false,