From ff925245e8889ebc5228531b8a00f61fc08c2937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Sun, 11 Jun 2023 15:50:49 +0200 Subject: [PATCH 01/16] start-process -wait dows not work. Stop pode server after first request instead. --- functions/Grant-YouTubeOauth.ps1 | 10 ++-------- functions/private/Find-Browser.ps1 | 1 + 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/functions/Grant-YouTubeOauth.ps1 b/functions/Grant-YouTubeOauth.ps1 index 6665570..19c14f4 100644 --- a/functions/Grant-YouTubeOauth.ps1 +++ b/functions/Grant-YouTubeOauth.ps1 @@ -32,6 +32,7 @@ function Grant-YoutubeOauth { '@ Write-PodeHtmlResponse -Value $Response + Close-PodeServer } } } @@ -47,12 +48,5 @@ function Grant-YoutubeOauth { $Browser = $BrowserCommand ? $BrowserCommand : (Find-Browser) Write-Verbose -Message ('Browser command line is: ' -f $Browser) - Start-Process -FilePath $Browser -ArgumentList ('"{0}"' -f $Uri) -Wait - - if (!$IsMacOS) { - Stop-Job -Name $JobName - } - else { - Write-Warning -Message 'Please manually stop the Background Job running the Pode web server after completing authentication. Cannot wait for browser process to complete on MacOS.' - } + Start-Process -FilePath $Browser -ArgumentList ('"{0}"' -f $Uri) } diff --git a/functions/private/Find-Browser.ps1 b/functions/private/Find-Browser.ps1 index 08b3a3c..1430d44 100644 --- a/functions/private/Find-Browser.ps1 +++ b/functions/private/Find-Browser.ps1 @@ -24,6 +24,7 @@ function Find-Browser { 'firefox.exe' 'chrome' 'firefox' + 'MicrosoftEdge.exe' ) foreach ($Command in $CommandList) { if (Get-Command -Name $Command) { return $Command } From 6204401390cfaf0c7664a30dd5ef0b986ab7d3fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Sun, 11 Jun 2023 22:39:59 +0200 Subject: [PATCH 02/16] fix scope encoding --- functions/Grant-YouTubeOauth.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/functions/Grant-YouTubeOauth.ps1 b/functions/Grant-YouTubeOauth.ps1 index 19c14f4..6658b28 100644 --- a/functions/Grant-YouTubeOauth.ps1 +++ b/functions/Grant-YouTubeOauth.ps1 @@ -32,7 +32,6 @@ function Grant-YoutubeOauth { '@ Write-PodeHtmlResponse -Value $Response - Close-PodeServer } } } @@ -44,9 +43,10 @@ function Grant-YoutubeOauth { 'https://www.googleapis.com/auth/youtube.force-ssl' 'https://www.googleapis.com/auth/youtube.readonly' ) - $Uri = 'https://accounts.google.com/o/oauth2/v2/auth?include_granted_scopes=true&response_type=token&client_id={0}&redirect_uri={1}&scope={3}&state={2}' -f $Client.client_id, $RedirectUri, (New-Guid).Guid, ($ScopeList -join ' ') + $scopesURI = [System.Web.HttpUtility]::UrlEncode($ScopeList -join ' ') + $Uri = 'https://accounts.google.com/o/oauth2/v2/auth?include_granted_scopes=true&response_type=token&client_id={0}&redirect_uri={1}&scope={3}&state={2}' -f $Client.client_id, $RedirectUri, (New-Guid).Guid, ($scopesURI) $Browser = $BrowserCommand ? $BrowserCommand : (Find-Browser) Write-Verbose -Message ('Browser command line is: ' -f $Browser) Start-Process -FilePath $Browser -ArgumentList ('"{0}"' -f $Uri) -} +} \ No newline at end of file From 6291e7998962d5009abaec2b4ad9c148eeaaad68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Sun, 11 Jun 2023 22:40:27 +0200 Subject: [PATCH 03/16] Set-YoutubeVideoTags --- functions/Set-YoutubeVideoTags.ps1 | 33 ++++++++++++++++++++++++++++++ youtube.psd1 | 1 + 2 files changed, 34 insertions(+) create mode 100644 functions/Set-YoutubeVideoTags.ps1 diff --git a/functions/Set-YoutubeVideoTags.ps1 b/functions/Set-YoutubeVideoTags.ps1 new file mode 100644 index 0000000..90b7ef8 --- /dev/null +++ b/functions/Set-YoutubeVideoTags.ps1 @@ -0,0 +1,33 @@ +function Set-YouTubeVideoTags { + <# + .SYNOPSIS + Updates the tags for a YouTube video. + + .EXAMPLE + Update-YouTubeVideoTags -VideoId LFWxH-bexNk -Tags 'PowerShell', 'YouTube API' + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [string] $VideoId, + [Parameter(Mandatory = $true)] + [string[]] $Tags + ) + $Uri = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$VideoId" + + $Body = @{ + id = $VideoId + snippet = @{ + tags = $Tags + title = "pineapple" + categoryId = "22" + } + } | ConvertTo-Json -Depth 5 + + $Headers = (Get-AccessToken) + @{ + 'Content-Type' = 'application/json' + } + + Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $Body -Method Put + } + \ No newline at end of file diff --git a/youtube.psd1 b/youtube.psd1 index dc148f7..eae1f33 100644 --- a/youtube.psd1 +++ b/youtube.psd1 @@ -25,6 +25,7 @@ 'Get-YouTubeActivity' 'Get-YouTubeChannel' 'Set-YouTubeVideoRating' + 'Set-YouTubeVideoTags' ) AliasesToExport = @('') VariablesToExport = @('') From 5f898329e13f4bc42b2b2f56488130f067e3e23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Sun, 11 Jun 2023 23:22:23 +0200 Subject: [PATCH 04/16] fix parameter "raw" --- functions/Get-YouTubeChannel.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/functions/Get-YouTubeChannel.ps1 b/functions/Get-YouTubeChannel.ps1 index 8192c58..7e2c0f2 100644 --- a/functions/Get-YouTubeChannel.ps1 +++ b/functions/Get-YouTubeChannel.ps1 @@ -9,7 +9,8 @@ function Get-YouTubeChannel { [CmdletBinding()] param ( [Parameter(ParameterSetName = 'ChannelId')] - [string[]] $Id + [string[]] $Id, + [switch] $Raw ) $Uri = 'https://www.googleapis.com/youtube/v3/channels?part=brandingSettings,contentDetails,contentOwnerDetails,id,snippet,localizations,statistics,status,topicDetails' @@ -22,6 +23,10 @@ function Get-YouTubeChannel { $Result = Invoke-RestMethod -Uri $Uri -Method Get -Headers (Get-AccessToken) $Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Channel') } - if ($Raw) { return $Result } - $Result.items + if ($Raw) { + return $Result + }else{ + $Result + } + } \ No newline at end of file From ee3ebb436e02950377fbcd92094100e3c91e9b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Sun, 11 Jun 2023 23:23:33 +0200 Subject: [PATCH 05/16] Get-YouTubePlaylist --- functions/Get-YoutubePlaylist.ps1 | 25 +++++++++++++++++++ ...tubeVideoTags.ps1 => Set-YoutubeVideo.ps1} | 5 ++-- youtube.psd1 | 3 ++- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 functions/Get-YoutubePlaylist.ps1 rename functions/{Set-YoutubeVideoTags.ps1 => Set-YoutubeVideo.ps1} (95%) diff --git a/functions/Get-YoutubePlaylist.ps1 b/functions/Get-YoutubePlaylist.ps1 new file mode 100644 index 0000000..826fa75 --- /dev/null +++ b/functions/Get-YoutubePlaylist.ps1 @@ -0,0 +1,25 @@ +function Get-YouTubePlaylist { + <# + .SYNOPSIS + Retrieves details for a YouTube channel. + + .PARAMETER ChannelId + The array of channels that you want to get detailed information for. + #> + [CmdletBinding()] + param ( + [Parameter(ParameterSetName = 'PlaylistId')] + [string[]] $PlaylistId, + [switch] $Raw + ) + $Uri = 'https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails,id,snippet,status' + + switch ($PSCmdlet.ParameterSetName) { + 'PlaylistId' { + $Uri += '&playlistId={0}' -f ($PlaylistId -join ',') + } + } + Write-Verbose -Message $Uri + $Result = Invoke-RestMethod -Uri $Uri -Method Get -Headers (Get-AccessToken) + return $Result + } \ No newline at end of file diff --git a/functions/Set-YoutubeVideoTags.ps1 b/functions/Set-YoutubeVideo.ps1 similarity index 95% rename from functions/Set-YoutubeVideoTags.ps1 rename to functions/Set-YoutubeVideo.ps1 index 90b7ef8..43a5283 100644 --- a/functions/Set-YoutubeVideoTags.ps1 +++ b/functions/Set-YoutubeVideo.ps1 @@ -1,4 +1,4 @@ -function Set-YouTubeVideoTags { +function Set-YouTubeVideo { <# .SYNOPSIS Updates the tags for a YouTube video. @@ -29,5 +29,4 @@ function Set-YouTubeVideoTags { } Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $Body -Method Put - } - \ No newline at end of file + } \ No newline at end of file diff --git a/youtube.psd1 b/youtube.psd1 index eae1f33..1b57c6d 100644 --- a/youtube.psd1 +++ b/youtube.psd1 @@ -25,7 +25,8 @@ 'Get-YouTubeActivity' 'Get-YouTubeChannel' 'Set-YouTubeVideoRating' - 'Set-YouTubeVideoTags' + 'Set-YouTubeVideo' + 'Get-YouTubePlaylist' ) AliasesToExport = @('') VariablesToExport = @('') From 37f81cdbc1bc31951bbb5eeab954102cf05b48b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Mon, 12 Jun 2023 01:49:11 +0200 Subject: [PATCH 06/16] add parameters --- functions/Set-YoutubeVideo.ps1 | 81 ++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 9 deletions(-) diff --git a/functions/Set-YoutubeVideo.ps1 b/functions/Set-YoutubeVideo.ps1 index 43a5283..b76461c 100644 --- a/functions/Set-YoutubeVideo.ps1 +++ b/functions/Set-YoutubeVideo.ps1 @@ -10,23 +10,86 @@ function Set-YouTubeVideo { param ( [Parameter(Mandatory = $true)] [string] $VideoId, - [Parameter(Mandatory = $true)] - [string[]] $Tags + [Parameter(Mandatory = $false)] + [string[]] $Tags, + [Parameter(Mandatory = $false)] + [string] $Title, + [Parameter(Mandatory = $false)] + [string] $categoryId, + [Parameter(Mandatory = $false)] + [string] $Description, + [ValidateSet('unlisted','private','public')] + [Parameter(Mandatory=$False)] + [string]$PrivacyStatus, + [Parameter(Mandatory=$False)] + [string]$selfDeclaredMadeForKids, + [Parameter(Mandatory=$False)] + [string]$publishAt ) - $Uri = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$VideoId" + + Write-Verbose "Getting video from API" + $currentVideo = Get-YouTubeVideo -Id $VideoId -Raw + Write-Verbose ($currentVideo | ConvertTo-Json) + $Uri = "https://www.googleapis.com/youtube/v3/videos?part=snippet,status&id=$VideoId" $Body = @{ id = $VideoId snippet = @{ - tags = $Tags - title = "pineapple" - categoryId = "22" } - } | ConvertTo-Json -Depth 5 + status = @{ + } + } + + if (![string]::IsNullOrEmpty($Title)) { + #update title + $Body.snippet.title = $Title + }else{ + #use existing title + $Body.snippet.title = $currentVideo.items.snippet.title + } + + if (![string]::IsNullOrEmpty($categoryId)) { + #update category + $Body.snippet.categoryId = $categoryId + }else{ + #use existing category + $Body.snippet.categoryId = $currentVideo.items.snippet.categoryId + } + + if (![string]::IsNullOrEmpty($Tags)) { + $Body.snippet.tags = $Tags + } + + if (![string]::IsNullOrEmpty($Description)) { + $Body.snippet.description = $Description + } + + if (![string]::IsNullOrEmpty($PrivacyStatus)) { + $Body.status.privacyStatus = $PrivacyStatus + }else{ + $Body.status.privacyStatus = $currentVideo.items.status.privacyStatus + } + + if (![string]::IsNullOrEmpty($selfDeclaredMadeForKids)) { + $Body.status.selfDeclaredMadeForKids = [bool]$selfDeclaredMadeForKids + }else{ + $Body.status.selfDeclaredMadeForKids = [bool]$currentVideo.items.status.selfDeclaredMadeForKids + } + + if (![string]::IsNullOrEmpty($publishAt)) { + $Body.status.publishAt = (Get-Date).AddDays(2).ToString("yyyy-MM-ddTHH:mm:ssZ") + #https://developers.google.com/youtube/v3/docs/videos/update?hl=de + #status.publishAt: Wenn Sie einen Wert für dieses Attribut festgelegt haben, müssen Sie auch das Attribut status.privacyStatus auf private setzen. + $Body.status.privacyStatus = 'private' + } + + $BodyJSON = $Body | ConvertTo-Json -Depth 10 $Headers = (Get-AccessToken) + @{ 'Content-Type' = 'application/json' } - Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $Body -Method Put - } \ No newline at end of file + Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $BodyJSON -Method Put + } + + \ No newline at end of file From 11685dcc6c196d42c2b3f4be709ea8dccf9ec14c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 00:28:45 +0200 Subject: [PATCH 07/16] add encoding for scopes. Add PodeRoute for writing the access_token to disk Close the Pode Server after receiving the token --- functions/Grant-YouTubeOauth.ps1 | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/functions/Grant-YouTubeOauth.ps1 b/functions/Grant-YouTubeOauth.ps1 index 6658b28..e3447d6 100644 --- a/functions/Grant-YouTubeOauth.ps1 +++ b/functions/Grant-YouTubeOauth.ps1 @@ -17,10 +17,6 @@ function Grant-YoutubeOauth { Start-PodeServer -ScriptBlock { Add-PodeEndpoint -Port 8000 -Protocol Http Add-PodeRoute -Method Get -Path /auth/complete -ScriptBlock { - @{ - access_token = $WebEvent.Query['access_token'] - } | ConvertTo-Json | Set-Content -Path $HOME/.pwsh.youtube.oauth.json - $Response = @'

Authentication Complete

You may close this browser window.

@@ -28,12 +24,21 @@ function Grant-YoutubeOauth { console.log(window.location.hash); let access_token_regex = /access_token=(?.*?)&token_type/; let result = access_token_regex.exec(window.location.hash); - fetch(`/auth/complete?access_token=${result.groups.access_token}`); + fetch(`/auth/receive?access_token=${result.groups.access_token}`); '@ - Write-PodeHtmlResponse -Value $Response + Write-PodeHtmlResponse -Value $Response -StatusCode 200 + } + + Add-Poderoute -Method Get -Path /auth/receive -ScriptBlock{ + Out-PodeVariable -Name access_token -Value $WebEvent.Query['access_token'] + Close-PodeServer } - } + } + $token = @{ + access_token = $access_token + } + $token | ConvertTo-Json | Out-File -Path $HOME/.pwsh.youtube.oauth.json } $Client = Get-Content -Path $ConfigPath | ConvertFrom-Json @@ -44,7 +49,7 @@ function Grant-YoutubeOauth { 'https://www.googleapis.com/auth/youtube.readonly' ) $scopesURI = [System.Web.HttpUtility]::UrlEncode($ScopeList -join ' ') - $Uri = 'https://accounts.google.com/o/oauth2/v2/auth?include_granted_scopes=true&response_type=token&client_id={0}&redirect_uri={1}&scope={3}&state={2}' -f $Client.client_id, $RedirectUri, (New-Guid).Guid, ($scopesURI) + $Uri = 'https://accounts.google.com/o/oauth2/v2/auth?include_granted_scopes=true&response_type=token&client_id={0}&redirect_uri={1}&scope={2}&state={2}' -f $Client.client_id, $RedirectUri, ($scopesURI), (New-Guid).Guid $Browser = $BrowserCommand ? $BrowserCommand : (Find-Browser) Write-Verbose -Message ('Browser command line is: ' -f $Browser) From 9189ab508996770451e172e4da2d7cc16368db52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 00:43:27 +0200 Subject: [PATCH 08/16] Delete Get-YouTubeChannel.ps1 --- functions/Get-YouTubeChannel.ps1 | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 functions/Get-YouTubeChannel.ps1 diff --git a/functions/Get-YouTubeChannel.ps1 b/functions/Get-YouTubeChannel.ps1 deleted file mode 100644 index 7e2c0f2..0000000 --- a/functions/Get-YouTubeChannel.ps1 +++ /dev/null @@ -1,32 +0,0 @@ -function Get-YouTubeChannel { - <# - .SYNOPSIS - Retrieves details for a YouTube channel. - - .PARAMETER ChannelId - The array of channels that you want to get detailed information for. - #> - [CmdletBinding()] - param ( - [Parameter(ParameterSetName = 'ChannelId')] - [string[]] $Id, - [switch] $Raw - ) - $Uri = 'https://www.googleapis.com/youtube/v3/channels?part=brandingSettings,contentDetails,contentOwnerDetails,id,snippet,localizations,statistics,status,topicDetails' - - switch ($PSCmdlet.ParameterSetName) { - 'ChannelId' { - $Uri += '&id={0}' -f ($Id -join ',') - } - } - Write-Verbose -Message $Uri - $Result = Invoke-RestMethod -Uri $Uri -Method Get -Headers (Get-AccessToken) - $Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Channel') } - - if ($Raw) { - return $Result - }else{ - $Result - } - -} \ No newline at end of file From f4d074cf85114d5aa0b7880baf84bba3967ff679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 00:45:08 +0200 Subject: [PATCH 09/16] Delete Get-YoutubePlaylist.ps1 --- functions/Get-YoutubePlaylist.ps1 | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 functions/Get-YoutubePlaylist.ps1 diff --git a/functions/Get-YoutubePlaylist.ps1 b/functions/Get-YoutubePlaylist.ps1 deleted file mode 100644 index 826fa75..0000000 --- a/functions/Get-YoutubePlaylist.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -function Get-YouTubePlaylist { - <# - .SYNOPSIS - Retrieves details for a YouTube channel. - - .PARAMETER ChannelId - The array of channels that you want to get detailed information for. - #> - [CmdletBinding()] - param ( - [Parameter(ParameterSetName = 'PlaylistId')] - [string[]] $PlaylistId, - [switch] $Raw - ) - $Uri = 'https://www.googleapis.com/youtube/v3/playlistItems?part=contentDetails,id,snippet,status' - - switch ($PSCmdlet.ParameterSetName) { - 'PlaylistId' { - $Uri += '&playlistId={0}' -f ($PlaylistId -join ',') - } - } - Write-Verbose -Message $Uri - $Result = Invoke-RestMethod -Uri $Uri -Method Get -Headers (Get-AccessToken) - return $Result - } \ No newline at end of file From 822e92af48c9b2fa82da6350cbcc99918f6626eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 00:45:59 +0200 Subject: [PATCH 10/16] Update youtube.psd1 --- youtube.psd1 | 2 -- 1 file changed, 2 deletions(-) diff --git a/youtube.psd1 b/youtube.psd1 index 1b57c6d..dc148f7 100644 --- a/youtube.psd1 +++ b/youtube.psd1 @@ -25,8 +25,6 @@ 'Get-YouTubeActivity' 'Get-YouTubeChannel' 'Set-YouTubeVideoRating' - 'Set-YouTubeVideo' - 'Get-YouTubePlaylist' ) AliasesToExport = @('') VariablesToExport = @('') From 051988238b8a2585691a0662cd050369803999be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 00:46:21 +0200 Subject: [PATCH 11/16] Delete Set-YoutubeVideo.ps1 --- functions/Set-YoutubeVideo.ps1 | 95 ---------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 functions/Set-YoutubeVideo.ps1 diff --git a/functions/Set-YoutubeVideo.ps1 b/functions/Set-YoutubeVideo.ps1 deleted file mode 100644 index b76461c..0000000 --- a/functions/Set-YoutubeVideo.ps1 +++ /dev/null @@ -1,95 +0,0 @@ -function Set-YouTubeVideo { - <# - .SYNOPSIS - Updates the tags for a YouTube video. - - .EXAMPLE - Update-YouTubeVideoTags -VideoId LFWxH-bexNk -Tags 'PowerShell', 'YouTube API' - #> - [CmdletBinding()] - param ( - [Parameter(Mandatory = $true)] - [string] $VideoId, - [Parameter(Mandatory = $false)] - [string[]] $Tags, - [Parameter(Mandatory = $false)] - [string] $Title, - [Parameter(Mandatory = $false)] - [string] $categoryId, - [Parameter(Mandatory = $false)] - [string] $Description, - [ValidateSet('unlisted','private','public')] - [Parameter(Mandatory=$False)] - [string]$PrivacyStatus, - [Parameter(Mandatory=$False)] - [string]$selfDeclaredMadeForKids, - [Parameter(Mandatory=$False)] - [string]$publishAt - ) - - Write-Verbose "Getting video from API" - $currentVideo = Get-YouTubeVideo -Id $VideoId -Raw - Write-Verbose ($currentVideo | ConvertTo-Json) - $Uri = "https://www.googleapis.com/youtube/v3/videos?part=snippet,status&id=$VideoId" - - $Body = @{ - id = $VideoId - snippet = @{ - } - status = @{ - } - } - - if (![string]::IsNullOrEmpty($Title)) { - #update title - $Body.snippet.title = $Title - }else{ - #use existing title - $Body.snippet.title = $currentVideo.items.snippet.title - } - - if (![string]::IsNullOrEmpty($categoryId)) { - #update category - $Body.snippet.categoryId = $categoryId - }else{ - #use existing category - $Body.snippet.categoryId = $currentVideo.items.snippet.categoryId - } - - if (![string]::IsNullOrEmpty($Tags)) { - $Body.snippet.tags = $Tags - } - - if (![string]::IsNullOrEmpty($Description)) { - $Body.snippet.description = $Description - } - - if (![string]::IsNullOrEmpty($PrivacyStatus)) { - $Body.status.privacyStatus = $PrivacyStatus - }else{ - $Body.status.privacyStatus = $currentVideo.items.status.privacyStatus - } - - if (![string]::IsNullOrEmpty($selfDeclaredMadeForKids)) { - $Body.status.selfDeclaredMadeForKids = [bool]$selfDeclaredMadeForKids - }else{ - $Body.status.selfDeclaredMadeForKids = [bool]$currentVideo.items.status.selfDeclaredMadeForKids - } - - if (![string]::IsNullOrEmpty($publishAt)) { - $Body.status.publishAt = (Get-Date).AddDays(2).ToString("yyyy-MM-ddTHH:mm:ssZ") - #https://developers.google.com/youtube/v3/docs/videos/update?hl=de - #status.publishAt: Wenn Sie einen Wert für dieses Attribut festgelegt haben, müssen Sie auch das Attribut status.privacyStatus auf private setzen. - $Body.status.privacyStatus = 'private' - } - - $BodyJSON = $Body | ConvertTo-Json -Depth 10 - - $Headers = (Get-AccessToken) + @{ - 'Content-Type' = 'application/json' - } - - Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $BodyJSON -Method Put - } - - \ No newline at end of file From f967007839a76ea8aa2bf408fed63062a84dd359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 01:08:49 +0200 Subject: [PATCH 12/16] Revert "Delete Set-YoutubeVideo.ps1" This reverts commit 051988238b8a2585691a0662cd050369803999be. --- functions/Set-YoutubeVideo.ps1 | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 functions/Set-YoutubeVideo.ps1 diff --git a/functions/Set-YoutubeVideo.ps1 b/functions/Set-YoutubeVideo.ps1 new file mode 100644 index 0000000..b76461c --- /dev/null +++ b/functions/Set-YoutubeVideo.ps1 @@ -0,0 +1,95 @@ +function Set-YouTubeVideo { + <# + .SYNOPSIS + Updates the tags for a YouTube video. + + .EXAMPLE + Update-YouTubeVideoTags -VideoId LFWxH-bexNk -Tags 'PowerShell', 'YouTube API' + #> + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + [string] $VideoId, + [Parameter(Mandatory = $false)] + [string[]] $Tags, + [Parameter(Mandatory = $false)] + [string] $Title, + [Parameter(Mandatory = $false)] + [string] $categoryId, + [Parameter(Mandatory = $false)] + [string] $Description, + [ValidateSet('unlisted','private','public')] + [Parameter(Mandatory=$False)] + [string]$PrivacyStatus, + [Parameter(Mandatory=$False)] + [string]$selfDeclaredMadeForKids, + [Parameter(Mandatory=$False)] + [string]$publishAt + ) + + Write-Verbose "Getting video from API" + $currentVideo = Get-YouTubeVideo -Id $VideoId -Raw + Write-Verbose ($currentVideo | ConvertTo-Json) + $Uri = "https://www.googleapis.com/youtube/v3/videos?part=snippet,status&id=$VideoId" + + $Body = @{ + id = $VideoId + snippet = @{ + } + status = @{ + } + } + + if (![string]::IsNullOrEmpty($Title)) { + #update title + $Body.snippet.title = $Title + }else{ + #use existing title + $Body.snippet.title = $currentVideo.items.snippet.title + } + + if (![string]::IsNullOrEmpty($categoryId)) { + #update category + $Body.snippet.categoryId = $categoryId + }else{ + #use existing category + $Body.snippet.categoryId = $currentVideo.items.snippet.categoryId + } + + if (![string]::IsNullOrEmpty($Tags)) { + $Body.snippet.tags = $Tags + } + + if (![string]::IsNullOrEmpty($Description)) { + $Body.snippet.description = $Description + } + + if (![string]::IsNullOrEmpty($PrivacyStatus)) { + $Body.status.privacyStatus = $PrivacyStatus + }else{ + $Body.status.privacyStatus = $currentVideo.items.status.privacyStatus + } + + if (![string]::IsNullOrEmpty($selfDeclaredMadeForKids)) { + $Body.status.selfDeclaredMadeForKids = [bool]$selfDeclaredMadeForKids + }else{ + $Body.status.selfDeclaredMadeForKids = [bool]$currentVideo.items.status.selfDeclaredMadeForKids + } + + if (![string]::IsNullOrEmpty($publishAt)) { + $Body.status.publishAt = (Get-Date).AddDays(2).ToString("yyyy-MM-ddTHH:mm:ssZ") + #https://developers.google.com/youtube/v3/docs/videos/update?hl=de + #status.publishAt: Wenn Sie einen Wert für dieses Attribut festgelegt haben, müssen Sie auch das Attribut status.privacyStatus auf private setzen. + $Body.status.privacyStatus = 'private' + } + + $BodyJSON = $Body | ConvertTo-Json -Depth 10 + + $Headers = (Get-AccessToken) + @{ + 'Content-Type' = 'application/json' + } + + Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $BodyJSON -Method Put + } + + \ No newline at end of file From 7c26ca70727cbf1ad0eb138c96a3a46e00fb929f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 01:10:05 +0200 Subject: [PATCH 13/16] Revert "Delete Get-YouTubeChannel.ps1" This reverts commit 9189ab508996770451e172e4da2d7cc16368db52. --- functions/Get-YouTubeChannel.ps1 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 functions/Get-YouTubeChannel.ps1 diff --git a/functions/Get-YouTubeChannel.ps1 b/functions/Get-YouTubeChannel.ps1 new file mode 100644 index 0000000..7e2c0f2 --- /dev/null +++ b/functions/Get-YouTubeChannel.ps1 @@ -0,0 +1,32 @@ +function Get-YouTubeChannel { + <# + .SYNOPSIS + Retrieves details for a YouTube channel. + + .PARAMETER ChannelId + The array of channels that you want to get detailed information for. + #> + [CmdletBinding()] + param ( + [Parameter(ParameterSetName = 'ChannelId')] + [string[]] $Id, + [switch] $Raw + ) + $Uri = 'https://www.googleapis.com/youtube/v3/channels?part=brandingSettings,contentDetails,contentOwnerDetails,id,snippet,localizations,statistics,status,topicDetails' + + switch ($PSCmdlet.ParameterSetName) { + 'ChannelId' { + $Uri += '&id={0}' -f ($Id -join ',') + } + } + Write-Verbose -Message $Uri + $Result = Invoke-RestMethod -Uri $Uri -Method Get -Headers (Get-AccessToken) + $Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Channel') } + + if ($Raw) { + return $Result + }else{ + $Result + } + +} \ No newline at end of file From 90a2953a92e5fdbdd5efeab9725ba402f9b111f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Wed, 14 Jun 2023 01:10:21 +0200 Subject: [PATCH 14/16] Revert "Revert "Delete Set-YoutubeVideo.ps1"" This reverts commit f967007839a76ea8aa2bf408fed63062a84dd359. --- functions/Set-YoutubeVideo.ps1 | 95 ---------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 functions/Set-YoutubeVideo.ps1 diff --git a/functions/Set-YoutubeVideo.ps1 b/functions/Set-YoutubeVideo.ps1 deleted file mode 100644 index b76461c..0000000 --- a/functions/Set-YoutubeVideo.ps1 +++ /dev/null @@ -1,95 +0,0 @@ -function Set-YouTubeVideo { - <# - .SYNOPSIS - Updates the tags for a YouTube video. - - .EXAMPLE - Update-YouTubeVideoTags -VideoId LFWxH-bexNk -Tags 'PowerShell', 'YouTube API' - #> - [CmdletBinding()] - param ( - [Parameter(Mandatory = $true)] - [string] $VideoId, - [Parameter(Mandatory = $false)] - [string[]] $Tags, - [Parameter(Mandatory = $false)] - [string] $Title, - [Parameter(Mandatory = $false)] - [string] $categoryId, - [Parameter(Mandatory = $false)] - [string] $Description, - [ValidateSet('unlisted','private','public')] - [Parameter(Mandatory=$False)] - [string]$PrivacyStatus, - [Parameter(Mandatory=$False)] - [string]$selfDeclaredMadeForKids, - [Parameter(Mandatory=$False)] - [string]$publishAt - ) - - Write-Verbose "Getting video from API" - $currentVideo = Get-YouTubeVideo -Id $VideoId -Raw - Write-Verbose ($currentVideo | ConvertTo-Json) - $Uri = "https://www.googleapis.com/youtube/v3/videos?part=snippet,status&id=$VideoId" - - $Body = @{ - id = $VideoId - snippet = @{ - } - status = @{ - } - } - - if (![string]::IsNullOrEmpty($Title)) { - #update title - $Body.snippet.title = $Title - }else{ - #use existing title - $Body.snippet.title = $currentVideo.items.snippet.title - } - - if (![string]::IsNullOrEmpty($categoryId)) { - #update category - $Body.snippet.categoryId = $categoryId - }else{ - #use existing category - $Body.snippet.categoryId = $currentVideo.items.snippet.categoryId - } - - if (![string]::IsNullOrEmpty($Tags)) { - $Body.snippet.tags = $Tags - } - - if (![string]::IsNullOrEmpty($Description)) { - $Body.snippet.description = $Description - } - - if (![string]::IsNullOrEmpty($PrivacyStatus)) { - $Body.status.privacyStatus = $PrivacyStatus - }else{ - $Body.status.privacyStatus = $currentVideo.items.status.privacyStatus - } - - if (![string]::IsNullOrEmpty($selfDeclaredMadeForKids)) { - $Body.status.selfDeclaredMadeForKids = [bool]$selfDeclaredMadeForKids - }else{ - $Body.status.selfDeclaredMadeForKids = [bool]$currentVideo.items.status.selfDeclaredMadeForKids - } - - if (![string]::IsNullOrEmpty($publishAt)) { - $Body.status.publishAt = (Get-Date).AddDays(2).ToString("yyyy-MM-ddTHH:mm:ssZ") - #https://developers.google.com/youtube/v3/docs/videos/update?hl=de - #status.publishAt: Wenn Sie einen Wert für dieses Attribut festgelegt haben, müssen Sie auch das Attribut status.privacyStatus auf private setzen. - $Body.status.privacyStatus = 'private' - } - - $BodyJSON = $Body | ConvertTo-Json -Depth 10 - - $Headers = (Get-AccessToken) + @{ - 'Content-Type' = 'application/json' - } - - Invoke-RestMethod -Uri $Uri -Headers $Headers -Body $BodyJSON -Method Put - } - - \ No newline at end of file From 1cefa67724316b12aae4954f58d8ba59b6b9619c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Sun, 18 Jun 2023 11:11:07 +0200 Subject: [PATCH 15/16] fix -raw param --- functions/Get-YouTubeChannel.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/Get-YouTubeChannel.ps1 b/functions/Get-YouTubeChannel.ps1 index 7e2c0f2..9f11f4b 100644 --- a/functions/Get-YouTubeChannel.ps1 +++ b/functions/Get-YouTubeChannel.ps1 @@ -26,7 +26,7 @@ function Get-YouTubeChannel { if ($Raw) { return $Result }else{ - $Result + $Result.items } } \ No newline at end of file From e3f00065935daacf8307ae4ee651097a1b0befbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Mon, 3 Jul 2023 22:31:26 +0200 Subject: [PATCH 16/16] Update Get-YouTubeChannel.ps1 --- functions/Get-YouTubeChannel.ps1 | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/functions/Get-YouTubeChannel.ps1 b/functions/Get-YouTubeChannel.ps1 index 9f11f4b..39108f5 100644 --- a/functions/Get-YouTubeChannel.ps1 +++ b/functions/Get-YouTubeChannel.ps1 @@ -23,10 +23,6 @@ function Get-YouTubeChannel { $Result = Invoke-RestMethod -Uri $Uri -Method Get -Headers (Get-AccessToken) $Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Channel') } - if ($Raw) { - return $Result - }else{ - $Result.items - } - -} \ No newline at end of file + if ($Raw) { return $Result } + $Result.items +}