Null-safety for new StreamUtils; improve efficiency for nginx-rtmp stats
This commit is contained in:
parent
a5418a6641
commit
4c6782854c
|
@ -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 @@
|
|||
<div class="text-center">
|
||||
<h3 class="display">Welcome to @Model.User's page!</h3>
|
||||
@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)) {
|
||||
<p>@user.PronounSubject.FirstCharToUpper() @pronounAdditional currently live! @user.PronounPossessive.FirstCharToUpper() stream chat is located <a href="@user.ChatUrl" target="_blank">here</a>.</p>
|
||||
}
|
||||
|
@ -28,10 +28,10 @@
|
|||
<p>@user.PronounSubject.FirstCharToUpper() @pronounAdditional currently live! @user.PronounSubject.FirstCharToUpper() have not specified a stream chat URL, so enjoy @user.PronounPossessive content!</p>
|
||||
}
|
||||
<div class="btn-group btn-group-lg" role="group">
|
||||
<a href="@Program.PlayerDomain/@user.Username" target="_blank" role="button" class="btn btn-success" data-toggle="tooltip" data-placement="bottom" title="@videoInfo">Source - @(stream.Meta.Video.Height)p</a>
|
||||
<a href="@Program.PlayerDomain/@user.Username" target="_blank" role="button" class="btn btn-success" data-toggle="tooltip" data-placement="bottom" title="@videoInfo">Source - @(stream?.Meta.Video.Height ?? "?")p</a>
|
||||
@if (user.AllowRestream) {
|
||||
if ((user.RestreamUrls ?? "").Contains(",")) {
|
||||
<a href="@user.RestreamUrls!.Split(",")[0]" target="_blank" role="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="@videoInfo">Source - @(stream.Meta.Video.Height)p">Twitch Restream</a>
|
||||
<a href="@user.RestreamUrls!.Split(",")[0]" target="_blank" role="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="@videoInfo">Source - @(stream?.Meta.Video.Height ?? "?")p">Twitch Restream</a>
|
||||
<a href="@user.RestreamUrls!.Split(",")[1]" target="_blank" role="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="Source @@ 10Mbit VBR">YouTube Restream</a>
|
||||
}
|
||||
else if (!string.IsNullOrWhiteSpace(user.RestreamUrls)) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue