Skip to content

Commit

Permalink
Add search playlist functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pcgeek86 committed Aug 8, 2023
1 parent a6544c9 commit f8f73ac
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
55 changes: 55 additions & 0 deletions formats/YouTube.Search.Playlist.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<Configuration>
<ViewDefinitions>
<View>
<Name>Table</Name>
<ViewSelectedBy>
<TypeName>YouTube.Search.PlaylistResult</TypeName>
</ViewSelectedBy>
<TableControl>
<TableHeaders>
<TableColumnHeader>
<Label>ID</Label>
<Width>34</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Published Date</Label>
<Width>22</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Title</Label>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>ChannelId</Label>
<Width>28</Width>
</TableColumnHeader>
<TableColumnHeader>
<Label>Channel Title</Label>
<Width>25</Width>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.id.playlistId</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.publishedAt</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.title</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.channelId</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.channelTitle</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
27 changes: 27 additions & 0 deletions functions/Find-YouTubePlaylist.ps1
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 7 additions & 1 deletion functions/Grant-YouTube.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions youtube.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'Grant-YouTubeOauth'
'Find-YouTubeVideo'
'Find-YouTubeChannel'
'Find-YouTubePlaylist'
'Get-YouTubeVideo'
'Set-YouTubeConfiguration'
'Get-YouTubeCommentThread'
Expand All @@ -25,6 +26,7 @@
'Get-YouTubeActivity'
'Get-YouTubeChannel'
'Set-YouTubeVideoRating'

)
AliasesToExport = @('')
VariablesToExport = @('')
Expand Down

0 comments on commit f8f73ac

Please sign in to comment.