diff --git a/Pages/profile.cshtml b/Pages/profile.cshtml
index 2209bc9..c264f3d 100644
--- a/Pages/profile.cshtml
+++ b/Pages/profile.cshtml
@@ -12,7 +12,7 @@
var live = StreamUtils.IsLive(user.Username);
Stream stream = null;
if (live) {
- stream = StreamUtils.GetStatsObject().Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.First(p => p.Name == user.Username);
+ stream = StreamUtils.GetStatsObject().Server.Applications.First(p => p.Name == "ingress").MethodLive.Streams.FirstOrDefault(p => p.Name == user.Username);
}
var pronounAdditional = user.PronounSubject == "they" ? "are" : "is"; // TODO make this configurable too
}
@@ -20,7 +20,7 @@
Welcome to @Model.User's page!
@if (live) {
- var videoInfo = $"{stream.Meta.Video.Height}p{Math.Round(double.Parse(stream.Meta.Video.FrameRate))} @ {Math.Round(double.Parse(stream.BwIn) / 1000000, 2)} Mbps";
+ var videoInfo = $"{stream?.Meta.Video.Height ?? "?"}p{Math.Round(double.Parse(stream?.Meta.Video.FrameRate ?? "0"))} @ {Math.Round(double.Parse(stream?.BwIn ?? "0") / 1000000, 2)} Mbps";
@if (!string.IsNullOrWhiteSpace(user.ChatUrl)) {
@user.PronounSubject.FirstCharToUpper() @pronounAdditional currently live! @user.PronounPossessive.FirstCharToUpper() stream chat is located here.
}
@@ -28,10 +28,10 @@
@user.PronounSubject.FirstCharToUpper() @pronounAdditional currently live! @user.PronounSubject.FirstCharToUpper() have not specified a stream chat URL, so enjoy @user.PronounPossessive content!
}
-
Source - @(stream.Meta.Video.Height)p
+
Source - @(stream?.Meta.Video.Height ?? "?")p
@if (user.AllowRestream) {
if ((user.RestreamUrls ?? "").Contains(",")) {
-
Source - @(stream.Meta.Video.Height)p">Twitch Restream
+
Source - @(stream?.Meta.Video.Height ?? "?")p">Twitch Restream
YouTube Restream
}
else if (!string.IsNullOrWhiteSpace(user.RestreamUrls)) {
diff --git a/StreamUtils.cs b/StreamUtils.cs
index b8e22b3..d38aa4f 100644
--- a/StreamUtils.cs
+++ b/StreamUtils.cs
@@ -1,11 +1,12 @@
using System.Collections.Generic;
-using System.IO;
using System.Linq;
using System.Net;
using System.Xml.Serialization;
namespace RTMPDash {
- public class StreamUtils {
+ public static class StreamUtils {
+ private static readonly XmlSerializer Serializer = new(typeof(StatsObject));
+
public static bool IsLive(string user) => GetStatsObject()
.Server.Applications.First(p => p.Name == "ingress")
.MethodLive.Streams.Any(p => p.Name == user);
@@ -16,10 +17,7 @@ namespace RTMPDash {
.ToList();
public static StatsObject GetStatsObject() {
- var serializer = new XmlSerializer(typeof(StatsObject));
- var xml = new WebClient().DownloadString("http://localhost:8080");
- using var reader = new StringReader(xml);
- var obj = (StatsObject) serializer.Deserialize(reader);
+ var obj = (StatsObject) Serializer.Deserialize(new WebClient().OpenRead("http://127.0.0.1:8080")!);
return obj;
}
}