-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
115 lines (98 loc) · 3.18 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using CefSharp.OffScreen;
using CefSharp;
using MyPoorConsoleChat.Chat;
using System;
using System.IO;
using System.Threading;
namespace MyPoorConsoleChat
{
internal class Program
{
private static Read ChatYoutube;
private static Read ChatTwitch;
static void Main(string[] args)
{
string channelYT = GetArgumentValue(args, "-yt");
string channelTW = GetArgumentValue(args, "-tw");
if (string.IsNullOrEmpty(channelYT))
{
Console.Clear();
channelYT = SetChannel("YouTube", "Insert YouTube channel URL that is currently live streaming:\n(Leave blank if not in use)\n");
}
if (string.IsNullOrEmpty(channelTW))
{
Console.Clear();
channelTW = SetChannel("Twitch", "Insert Twitch channel username:\n(Leave blank if not in use)\n");
}
InitializeCefSharp();
Console.Clear();
Console.WriteLine("Press 'q' to exit...");
Thread.Sleep(5000);
StartChat(channelYT, false);
StartChat(channelTW, true);
while (Console.ReadKey(true).Key != ConsoleKey.Q)
{
}
StopChat(ChatYoutube);
StopChat(ChatTwitch);
Cef.Shutdown();
}
static void InitializeCefSharp()
{
var settings = new CefSettings()
{
LogSeverity = LogSeverity.Disable,
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache")
};
Cef.Initialize(settings, performDependencyCheck: true, browserProcessHandler: null);
}
static void StartChat(string channel, bool isTwitch)
{
if (!string.IsNullOrEmpty(channel))
{
var chat = new Read();
chat.Start(isTwitch, channel);
if (isTwitch)
{
ChatTwitch = chat;
}
else
{
ChatYoutube = chat;
}
}
}
static void StopChat(Read chat)
{
if (chat != null && chat.IsConnected)
{
chat.Stop();
}
}
static string GetArgumentValue(string[] args, string argumentName)
{
foreach (string arg in args)
{
if (arg.StartsWith($"{argumentName}="))
{
return arg.Substring(argumentName.Length + 1);
}
}
return null;
}
static string SetChannel(string platform, string promptMessage)
{
Console.WriteLine(promptMessage);
var input = Console.ReadLine()?.Trim();
if (!string.IsNullOrEmpty(input))
{
if (platform.Equals("YouTube", StringComparison.OrdinalIgnoreCase))
{
return Livestream.GetChatUrl(input);
}
return input;
}
return null;
}
}
}