-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📽️ Add YouTube Activity and Subscription support 📺
- Loading branch information
Showing
12 changed files
with
271 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<Configuration> | ||
<ViewDefinitions> | ||
<View> | ||
<Name>Table</Name> | ||
<ViewSelectedBy> | ||
<TypeName>YouTube.Activity</TypeName> | ||
</ViewSelectedBy> | ||
<TableControl> | ||
<AutoSize></AutoSize> | ||
<TableHeaders> | ||
<TableColumnHeader> | ||
<Label>Title</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>Type</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>Published At</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>SubscriptionId</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>ChannelId</Label> | ||
</TableColumnHeader> | ||
</TableHeaders> | ||
<TableRowEntries> | ||
<TableRowEntry> | ||
<TableColumnItems> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.title</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.type</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.publishedAt</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.id</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.channelId</ScriptBlock> | ||
</TableColumnItem> | ||
</TableColumnItems> | ||
</TableRowEntry> | ||
</TableRowEntries> | ||
</TableControl> | ||
</View> | ||
</ViewDefinitions> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<Configuration> | ||
<ViewDefinitions> | ||
<View> | ||
<Name>Table</Name> | ||
<ViewSelectedBy> | ||
<TypeName>YouTube.Search.ChannelResult</TypeName> | ||
</ViewSelectedBy> | ||
<TableControl> | ||
<AutoSize></AutoSize> | ||
<TableHeaders> | ||
<TableColumnHeader> | ||
<Label>Channel Title</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>Published Date</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>ChannelId</Label> | ||
</TableColumnHeader> | ||
</TableHeaders> | ||
<TableRowEntries> | ||
<TableRowEntry> | ||
<TableColumnItems> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.channelTitle</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.publishedAt</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.id.channelId</ScriptBlock> | ||
</TableColumnItem> | ||
</TableColumnItems> | ||
</TableRowEntry> | ||
</TableRowEntries> | ||
</TableControl> | ||
</View> | ||
</ViewDefinitions> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<Configuration> | ||
<ViewDefinitions> | ||
<View> | ||
<Name>Table</Name> | ||
<ViewSelectedBy> | ||
<TypeName>YouTube.Subscription</TypeName> | ||
</ViewSelectedBy> | ||
<TableControl> | ||
<AutoSize></AutoSize> | ||
<TableHeaders> | ||
<TableColumnHeader> | ||
<Label>Title</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>Items</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>Published At</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>SubscriptionId</Label> | ||
</TableColumnHeader> | ||
<TableColumnHeader> | ||
<Label>ChannelId</Label> | ||
</TableColumnHeader> | ||
</TableHeaders> | ||
<TableRowEntries> | ||
<TableRowEntry> | ||
<TableColumnItems> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.title</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.contentDetails.totalItemCount</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.publishedAt</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.id</ScriptBlock> | ||
</TableColumnItem> | ||
<TableColumnItem> | ||
<ScriptBlock>$_.snippet.channelId</ScriptBlock> | ||
</TableColumnItem> | ||
</TableColumnItems> | ||
</TableRowEntry> | ||
</TableRowEntries> | ||
</TableControl> | ||
</View> | ||
</ViewDefinitions> | ||
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
function Find-YouTubeChannel { | ||
<# | ||
.SYNOPSIS | ||
Search for YouTube channels based on a query term. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string] $Query, | ||
[string] $PageToken, | ||
[switch] $Raw | ||
) | ||
$Uri = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel&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.ChannelResult') } | ||
$Result.Items | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
function Get-YouTubeActivity { | ||
<# | ||
.SYNOPSIS | ||
Obtain activities performed by yourself or a specific channel ID. | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(ParameterSetName = 'ChannelId')] | ||
[string] $ChannelId, | ||
[Parameter(ParameterSetName = 'Mine')] | ||
[switch] $Mine, | ||
[Parameter(ParameterSetName = 'ChannelId')] | ||
[Parameter(ParameterSetName = 'Mine')] | ||
[switch] $Raw | ||
) | ||
|
||
$Uri = 'https://www.googleapis.com/youtube/v3/activities?part=id,snippet,contentDetails&maxResults=50' | ||
|
||
switch ($PSCmdlet.ParameterSetName) { | ||
'Mine' { | ||
$Uri += '&mine=true' | ||
break | ||
} | ||
'ChannelId' { | ||
$Uri += '&channelId={0}' -f $ChannelId | ||
} | ||
} | ||
$Result = Invoke-RestMethod -Uri $Uri -Headers (Get-AccessToken) | ||
|
||
$Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Activity') } | ||
|
||
if ($PSBoundParameters.ContainsKey('Raw')) { $Result } | ||
|
||
$Result.items | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function Get-YouTubeSubscription { | ||
[CmdletBinding()] | ||
param ( | ||
[string] $NextPageToken, | ||
[switch] $Raw | ||
) | ||
|
||
$Uri = 'https://www.googleapis.com/youtube/v3/subscriptions?part=id,contentDetails,snippet,subscriberSnippet&mine=true&maxResults=50' | ||
if ($PSBoundParameters.ContainsKey('NextPageToken')) { | ||
$Uri += '&pageToken={0}' -f $NextPageToken | ||
Write-Verbose -Message 'Added next page token' | ||
} | ||
$Result = Invoke-RestMethod -Uri $Uri -Headers (Get-AccessToken) | ||
|
||
$Result.items | ForEach-Object -Process { $PSItem.PSTypeNames.Add('YouTube.Subscription') } | ||
|
||
if ($PSBoundParameters.ContainsKey('Raw')) { return $Result } | ||
|
||
$Result.items | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
function Remove-YouTubeSubscription { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[string] $Id | ||
) | ||
$Uri = 'https://www.googleapis.com/youtube/v3/subscriptions?id={0}' -f $Id | ||
Invoke-RestMethod -Uri $Uri -Method Delete -Headers (Get-AccessToken) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Import-Module -Name $PSScriptRoot/../ -Force | ||
|
||
$Activities = Get-YouTubeActivity -Mine | ||
|
||
$Activities | ||
|
||
Get-YouTubeActivity -ChannelId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Import-Module -Name $PSScriptRoot/../ -Force | ||
|
||
$Result = Find-YouTubeChannel -Query 'trevor sullivan' | ||
|
||
#$Result | ConvertTo-Json -Depth 10 | Set-Content -Path ("$HOME/{0}.json" -f (New-Guid).Guid) | ||
|
||
$Result.snippet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Import-Module -Name $PSScriptRoot/../ -Force | ||
|
||
$Subscriptions = Get-YouTubeSubscription | ||
|
||
Remove-YouTubeSubscription -Id RsdxlJShC6cmvtxrXi97D2DP2WSbPO0-RJocte_4xbE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Import-Module -Name $PSScriptRoot/../ -Force | ||
|
||
$Subscriptions = Get-YouTubeSubscription | ||
|
||
$Subscriptions.items[0].snippet.title | ||
$Subscriptions.items[0].contentDetails | ||
|
||
$AllResults = @() | ||
$RawResult = Get-YouTubeSubscription -Raw | ||
$AllResults += $RawResult | ||
$RawResult = Get-YouTubeSubscription -Raw -NextPageToken $RawResult.nextPageToken | ||
$AllResults += $RawResult | ||
$RawResult = Get-YouTubeSubscription -Raw -NextPageToken $RawResult.nextPageToken | ||
$AllResults += $RawResult | ||
$RawResult = Get-YouTubeSubscription -Raw -NextPageToken $RawResult.nextPageToken | ||
$AllResults += $RawResult | ||
|
||
$AllResults.items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
RootModule = 'youtube.psm1' | ||
Author = 'Trevor Sullivan <[email protected]>' | ||
CompanyName = 'Trevor Sullivan' | ||
ModuleVersion = '0.1' | ||
ModuleVersion = '0.2' | ||
GUID = '4f1448cd-300f-444c-afdf-8ed678504ffd' | ||
Copyright = '2022 Trevor Sullivan' | ||
Description = 'Manage YouTube from the command line with PowerShell.' | ||
|
@@ -12,12 +12,16 @@ | |
'Grant-YouTube' | ||
'Grant-YouTubeOauth' | ||
'Find-YouTubeVideo' | ||
'Find-YouTubeChannel' | ||
'Get-YouTubeVideo' | ||
'Set-YouTubeConfiguration' | ||
'Get-YouTubeCommentThread' | ||
'Get-YouTubeComment' | ||
'New-YouTubeComment' | ||
'Remove-YouTubeComment' | ||
'Get-YouTubeSubscription' | ||
'Remove-YouTubeSubscription' | ||
'Get-YouTubeActivity' | ||
) | ||
AliasesToExport = @('') | ||
VariablesToExport = @('') | ||
|