-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGet-YouTubeVideo.ps1
36 lines (29 loc) · 1.2 KB
/
Get-YouTubeVideo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function Get-YouTubeVideo {
<#
.SYNOPSIS
Retrieves details about a specific YouTube video, or multiple videos.
.EXAMPLE
Get-YouTubeVideo -Id LFWxH-bexNk
.EXAMPLE
Get-YouTubeVideo -Id LFWxH-bexNk,8dZbdl3wzW8
#>
[CmdletBinding()]
param (
[Parameter(ParameterSetName = 'VideoById')]
[string[]] $Id,
[Parameter(ParameterSetName = 'LikedVideos')]
[switch] $Liked,
[Parameter(ParameterSetName = 'DislikedVideos')]
[switch] $Disliked,
[switch] $Raw
)
$Parts = 'contentDetails,id,liveStreamingDetails,localizations,player,recordingDetails,snippet,statistics,status,topicDetails'
$Uri = 'https://www.googleapis.com/youtube/v3/videos?part={0}&maxResults=50' -f $Parts
if ($PSCmdlet.ParameterSetName -eq 'VideoById') { $Uri += '&id={0}' -f ($Id -join ',') }
if ($PSCmdlet.ParameterSetName -eq 'LikedVideos') { $Uri += '&myRating=liked' }
if ($PSCmdlet.ParameterSetName -eq 'DislikedVideos') { $Uri += '&myRating=disliked' }
$Result = Invoke-RestMethod -Method Get -Uri $Uri -Headers (Get-AccessToken)
if ($PSBoundParameters.ContainsKey('Raw')) { return $Result }
$Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Video') }
$Result.items
}