@@ -8,32 +8,34 @@ function Get-OEmbed {
88 [oEmbed](https://oembed.com/) is a format for allowing an embedded representation of a URL on third party sites.
99
1010 Most social networks support oEmbed, so this little function lets you embed almost any social network post
11+ . EXAMPLE
12+ oEmbed -Url https://www.youtube.com/watch?v=UIR9Z_JdVhs
1113 #>
1214 [Alias (' oEmbed' )]
13- [CmdletBinding (PositionalBinding = $false , SupportsShouldProcess , DefaultParameterSetName = ' ?url ' )]
15+ [CmdletBinding (PositionalBinding = $false , SupportsShouldProcess , DefaultParameterSetName = ' Query ' )]
1416 param (
1517 # The URL
16- [Parameter (Mandatory , Position = 0 , ValueFromPipeline , ValueFromPipelineByPropertyName , ParameterSetName = ' ?url ' )]
18+ [Parameter (Mandatory , Position = 0 , ValueFromPipeline , ValueFromPipelineByPropertyName , ParameterSetName = ' Query ' )]
1719 [Uri ]
1820 $Url ,
1921
2022 # The maximum width of the returned image
21- [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' ?url ' )]
23+ [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' Query ' )]
2224 [int ]
2325 $MaxWidth ,
2426
2527 # The maximum height of the returned image
26- [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' ?url ' )]
28+ [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' Query ' )]
2729 [int ]
2830 $MaxHeight ,
2931
3032 # The format of the returned image
31- [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' ?url ' )]
33+ [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' Query ' )]
3234 [string ]
3335 $Format ,
3436
3537 # Whether to force a refresh of the cached oEmbed data
36- [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' ?url ' )]
38+ [Parameter (ValueFromPipelineByPropertyName , ParameterSetName = ' Query ' )]
3739 [switch ]
3840 $Force ,
3941
@@ -140,14 +142,21 @@ function Get-OEmbed {
140142 ) - Id $progressId
141143 }
142144 if (-not $script :oEmbedUrlCache [$oEmbedUrl ] -or $Force ) {
145+ if ($WhatIfPreference ) { return $oEmbedUrl }
146+ if (-not $PSCmdlet.ShouldProcess ($oEmbedUrl )) {
147+ Write-Verbose " Skipping $oEmbedUrl "
148+ continue
149+ } else {
150+ Write-Verbose " Retrieving $oEmbedUrl "
151+ }
152+
143153 $script :oEmbedUrlCache [$oEmbedUrl ] = Invoke-RestMethod - Uri $oEmbedUrl |
144154 Add-Member NoteProperty ' Url' $Url - Force - PassThru |
145155 Add-Member NoteProperty ' oEmbedUrl' $oEmbedUrl - Force - PassThru
146156 $script :oEmbedUrlCache [$oEmbedUrl ].pstypenames.insert(0 , ' OpenEmbedding' )
147- }
148-
157+ }
149158
150- $script :oEmbedUrlCache [$oEmbedUrl ]
159+ $script :oEmbedUrlCache [$oEmbedUrl ]
151160 }
152161
153162 if ($oEmbedQueue.Count -gt 1 ) {
0 commit comments