Skip to content

Commit 379a946

Browse files
Merge pull request #72 from StartAutomating/Show-OBS
obs-powershell 0.1.7
2 parents 89b8b06 + 50e22a1 commit 379a946

File tree

168 files changed

+4672
-899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+4672
-899
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## obs-powershell 0.1.7:
2+
3+
* New Commands:
4+
* Show-OBS (Fixes #66)
5+
* Hide-OBS (Fixes #67)
6+
* Remove-OBS (Fixes #68)
7+
8+
* Adding -Force to Add-OBS*Source commands (Fixes #69)
9+
* Add-OBS*Source Commands: Supporting -SceneItemEnabled (Fixes #70)
10+
* Add-OBSMediaSource, adding -FitToScreen (Fixes #71)
11+
12+
---
13+
114
## obs-powershell 0.1.6:
215

316
* Adding OBS.SceneItem .Scale (Fixes #64)

Commands/Hide-OBS.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function Hide-OBS {
2+
<#
3+
.SYNOPSIS
4+
Hide OBS
5+
.DESCRIPTION
6+
Hides items in OBS
7+
.EXAMPLE
8+
Hide-OBS -SourceName "foo"
9+
.LINK
10+
Set-OBSSceneItemEnabled
11+
#>
12+
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='Medium')]
13+
param(
14+
# The name of the item we want to Hide
15+
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
16+
[Alias('SourceName','InputName')]
17+
$ItemName,
18+
19+
# The name of the scene. If not provided, the current program scene will be used.
20+
[Parameter(ValueFromPipelineByPropertyName)]
21+
[string]
22+
$SceneName
23+
)
24+
25+
process {
26+
# If no scene was provided
27+
if (-not $SceneName) {
28+
# find the current program scene
29+
$sceneName = Get-OBSCurrentProgramScene
30+
}
31+
32+
# Walk over all items in the scene
33+
foreach ($sceneItem in Get-OBSSceneItem -SceneName $SceneName) {
34+
# If the match our wildcard and we confirm, remove it.
35+
if ($sceneItem.SourceName -like $ItemName -and
36+
$PSCmdlet.ShouldProcess("Hide input $($sceneItem.SourceName)")) {
37+
# Hide it.
38+
$sceneItem | Set-OBSSceneItemEnabled -SceneItemEnabled:$false
39+
}
40+
}
41+
}
42+
}
43+

Commands/Remove-OBS.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
function Remove-OBS {
2+
<#
3+
.SYNOPSIS
4+
Remove OBS
5+
.DESCRIPTION
6+
Removes items from OBS
7+
.EXAMPLE
8+
Remove-OBS -SourceName "foo"
9+
.EXAMPLE
10+
Remove-OBS -SceneName "bar"
11+
.LINK
12+
Remove-OBSInput
13+
.LINK
14+
Remove-OBSScene
15+
#>
16+
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')]
17+
param(
18+
# The name of the item we want to remove
19+
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
20+
[Alias('SourceName','InputName','SceneName')]
21+
$ItemName
22+
)
23+
24+
process {
25+
# If we remove an input, we don't want to remove a scene
26+
$removedAnInput = $false
27+
# Go over each input
28+
foreach ($obsInput in Get-OBSInput) {
29+
# If it matches our wildcard and we confirm
30+
if ($obsInput.InputName -like $ItemName -and
31+
$PSCmdlet.ShouldProcess("Remove input $($obsInput.InputName)")) {
32+
# remove it.
33+
Remove-OBSInput -InputName $obsInput.InputName
34+
$removedAnInput = $true
35+
}
36+
}
37+
38+
# Return if we removed an input.
39+
if ($removedAnInput) { return }
40+
41+
# Go over all scenes
42+
foreach ($obsScene in (Get-OBSScene).Scenes) {
43+
# If the name matches our wildcard and we confirm
44+
if ($obsScene.SceneName -like $ItemName -and
45+
$PSCmdlet.ShouldProcess("Remove scene $($obsScene.SceneName)")) {
46+
# remove the scene.
47+
Remove-OBSScene -SceneName $obsScene.SceneName
48+
}
49+
}
50+
}
51+
}

Commands/Show-OBS.ps1

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
function Show-OBS {
2+
<#
3+
.SYNOPSIS
4+
Shows content in OBS
5+
.DESCRIPTION
6+
Shows content in Open Broadcasting Studio
7+
.EXAMPLE
8+
'<svg viewBox="0 0 1 1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">
9+
<polygon points="0 0 0 1 1 1 1 0" fill="blue" />
10+
</svg>' | Set-Content .\BlueRect.svg
11+
Show-OBS -FilePath .\BlueRect.svg
12+
.EXAMPLE
13+
Show-OBS -FilePath *excited* -RootPath $home\Pictures\Gif
14+
#>
15+
param(
16+
# The path or URI to show in OBS.
17+
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
18+
[Alias('FullName','Src', 'Uri','FileName')]
19+
[string]
20+
$FilePath,
21+
22+
# The name of the source in OBS.
23+
# If this is not provided, it will be derived from the -FilePath.
24+
[Parameter(ValueFromPipelineByPropertyName)]
25+
[string]
26+
$Name,
27+
28+
# A root path.
29+
# If not provided, this will be the root of the -FilePath (if it is a filepath).
30+
# If the file path was a URI, the root path will be ignored.
31+
[Parameter(ValueFromPipelineByPropertyName)]
32+
[string]
33+
$RootPath,
34+
35+
# The name of the scene.
36+
# If no scene name is provided, the current program scene will be used.
37+
[Parameter(ValueFromPipelineByPropertyName)]
38+
[string]
39+
$Scene,
40+
41+
# The opacity to use for the input.
42+
# If not provided, will default to 2/3rds.
43+
# Will only be used when showing a browser source with a -FilePath
44+
[Parameter(ValueFromPipelineByPropertyName)]
45+
[double]
46+
$Opacity = (2/3),
47+
48+
# Any parameters to pass to the source command.
49+
[Parameter(ValueFromPipelineByPropertyName)]
50+
[Collections.IDictionary]
51+
$SourceParameter = [ordered]@{},
52+
53+
# If set, will check if the source exists in the scene before creating it and removing any existing sources found.
54+
# If not set, you will get an error if a source with the same name exists.
55+
[Parameter(ValueFromPipelineByPropertyName)]
56+
[switch]
57+
$Force,
58+
59+
# If set, will make the input become the size of the screen.
60+
[Parameter(ValueFromPipelineByPropertyName)]
61+
[switch]
62+
$FitToScreen
63+
)
64+
65+
begin {
66+
filter FitToScreenAndOutput {
67+
if ($FitToScreen -and $_.FitToScreen) {
68+
$_.FitToScreen()
69+
}
70+
$_
71+
}
72+
}
73+
74+
process {
75+
# If we had a -RootPath
76+
if ($RootPath) {
77+
# Look in the root path
78+
$imageFiles = @(Get-ChildItem $RootPath -Recurse -File|
79+
# For files like this keyword
80+
Where-Object FullName -like "*$filePath*" |
81+
# that are extensions we could show
82+
Where-Object Extension -in '.html', '.jpg', '.jpeg', '.gif', '.apng', '.png'
83+
)
84+
if ($imageFiles.Count) {
85+
$FilePath = ($imageFiles | Get-Random).FullName
86+
}
87+
}
88+
89+
90+
91+
# Determine if the thing we are showing will be a ffmpeg source.
92+
$IsMediaSource =
93+
# If it's an http path, it's not
94+
if ($FilePath -like 'http*') {
95+
$false
96+
} elseif (
97+
# If it's an HTML-friendly path, it's not
98+
$FilePath -match '.(?>html?|gif|jpe?g|a?png|svg)$'
99+
) {
100+
$false
101+
} else {
102+
# Otherwise, let's give it a try.
103+
$true
104+
}
105+
106+
if (-not $RootPath -and $filePath -notlike 'http*') {
107+
$RootPath = "$($FilePath | Split-Path)"
108+
}
109+
110+
# If we provided a scene
111+
if ($Scene) {
112+
# pass it down.
113+
$SourceParameter.Scene = $Scene
114+
}
115+
116+
# If we want to use -Force
117+
if ($Force) {
118+
# pass it down
119+
$SourceParameter.Force = $Force
120+
}
121+
122+
# If we do not want to create a media source,
123+
if (-not $IsMediaSource) {
124+
# we create a browser source.
125+
$SourceParameter.Uri = $FilePath
126+
# If the path was not already HTML,
127+
if ($RootPath -and $FilePath -notmatch '\.html{0,1}$') {
128+
# we make a minimal frame in a .html file
129+
$relativePath = $FilePath.Substring($RootPath.Length + 1)
130+
$htmlFrame = "<html>
131+
<body style='width:100%;height:100%'>
132+
<img src='$relativePath' style='width:100%;height:100%' />'
133+
<body>
134+
</html>"
135+
136+
$leafPath = $filePath | Split-Path -Leaf
137+
$htmlPath = Join-Path $RootPath "$($leafPath).html"
138+
139+
$htmlFrame | Set-Content -Path $htmlPath
140+
# And set up the CSS for that frame, passing down -Opacity.
141+
# (this may not work for all images)
142+
$css = "
143+
body {
144+
background-color: rgba(0, 0, 0, 0); margin: 0px auto; overflow: hidden;
145+
}
146+
img {
147+
width: 100%
148+
height: 100%;
149+
opacity: $opacity;
150+
}
151+
"
152+
$SourceParameter.Uri = $htmlPath
153+
$SourceParameter.CSS = $css
154+
Add-OBSBrowserSource @SourceParameter | FitToScreenAndOutput
155+
} else {
156+
Add-OBSBrowserSource @SourceParameter | FitToScreenAndOutput
157+
}
158+
159+
} else {
160+
$SourceParameter.FilePath = $FilePath
161+
Add-OBSMediaSource @SourceParameter | FitToScreenAndOutput
162+
}
163+
}
164+
}

Commands/Sources/Add-OBSBrowserSource.ps.ps1

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ function Add-OBSBrowserSource
7575
# If no name is provided, the last segment of the URI or file path will be the input name.
7676
[Parameter(ValueFromPipelineByPropertyName)]
7777
[string]
78-
$Name
78+
$Name,
79+
80+
# If set, will check if the source exists in the scene before creating it and removing any existing sources found.
81+
# If not set, you will get an error if a source with the same name exists.
82+
[Parameter(ValueFromPipelineByPropertyName)]
83+
[switch]
84+
$Force
7985
)
8086

8187
process {
@@ -144,8 +150,29 @@ function Add-OBSBrowserSource
144150
}
145151
}
146152

153+
# If -Force is provided
154+
if ($Force) {
155+
# Clear any items from that scene
156+
Get-OBSSceneItem -sceneName $myParameters["Scene"] |
157+
Where-Object SourceName -eq $name |
158+
Remove-OBSInput -InputName { $_.SourceName }
159+
}
160+
161+
162+
$addObsInputParams = [Ordered]@{
163+
sceneName = $myParameters["Scene"]
164+
inputKind = "browser_source"
165+
inputSettings = $myParameterData
166+
inputName = $Name
167+
}
168+
# If -SceneItemEnabled was passed,
169+
if ($myParameters.Contains('SceneItemEnabled')) {
170+
# propagate it to Add-OBSInput.
171+
$addObsInputParams.SceneItemEnabled = $myParameters['SceneItemEnabled'] -as [bool]
172+
}
173+
147174
$outputAddedResult =
148-
Add-OBSInput -sceneName $myParameters["Scene"] -inputKind "browser_source" -inputSettings $myParameterData -inputName $Name
175+
Add-OBSInput @addObsInputParams
149176

150177
if ($outputAddedResult) {
151178
Get-OBSSceneItem -sceneName $myParameters["Scene"] |

Commands/Sources/Add-OBSBrowserSource.ps1

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ function Add-OBSBrowserSource {
6464
# If no name is provided, the last segment of the URI or file path will be the input name.
6565
[Parameter(ValueFromPipelineByPropertyName)]
6666
[string]
67-
$Name
67+
$Name,
68+
# If set, will check if the source exists in the scene before creating it and removing any existing sources found.
69+
# If not set, you will get an error if a source with the same name exists.
70+
[Parameter(ValueFromPipelineByPropertyName)]
71+
[switch]
72+
$Force
6873
)
6974
dynamicParam {
7075
$baseCommand =
@@ -160,8 +165,27 @@ dynamicParam {
160165
$uri
161166
}
162167
}
168+
# If -Force is provided
169+
if ($Force) {
170+
# Clear any items from that scene
171+
Get-OBSSceneItem -sceneName $myParameters["Scene"] |
172+
Where-Object SourceName -eq $name |
173+
Remove-OBSInput -InputName { $_.SourceName }
174+
}
175+
$addObsInputParams = [Ordered]@{
176+
sceneName = $myParameters["Scene"]
177+
inputKind = "browser_source"
178+
inputSettings = $myParameterData
179+
inputName = $Name
180+
}
181+
# If -SceneItemEnabled was passed,
182+
if ($myParameters.Contains('SceneItemEnabled')) {
183+
# propagate it to Add-OBSInput.
184+
$addObsInputParams.SceneItemEnabled = $myParameters['SceneItemEnabled'] -as [bool]
185+
}
186+
163187
$outputAddedResult =
164-
Add-OBSInput -sceneName $myParameters["Scene"] -inputKind "browser_source" -inputSettings $myParameterData -inputName $Name
188+
Add-OBSInput @addObsInputParams
165189
if ($outputAddedResult) {
166190
Get-OBSSceneItem -sceneName $myParameters["Scene"] |
167191
Where-Object SourceName -eq $name

0 commit comments

Comments
 (0)