Skip to content

Commit

Permalink
Add all project files for initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pcgeek86 committed Jan 23, 2022
0 parents commit 3a7c4ab
Show file tree
Hide file tree
Showing 27 changed files with 694 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/.github
**/build
**/tests
BuildNumber
README.md
49 changes: 49 additions & 0 deletions .github/workflows/youtube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on:
workflow_dispatch:
push:

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_TAG: ghcr.io/pcgeek86/pwsh-youtube

jobs:
updatebuildnumber:
runs-on: ubuntu-latest
steps:
- name: Clone Project Files
uses: actions/checkout@v2
- name: Update Build Number
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Increment build number
file_pattern: BuildNumber
- name: Increment project build number
shell: pwsh
run: |
[int](Get-Content -Path BuildNumber)+1 | Set-Content -Path BuildNumber
publish:
runs-on: ubuntu-latest
steps:
- name: Clone Project Files
uses: actions/checkout@v2
- run: |
./build/publish.ps1
docker:
permissions:
packages: write
runs-on: ubuntu-latest
steps:
- name: Clone Project Files
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image to GitHub Packages
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ghcr.io/pcgeek86/pwsh-youtube
1 change: 1 addition & 0 deletions BuildNumber
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mcr.microsoft.com/powershell

SHELL [ "pwsh", "-Command" ]

ADD [".", "/youtube"]

RUN $env:PSModulePath += ':/'; \
mkdir --parents $HOME/.config/powershell ; \
Set-Content -Path $PROFILE.CurrentUserAllHosts -Value 'Import-Module -Name /youtube; Set-YouTubeConfiguration'

ENTRYPOINT [ "pwsh" ]
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
### YouTube PowerShell Module

The purpose of this PowerShell module is to enable you to manage YouTube data from PowerShell.

### 🚀 Features

* Search for YouTube videos with queries
* Get details for YouTube videos (ie. duration, like count, comment count)

### 📦 Installation

