@@ -8,32 +8,34 @@ function Get-OEmbed {
8
8
[oEmbed](https://oembed.com/) is a format for allowing an embedded representation of a URL on third party sites.
9
9
10
10
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
11
13
#>
12
14
[Alias('oEmbed')]
13
- [CmdletBinding(PositionalBinding=$false,SupportsShouldProcess,DefaultParameterSetName='?url ')]
15
+ [CmdletBinding(PositionalBinding=$false,SupportsShouldProcess,DefaultParameterSetName='Query ')]
14
16
param(
15
17
# The URL
16
- [Parameter(Mandatory,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName,ParameterSetName='?url ')]
18
+ [Parameter(Mandatory,Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName,ParameterSetName='Query ')]
17
19
[Uri]
18
20
$Url,
19
21
20
22
# The maximum width of the returned image
21
- [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='?url ')]
23
+ [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Query ')]
22
24
[int]
23
25
$MaxWidth,
24
26
25
27
# The maximum height of the returned image
26
- [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='?url ')]
28
+ [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Query ')]
27
29
[int]
28
30
$MaxHeight,
29
31
30
32
# The format of the returned image
31
- [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='?url ')]
33
+ [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Query ')]
32
34
[string]
33
35
$Format,
34
36
35
37
# Whether to force a refresh of the cached oEmbed data
36
- [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='?url ')]
38
+ [Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Query ')]
37
39
[switch]
38
40
$Force,
39
41
@@ -140,14 +142,21 @@ function Get-OEmbed {
140
142
) -Id $progressId
141
143
}
142
144
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
+
143
153
$script:oEmbedUrlCache[$oEmbedUrl] = Invoke-RestMethod -Uri $oEmbedUrl |
144
154
Add-Member NoteProperty 'Url' $Url -Force -PassThru |
145
155
Add-Member NoteProperty 'oEmbedUrl' $oEmbedUrl -Force -PassThru
146
156
$script:oEmbedUrlCache[$oEmbedUrl].pstypenames.insert(0,'OpenEmbedding')
147
- }
148
-
157
+ }
149
158
150
- $script:oEmbedUrlCache[$oEmbedUrl]
159
+ $script:oEmbedUrlCache[$oEmbedUrl]
151
160
}
152
161
153
162
if ($oEmbedQueue.Count -gt 1) {
0 commit comments