@@ -37,27 +37,46 @@ else {
3737}
3838
3939# ===========================================================================
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.
40+ # import user config
41+ try {
42+ $ConfigPath = Join-Path $PSScriptRoot " config.ps1"
43+ if (Test-Path $ConfigPath ) {
44+ . $ConfigPath
45+ }
46+ else {
47+ TerminateWithError - errorMessage " `" config.ps1`" is missing."
48+ }
49+ }
50+ catch {
51+ TerminateWithError - errorMessage " `" config.ps1`" is missing or can not be loaded."
52+ }
4653
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
54+ $Defaults = @ {
55+ UI_Path = " "
56+ UseBrowser = $true
57+ browserCookies = " firefox"
58+ myCookies = " "
59+ templateNameChannel = " %(uploader)s - %(title)s.%(ext)s"
60+ templateNameTitle = " %(title)s.%(ext)s"
61+ useTitle = $true
62+ videoQuality = " best"
63+ videoContainer = " mp4"
64+ autoAudio = @ (" https://music.youtube.com/watch?v=" )
65+ jsRuntime = " bun"
66+ }
67+
68+ foreach ($VarName in $Defaults.Keys ) {
69+ if (-not (Get-Variable - Name $VarName - ErrorAction SilentlyContinue)) {
70+ # Required variable is missing in config.ps1, let’s create it here with the default value
71+ New-Variable - Name $VarName - Value $Defaults [$VarName ] - Option Constant - Confirm:$false
72+ Write-Host
73+ Write-Warning " Variable '$VarName ' is missing in your `" config.ps1`" . We will use the fallback value: `" $ ( $Defaults [$VarName ]) `" "
74+ Write-Host
75+ }
76+ }
77+ # ===========================================================================
6078
79+ New-Variable - Name directory - Value (Join-Path - Path " $downloadsPath " - ChildPath " $DownloadFolderName " ) - Option Constant
6180
6281# This is the command triggered by the protocol
6382# It open the Windows Terminal with the profile 'PowerShell 7' and this script with the given url
@@ -200,7 +219,7 @@ function Test-FFmpegInstallation {
200219<# *==========================================================================
201220* ℹ GET PARAMETERS
202221===========================================================================#>
203- Clear-Host
222+ # Clear-Host
204223
205224<# *==========================================================================
206225* ℹ HANDLE HELP PARAMETER
0 commit comments