33 [switch ]$uninstall ,
44 [switch ]$help ,
55 [switch ]$man ,
6+ [switch ]$version ,
67 [string ]$url ,
78 [switch ]$debug
89)
910
1011# Stop the script if an error occurs.
1112$ErrorActionPreference = ' Stop'
13+
14+ $ScriptVersion = " 2.3.0"
15+
1216<# *==========================================================================
1317* ℹ PARAMETERS
1418
@@ -19,8 +23,7 @@ $ErrorActionPreference = 'Stop'
1923* ℹ DEFAULT VARIABLES
2024===========================================================================#>
2125
22- # This folder name must exist as a child in the user downloads directory defined by the OS
23- New-Variable - Name DownloadFolderName - Value " yt-dlp" - Option Constant
26+
2427
2528# Don’t edit this part unless you know what you do.
2629# Get default downloads dir for each platform
@@ -37,27 +40,47 @@ else {
3740}
3841
3942# ===========================================================================
40- # you can edit those values
41- New-Variable - Name UI_Path - Value " D:/Programmes/Internet/youtube-dl/YDL-UI_Portable/YDL-UI.exe" - 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 recommended to not use such a file for security reason.
43+ # import user config
44+ try {
45+ $ConfigPath = Join-Path $PSScriptRoot " config.ps1"
46+ if (Test-Path $ConfigPath ) {
47+ . $ConfigPath
48+ }
49+ else {
50+ TerminateWithError - errorMessage " `" config.ps1`" is missing."
51+ }
52+ }
53+ catch {
54+ TerminateWithError - errorMessage " `" config.ps1`" is missing or can not be loaded."
55+ }
4656
47- New-Variable - Name directory - Value (Join-Path - Path " $downloadsPath " - ChildPath " $DownloadFolderName " ) - Option Constant
48- New-Variable - Name templateNameChannel - Value " %(uploader|)s%(uploader& - )s%(title).70s.%(ext)s" - Option Constant
49- New-Variable - Name templateNameTitle - Value " %(title).70s.%(ext)s" - Option Constant
50- # if useTitle is true then use $templateNameTitle else $templateNameChannel
51- New-Variable - Name useTitle - Value $true - Option Constant
52- # defaut quality for video (make it compatible to upload on 𝕏)
53- New-Variable - Name videoQuality - Value " bestvideo*[vcodec^=avc1]+bestaudio[acodec^=mp4a]/bestvideo*+bestaudio/best"
54- # Videos will use this container
55- New-Variable - Name videoContainer - Value " mp4" - Option Constant
56- # set URLs for which the script will detect as audio
57- New-Variable - Name autoAudio - Value @ (" https://music.youtube.com/watch?v=" ) - Option Constant
58- # set default js runtime required in the new yt-dlp versions. Just comment if using Deno.
59- New-Variable - Name jsRuntime - Value " bun" - Option Constant
57+ $Defaults = @ {
58+ DownloadFolderName = " yt-dlp"
59+ UI_Path = " "
60+ UseBrowserCookies = $true
61+ browserCookies = " firefox"
62+ myCookies = " "
63+ templateNameChannel = " %(uploader)s - %(title)s.%(ext)s"
64+ templateNameTitle = " %(title)s.%(ext)s"
65+ useTitle = $true
66+ videoQuality = " best"
67+ videoContainer = " mp4"
68+ autoAudio = @ (" https://music.youtube.com/watch?v=" )
69+ jsRuntime = " bun"
70+ }
6071
72+ foreach ($VarName in $Defaults.Keys ) {
73+ if (-not (Get-Variable - Name $VarName - ErrorAction SilentlyContinue)) {
74+ # Required variable is missing in config.ps1, let’s create it here with the default value
75+ New-Variable - Name $VarName - Value $Defaults [$VarName ] - Option Constant - Confirm:$false
76+ Write-Host
77+ Write-Warning " Variable '$VarName ' is missing in your `" config.ps1`" . We will use the fallback value: `" $ ( $Defaults [$VarName ]) `" "
78+ Write-Host
79+ }
80+ }
81+ # ===========================================================================
82+
83+ New-Variable - Name directory - Value (Join-Path - Path " $downloadsPath " - ChildPath " $DownloadFolderName " ) - Option Constant
6184
6285# This is the command triggered by the protocol
6386# It open the Windows Terminal with the profile 'PowerShell 7' and this script with the given url
@@ -74,8 +97,18 @@ New-Variable -Name repo -Value "https://github.com/Fred-Vatin/run-yt-dlp-from-br
7497<# *==========================================================================
7598* ℹ FUNCTIONS
7699===========================================================================#>
100+ function Show-Version {
101+ Write-Host " "
102+ Write-Host " run-yt-dlp-from-browser" - ForegroundColor Yellow
103+ Write-Host " Version : " - NoNewline
104+ Write-Host " $ScriptVersion " - ForegroundColor Green
105+ }
106+
107+
77108# Display help message with specified formatting
78109function Show-Help {
110+ Show-Version
111+ Write-Host " "
79112 Write-Host " ℹ`t PARAMETERS" - ForegroundColor Magenta
80113 Write-Host " ========================`n " - ForegroundColor Magenta
81114 Write-Host " -help" - ForegroundColor Magenta
@@ -115,8 +148,8 @@ function Show-Help {
115148 Write-Host " `t $directory `n "
116149 Write-Host " UI_Path" - ForegroundColor Magenta
117150 Write-Host " `t $UI_Path `n "
118- Write-Host " UseBrowser (ignore \" myCookies\" if true)" - ForegroundColor Magenta
119- Write-Host " `t $UseBrowser `n "
151+ Write-Host " UseBrowserCookies (ignore \" myCookies\" if true)" - ForegroundColor Magenta
152+ Write-Host " `t $UseBrowserCookies `n "
120153 Write-Host " browserCookies" - ForegroundColor Magenta
121154 Write-Host " `t $browserCookies `n "
122155 Write-Host " myCookies" - ForegroundColor Magenta
@@ -200,7 +233,16 @@ function Test-FFmpegInstallation {
200233<# *==========================================================================
201234* ℹ GET PARAMETERS
202235===========================================================================#>
203- Clear-Host
236+ if ($version ) {
237+ Show-Version
238+ Write-Host " Source : " - NoNewline
239+ Write-Host " https://github.com/Fred-Vatin/run-yt-dlp-from-browser" - ForegroundColor Cyan
240+ Write-Host " "
241+ Write-Host " Run with the " - NoNewline
242+ Write-Host " -help " - ForegroundColor Magenta - NoNewline
243+ Write-Host " parameter for more info"
244+ exit
245+ }
204246
205247<# *==========================================================================
206248* ℹ HANDLE HELP PARAMETER
@@ -451,7 +493,7 @@ if ($url -and -not $install -and -not $uninstall) {
451493 <# *==========================================================================
452494 * ℹ TEST COOKIES
453495 ===========================================================================#>
454- if (-not $UseBrowser ) {
496+ if (-not $UseBrowserCookies ) {
455497 # Test cookie path
456498 if (Test-Path - Path $myCookies ) {
457499 Write-Host " `- Use user cookies from file" - ForegroundColor Green
@@ -473,7 +515,7 @@ if ($url -and -not $install -and -not $uninstall) {
473515 $pattern = ' -o\s+(.+?)\s+http'
474516 $substitution = ' -o "$1" http'
475517
476- if ($UseBrowser ) {
518+ if ($UseBrowserCookies ) {
477519 $options += @ (" --cookies-from-browser" , " $browserCookies " )
478520 }
479521 elseif ($myCookies ) {
0 commit comments