Skip to content

Commit 621a651

Browse files
committed
feat(ps1): use cookies from browser
1 parent c85dd1c commit 621a651

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

powershell/yt-download.ps1

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ else {
3939
#===========================================================================
4040
# you can edit those values
4141
New-Variable -Name UI_Path -Value "D:/Programmes/Internet/youtube-dl/YDL-UI_Portable/YDL-UI.exe" -Option Constant
42-
New-Variable -Name myCookies -Value "D:\OneDrive\Backup\Internet\youtube-dl\cookies.txt" -Option Constant
42+
New-Variable -Name UseBrowser -Value $true -Option Constant # true is recommended
43+
# Must be the name of a yt-dlp supported browser and optionnaly the name of the profile directory containing the cookies you need
44+
New-Variable -Name browserCookies -Value "firefox:oo49eawy.Youtube" -Option Constant
45+
New-Variable -Name myCookies -Value "D:/pathTo/cookies.txt" # it is reccommanded to not use such a file for security reason.
4346

4447
New-Variable -Name directory -Value (Join-Path -Path "$downloadsPath" -ChildPath "$DownloadFolderName") -Option Constant
4548
New-Variable -Name templateNameChannel -Value "%(uploader|)s%(uploader& - )s%(title).70s.%(ext)s" -Option Constant
@@ -112,6 +115,10 @@ function Show-Help {
112115
Write-Host "`t$directory`n"
113116
Write-Host "UI_Path" -ForegroundColor Magenta
114117
Write-Host "`t$UI_Path`n"
118+
Write-Host "UseBrowser (ignore \"myCookies\" if true)" -ForegroundColor Magenta
119+
Write-Host "`t$UseBrowser`n"
120+
Write-Host "browserCookies" -ForegroundColor Magenta
121+
Write-Host "`t$browserCookies`n"
115122
Write-Host "myCookies" -ForegroundColor Magenta
116123
Write-Host "`t$myCookies`n"
117124
}
@@ -444,13 +451,15 @@ if ($url -and -not $install -and -not $uninstall) {
444451
<#*==========================================================================
445452
* ℹ TEST COOKIES
446453
===========================================================================#>
447-
# Test cookie path
448-
if (Test-Path -Path $myCookies) {
449-
Write-Host "`- Use user cookies from file" -ForegroundColor Green
450-
}
451-
else {
452-
Write-Host "The cookie file doesn’t exist and will not be used:`n $myCookies" -ForegroundColor Yellow
453-
$myCookies = ""
454+
if (-not $UseBrowser) {
455+
# Test cookie path
456+
if (Test-Path -Path $myCookies) {
457+
Write-Host "`- Use user cookies from file" -ForegroundColor Green
458+
}
459+
else {
460+
Write-Host "The cookie file doesn’t exist and will not be used:`n $myCookies" -ForegroundColor Yellow
461+
$myCookies = ""
462+
}
454463
}
455464

456465
<#*==========================================================================
@@ -464,7 +473,10 @@ if ($url -and -not $install -and -not $uninstall) {
464473
$pattern = '-o\s+(.+?)\s+http'
465474
$substitution = '-o "$1" http'
466475

467-
if ($myCookies) {
476+
if ($UseBrowser) {
477+
$options += @("--cookies-from-browser", "$browserCookies")
478+
}
479+
elseif ($myCookies) {
468480
$options += @("--cookies", "$myCookies")
469481
}
470482

0 commit comments

Comments
 (0)