@@ -66,12 +66,12 @@ catch {
6666# Don’t edit this part unless you know what you do.
6767# Get default downloads dir for each platform
6868if (-not $DownloadsPath ) {
69- if ($PSVersionTable .Platform -eq " Win32NT " ) {
69+ if ($IsWindows ) {
7070 New-Variable - Name UserShellFolders - Value " HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" - Option Constant
7171 New-Variable - Name downloadsKey - Value " {374DE290-123F-4565-9164-39C4925E467B}" - Option Constant
7272 New-Variable - Name DownloadsPath - Value ((Get-ItemProperty - Path $UserShellFolders - Name $downloadsKey ).$downloadsKey ) - Option Constant
7373 }
74- elseif ($PSVersionTable .Platform -eq " Unix " ) {
74+ elseif ($IsLinux -or $IsMacOS ) {
7575 New-Variable - Name DownloadsPath - Value (Join-Path - Path $HOME - ChildPath " Downloads" ) - Option Constant
7676 }
7777 else {
@@ -477,7 +477,6 @@ if ($url -and -not $install -and -not $uninstall) {
477477 }
478478 }
479479
480-
481480 <# *==========================================================================
482481 * ℹ TEST DOWNLOAD DIR
483482 ===========================================================================#>
@@ -727,7 +726,6 @@ if ($url -and -not $install -and -not $uninstall) {
727726 & yt- dlp $options 2>&1 | Out-ColoredLog
728727 }
729728
730-
731729 <# *==========================================================================
732730 * ℹ OPEN DOWNLOAD DIR
733731 ===========================================================================#>
@@ -773,19 +771,24 @@ if ($uninstall) {
773771 WriteTitle " UNINSTALL"
774772 Write-Host " Uninstalling ytdl protocol handler..."
775773
776- try {
777- Remove-Item - Path " $ytdlKey " - Recurse - Force - ErrorAction SilentlyContinue
774+ if ($IsWindows ) {
775+ try {
776+ Remove-Item - Path " $ytdlKey " - Recurse - Force - ErrorAction SilentlyContinue
778777
779- if (Test-Path - Path $ytdlKey ) {
780- throw " $ytdlKey could NOT be deleted"
778+ if (Test-Path - Path $ytdlKey ) {
779+ throw " $ytdlKey could NOT be deleted"
780+ }
781+ else {
782+ Write-Host " $ytdlKey deleted from the registry" - ForegroundColor Yellow
783+ Write-Host " `n Successfully uninstalled." - ForegroundColor Green
784+ }
781785 }
782- else {
783- Write-Host " $ytdlKey deleted from the registry" - ForegroundColor Yellow
784- Write-Host " `n Successfully uninstalled." - ForegroundColor Green
786+ catch {
787+ TerminateWithError - errorMessage " Uninstall failed" - exception $_.Exception
785788 }
786789 }
787- catch {
788- TerminateWithError - errorMessage " Uninstall failed " - exception $_ .Exception
790+ else {
791+ TerminateWithError - errorMessage " Sorry but this works only on Windows (for now) "
789792 }
790793}
791794
@@ -799,46 +802,53 @@ if ($install) {
799802 WriteTitle " INSTALL"
800803 Write-Host " Installing ytdl protocol handler...`n "
801804
802- # Abort if yt-dlp is not found in path
803- Test-YtdlInstallation
805+ if ($IsWindows ) {
806+ # Abort if yt-dlp is not found in path
807+ Test-YtdlInstallation
804808
805- $scriptPath = $PSCommandPath
806- Write-Host " Commands will be sent to:"
807- Write-Host " $scriptPath " - ForegroundColor Cyan
809+ $scriptPath = $PSCommandPath
810+ Write-Host " Commands will be sent to:"
811+ Write-Host " $scriptPath " - ForegroundColor Cyan
808812
809- $ytDlpPath = Get-YtdlPath
813+ $ytDlpPath = Get-YtdlPath
810814
811- try {
812- # Create or update ytdl registry key
813- New-Item - Path $ytdlKey - Force | Out-Null
814- Set-ItemProperty - Path $ytdlKey - Name " (Default)" - Value " URL:ytdl"
815- Set-ItemProperty - Path $ytdlKey - Name " URL Protocol" - Value " "
815+ try {
816+ # Create or update ytdl registry key
817+ New-Item - Path $ytdlKey - Force | Out-Null
818+ Set-ItemProperty - Path $ytdlKey - Name " (Default)" - Value " URL:ytdl"
819+ Set-ItemProperty - Path $ytdlKey - Name " URL Protocol" - Value " "
816820
817- Write-Host " `n $ytdlKey " - NoNewline - ForegroundColor Green
818- Write-Host " was added to the registry" - ForegroundColor Cyan
821+ Write-Host " `n $ytdlKey " - NoNewline - ForegroundColor Green
822+ Write-Host " was added to the registry" - ForegroundColor Cyan
819823
820824
821- # Configure DefaultIcon if yt-dlp is found
822- if ($ytdlpPath ) {
823- New-Item - Path " $ytdlKey \DefaultIcon" - Force | Out-Null
824- Set-ItemProperty - Path " $ytdlKey \DefaultIcon" - Name " (Default)" - Value " "" $ytdlpPath "" ,1"
825+ # Configure DefaultIcon if yt-dlp is found
826+ if ($ytdlpPath ) {
827+ New-Item - Path " $ytdlKey \DefaultIcon" - Force | Out-Null
828+ Set-ItemProperty - Path " $ytdlKey \DefaultIcon" - Name " (Default)" - Value " "" $ytdlpPath "" ,1"
825829
826- Write-Host " `n Icon using " - NoNewline - ForegroundColor Cyan
827- Write-Host " $ytDlpPath " - NoNewline - ForegroundColor Green
828- Write-Host " succesfully added to the registry" - ForegroundColor Cyan
829- }
830+ Write-Host " `n Icon using " - NoNewline - ForegroundColor Cyan
831+ Write-Host " $ytDlpPath " - NoNewline - ForegroundColor Green
832+ Write-Host " succesfully added to the registry" - ForegroundColor Cyan
833+ }
830834
831- # Create shell\open\command key
832- New-Item - Path " $ytdlKey \shell\open\command" - Force | Out-Null
833- Set-ItemProperty - Path " $ytdlKey \shell\open\command" - Name " (Default)" - Value $command
835+ # Create shell\open\command key
836+ New-Item - Path " $ytdlKey \shell\open\command" - Force | Out-Null
837+ Set-ItemProperty - Path " $ytdlKey \shell\open\command" - Name " (Default)" - Value $command
838+
839+ Write-Host " `n Command: " - NoNewline - ForegroundColor Cyan
840+ Write-Host " $command " - NoNewline - ForegroundColor Green
841+ Write-Host " succesfully added to the registry" - ForegroundColor Cyan
834842
835- Write-Host " `n Command: " - NoNewline - ForegroundColor Cyan
836- Write-Host " $command " - NoNewline - ForegroundColor Green
837- Write-Host " succesfully added to the registry" - ForegroundColor Cyan
843+ Write-Host " `n INSTALLATION COMPLETE" - ForegroundColor Green
844+ }
845+ catch {
846+ TerminateWithError - errorMessage " Failed to add protocol '$protocol `://' into the registry" - Exception $_.Exception
847+ }
838848
839- Write-Host " `n INSTALLATION COMPLETE" - ForegroundColor Green
840849 }
841- catch {
842- TerminateWithError - errorMessage " Failed to add protocol ' $protocol `://' into the registry " - Exception $_ .Exception
850+ else {
851+ TerminateWithError - errorMessage " Sorry but this works only on Windows (for now) "
843852 }
853+
844854}
0 commit comments