We recommend installing this module on [PowerShell Core](https://github.com/powershell/powershell) edition, for cross-platform compatibility.
You can install this module from the [PowerShell Gallery](https://powershellgallery.com).

```
Install-Module -Name YouTube -Scope CurrentUser -Force
```

### 📄 Configuration

In order to use this module, you will need to configure an application in [Google Cloud Console](https://console.cloud.google.com).

* Create a Google Cloud Project
* Add the [YouTube Data API v3](https://console.cloud.google.com/marketplace/product/google/youtube.googleapis.com) to your project
* Go to `APIs & Services` --> `Credentials`
* Choose `Create Credentials` --> `oAuth Client ID`
* For `Application Type`, choose `TVs and Limited Input devices`
* Use the generated `Client ID` and `Client Secret` values to configure the module

After doing this, run the following command:

```
Set-YouTubeConfiguration
```

After configuring the client ID and client secret values, you will need to login to your YouTube account.

```
Grant-YouTube
```

### Usage

#### Search for YouTube videos.

```
PS /> Find-YouTubeVideo -Query 'trevor sullivan'
VideoId Channel Title Published Date Title
------- ------------- -------------- -----
LFWxH-bexNk Trevor Sullivan 2/2/2020 9:49:30 PM Handling Errors in PowerShell with Try..Catch..Finally
8dZbdl3wzW8 Trevor Sullivan 12/12/2020 11:01:24 PM Run Tasks on Timers in PowerShell
jh361zZvOlg Trevor Sullivan 1/21/2016 6:27:39 PM Trevor Sullivan: Organ donation makes a difference (full clip)
4Ink31WKRmQ Midwest Management Summit 3/24/2016 2:20:03 AM MMS 2016 Speaker Interview - Trevor Sullivan
-nGpXnjQVIQ Trevor Sullivan - NanangoCFC 1/16/2022 1:26:24 PM 2022.01.16 Isaiah 64 - The Heart's Cry of Believers in a Fallen World
8D23XL0b4zo Trevor Sullivan - NanangoCFC 1/22/2022 11:35:13 PM 2022.01.23 Isaiah 65 New Heavens & New Earth
Y3_N9S6ZoEg Midwest Management Summit 10/13/2015 5:24:33 AM MMS 2015 - Speaker Interview - Trevor Sullivan
bO264A6eoW0 Trevor Sullivan 5/6/2019 3:11:15 AM Original Choreography by Trevor Sullivan
-7uuXvQrvX8 Midwest Management Summit 10/25/2014 8:31:09 PM MMS Speaker Interview - David O'Brien and Trevor Sullivan
qwwnbXSm700 Trevor Sullivan 11/12/2015 5:32:39 AM Authoring Custom PowerShell Intellisense with Trevor Sullivan
D5W1HarSaZU Ignite Talks Burlington 2/26/2019 1:11:32 AM Trevor Sullivan - Broccoli. Broccoli? BROCCOLI! - IgniteBTV 2/20/2019
tPs2ROyqrxI Trevor Sullivan 1/20/2022 7:07:15 AM Ya daddy
VqKD3JjA7Eo The QB School 12/22/2021 2:00:11 PM Free Trevor
qye_c4_pWQ4 CBT Nuggets 1/18/2022 12:15:13 PM What is InfluxDB and Why Use It?
```

#### Get Details for a YouTube Video

```
PS /> Get-YouTubeVideo -Id LFWxH-bexNk
VideoId Channel Title Views Likes Dislikes Comments Duration
------- ------------- ----- ----- -------- -------- --------
LFWxH-bexNk Trevor Sullivan 6307 265 0 22 PT18M48S
```

#### Get Details for Multiple YouTube Videos

```
Get-YouTubeVideo -Id LFWxH-bexNk,8dZbdl3wzW8
VideoId Channel Title Views Likes Dislikes Comments Duration
------- ------------- ----- ----- -------- -------- --------
LFWxH-bexNk Trevor Sullivan 6307 265 0 22 PT18M48S
8dZbdl3wzW8 Trevor Sullivan 4035 150 0 10 PT17M8S
```
31 changes: 31 additions & 0 deletions build/publish.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
params (
[string] $PSGalleryApiKey
)

# Purpose: Cleans the module directory to prepare for publication to PowerShell Gallery
$ErrorActionPreference = 'stop'
$ModulePath = "$PSScriptRoot/../"

# Build directory should work on Windows or Linux
$BuildDirectory = $env:TEMP ? "$env:TEMP/YouTube" : "/tmp/YouTube"

# These project paths will be excluded from the module during publishing
$Exclude = @(
'README.md'
'tests'
'.github'
'BuildNumber'
)

# Copy project to temporary build directory
Remove-Item -Path $BuildDirectory -Recurse -Force
$null = New-Item -ItemType Directory -Path $BuildDirectory
Write-Host -Object 'Created build directory'
Copy-Item -Exclude $Exclude -Path $ModulePath/* -Destination $BuildDirectory -Recurse
Write-Host -Object 'Copied all items to build directory'

# Replace module version with build number
$ManifestPath = "$BuildDirectory/youtube.psd1"
(Get-Content -Path $ManifestPath -Raw) -replace 'ModuleVersion = ''0.1''', ('ModuleVersion = ''0.1.{0}''' -f (Get-Content -Path $ModulePath/BuildNumber)) | Set-Content -Path $ManifestPath

Publish-Module -Path $BuildDirectory -NuGetApiKey $PSGalleryApiKey
63 changes: 63 additions & 0 deletions formats/YouTube.CommentThread.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Configuration>
<ViewDefinitions>
<View>
<Name>Table</Name>
<ViewSelectedBy>
<TypeName>YouTube.CommentThread</TypeName>
</ViewSelectedBy>
<TableControl>
<AutoSize></AutoSize>
<TableHeaders>
<TableColumnHeader>
<Label>CommentId</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>PublishedAt</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Updated At</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Replies</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Like Count</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Commenter</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Text</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.id</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.topLevelComment.snippet.publishedAt</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.topLevelComment.snippet.updatedAt</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.totalReplyCount</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.topLevelComment.snippet.likeCount</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.topLevelComment.snippet.authorDisplayName</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.topLevelComment.snippet.textDisplay</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
63 changes: 63 additions & 0 deletions formats/YouTube.Video.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<Configuration>
<ViewDefinitions>
<View>
<Name>Table</Name>
<ViewSelectedBy>
<TypeName>YouTube.Video</TypeName>
</ViewSelectedBy>
<TableControl>
<AutoSize></AutoSize>
<TableHeaders>
<TableColumnHeader>
<Label>VideoId</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Channel Title</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Views</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Likes</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Dislikes</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Comments</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Duration</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.id</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.channelTitle</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.statistics.viewCount</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.statistics.likeCount</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.statistics.dislikeCount</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.statistics.commentCount</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.contentDetails.duration</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
45 changes: 45 additions & 0 deletions formats/YouTube.VideoResult.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<Configuration>
<ViewDefinitions>
<View>
<Name>Table</Name>
<ViewSelectedBy>
<TypeName>YouTube.VideoResult</TypeName>
</ViewSelectedBy>
<TableControl>
<AutoSize></AutoSize>
<TableHeaders>
<TableColumnHeader>
<Label>VideoId</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Channel Title</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Published Date</Label>
</TableColumnHeader>
<TableColumnHeader>
<Label>Title</Label>
</TableColumnHeader>
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
<TableColumnItems>
<TableColumnItem>
<ScriptBlock>$_.id.videoId</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.channelTitle</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.publishedAt</ScriptBlock>
</TableColumnItem>
<TableColumnItem>
<ScriptBlock>$_.snippet.title</ScriptBlock>
</TableColumnItem>
</TableColumnItems>
</TableRowEntry>
</TableRowEntries>
</TableControl>
</View>
</ViewDefinitions>
</Configuration>
20 changes: 20 additions & 0 deletions functions/Find-YouTubeVideo.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function Find-YouTubeVideo {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $Query,
[string] $PageToken,
[switch] $Raw
)
$Uri = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&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.VideoResult') }
$Result.Items
}
Loading

0 comments on commit 3a7c4ab

Please sign in to comment.