forked from shanselman/PowerPointToOBSSceneSwitcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
95 lines (80 loc) · 3.2 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Office.Interop.PowerPoint;
//Thanks to CSharpFritz and EngstromJimmy for their gists, snippets, and thoughts.
namespace PowerPointToOBSSceneSwitcher
{
class Program
{
private static Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
private static ObsLocal OBS;
static async Task Main(string[] args)
{
Console.Write("Connecting to PowerPoint...");
ppt.SlideShowNextSlide += App_SlideShowNextSlide;
Console.WriteLine("connected");
Console.Write("Connecting to OBS...");
OBS = new ObsLocal();
await OBS.Connect();
Console.WriteLine("connected");
OBS.GetScenes();
Console.ReadLine();
}
async static void App_SlideShowNextSlide(SlideShowWindow Wn)
{
if (Wn != null)
{
Console.WriteLine($"Moved to Slide Number {Wn.View.Slide.SlideNumber}");
//Text starts at Index 2 ¯\_(ツ)_/¯
var note = String.Empty;
try { note = Wn.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text; }
catch { /*no notes*/ }
bool sceneHandled = false;
var notereader = new StringReader(note);
string line;
while ((line = notereader.ReadLine()) != null)
{
if (line.StartsWith("OBS:"))
{
line = line.Substring(4).Trim();
if (!sceneHandled)
{
Console.WriteLine($" Switching to OBS Scene named \"{line}\"");
try
{
sceneHandled = OBS.ChangeScene(line);
}
catch (Exception ex)
{
Console.WriteLine($" ERROR: {ex.Message.ToString()}");
}
}
else
{
Console.WriteLine($" WARNING: Multiple scene definitions found. I used the first and have ignored \"{line}\"");
}
}
if (line.StartsWith("OBSDEF:"))
{
OBS.DefaultScene = line.Substring(7).Trim();
Console.WriteLine($" Setting the default OBS Scene to \"{OBS.DefaultScene}\"");
}
if (line.StartsWith("**START"))
{
OBS.StartRecording();
}
if (line.StartsWith("**STOP"))
{
OBS.StopRecording();
}
if (!sceneHandled)
{
OBS.ChangeScene(OBS.DefaultScene);
Console.WriteLine($" Switching to OBS Default Scene named \"{OBS.DefaultScene}\"");
}
}
}
}
}
}