diff --git a/formats/YouTube.Search.Playlist.ps1xml b/formats/YouTube.Search.Playlist.ps1xml new file mode 100644 index 0000000..abe3fc2 --- /dev/null +++ b/formats/YouTube.Search.Playlist.ps1xml @@ -0,0 +1,55 @@ + + + + Table + + YouTube.Search.PlaylistResult + + + + + + 34 + + + + 22 + + + + 35 + + + + 28 + + + + 25 + + + + + + + $_.id.playlistId + + + $_.snippet.publishedAt + + + $_.snippet.title + + + $_.snippet.channelId + + + $_.snippet.channelTitle + + + + + + + + diff --git a/functions/Find-YouTubePlaylist.ps1 b/functions/Find-YouTubePlaylist.ps1 new file mode 100644 index 0000000..8b9b89e --- /dev/null +++ b/functions/Find-YouTubePlaylist.ps1 @@ -0,0 +1,27 @@ +function Find-YouTubePlaylist { + <# + .SYNOPSIS + Find a YouTube video playlist, using a search. + + + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [string] $Query, + [ValidateNotNullOrEmpty()] + [string] $PageToken, + [switch] $Raw + ) + $Uri = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=playlist&maxResults=50&q={0}' -f $Query + if ($PageToken) { + $Uri += '&pageToken={0}' -f $PageToken + } + + $Result = Invoke-RestMethod -Uri $Uri -Headers (Get-AccessToken) + + if ($PSBoundParameters.ContainsKey('Raw')) { return $Result } + + $Result.Items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Search.PlaylistResult') } + $Result.Items +} \ No newline at end of file diff --git a/functions/Grant-YouTube.ps1 b/functions/Grant-YouTube.ps1 index 1161318..0f00143 100644 --- a/functions/Grant-YouTube.ps1 +++ b/functions/Grant-YouTube.ps1 @@ -11,7 +11,13 @@ function Grant-Youtube { Write-Verbose -Message $Client $GrantType = 'urn:ietf:params:oauth:grant-type:device_code' $Uri = 'https://oauth2.googleapis.com/device/code?client_id={0}&scope={1}' -f $Client.client_id, $Scopes - $Response = Invoke-RestMethod -Method Post -Uri $Uri + try { + $Response = Invoke-RestMethod -Method Post -Uri $Uri -ErrorAction Stop + } + catch { + throw 'Invalid YouTube app configuration. Check your YouTube application configuration in Google Cloud Platform.' + return + } Write-Host -Object ('Open your browser and go to https://www.google.com/device, enter code {0}' -f $Response.user_code) while ((Get-Date) -lt (Get-Date).AddSeconds($Response.expires_in)) { diff --git a/youtube.psd1 b/youtube.psd1 index dc148f7..840c7b8 100644 --- a/youtube.psd1 +++ b/youtube.psd1 @@ -13,6 +13,7 @@ 'Grant-YouTubeOauth' 'Find-YouTubeVideo' 'Find-YouTubeChannel' + 'Find-YouTubePlaylist' 'Get-YouTubeVideo' 'Set-YouTubeConfiguration' 'Get-YouTubeCommentThread' @@ -25,6 +26,7 @@ 'Get-YouTubeActivity' 'Get-YouTubeChannel' 'Set-YouTubeVideoRating' + ) AliasesToExport = @('') VariablesToExport = @('')