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);
|
var live = StreamUtils.IsLive(user.Username);
|
||||||
Stream stream = null;
|
Stream stream = null;
|
||||||
if (live) {
|
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
|
var pronounAdditional = user.PronounSubject == "they" ? "are" : "is"; // TODO make this configurable too
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h3 class="display">Welcome to @Model.User's page!</h3>
|
<h3 class="display">Welcome to @Model.User's page!</h3>
|
||||||
@if (live) {
|
@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)) {
|
@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>
|
<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>
|
<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">
|
<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.AllowRestream) {
|
||||||
if ((user.RestreamUrls ?? "").Contains(",")) {
|
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>
|
<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)) {
|
else if (!string.IsNullOrWhiteSpace(user.RestreamUrls)) {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace RTMPDash {
|
namespace RTMPDash {
|
||||||
public class StreamUtils {
|
public static class StreamUtils {
|
||||||
|
private static readonly XmlSerializer Serializer = new(typeof(StatsObject));
|
||||||
|
|
||||||
public static bool IsLive(string user) => GetStatsObject()
|
public static bool IsLive(string user) => GetStatsObject()
|
||||||
.Server.Applications.First(p => p.Name == "ingress")
|
.Server.Applications.First(p => p.Name == "ingress")
|
||||||
.MethodLive.Streams.Any(p => p.Name == user);
|
.MethodLive.Streams.Any(p => p.Name == user);
|
||||||
|
@ -16,10 +17,7 @@ namespace RTMPDash {
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
public static StatsObject GetStatsObject() {
|
public static StatsObject GetStatsObject() {
|
||||||
var serializer = new XmlSerializer(typeof(StatsObject));
|
var obj = (StatsObject) Serializer.Deserialize(new WebClient().OpenRead("http://127.0.0.1:8080")!);
|
||||||
var xml = new WebClient().DownloadString("http://localhost:8080");
|
|
||||||
using var reader = new StringReader(xml);
|
|
||||||
var obj = (StatsObject) serializer.Deserialize(reader);
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue