Make actual use of the new stats object; remove SrcRes database object

This commit is contained in:
Laura Hausmann 2021-01-25 19:43:05 +01:00
parent fce7380d19
commit 70bb5c49cd
Signed by: zotan
GPG Key ID: 5EC1D38FFC321311
8 changed files with 16 additions and 49 deletions

View File

@ -12,7 +12,6 @@ namespace RTMPDash.DataModels.Tables {
[Column(Name = "PronounPossessive")] public string PronounPossessive { get; set; }
[Column(Name = "ChatUrl")] public string ChatUrl { get; set; }
[Column(Name = "AnnouncementUrl")] public string AnnouncementUrl { get; set; }
[Column(Name = "SrcRes")] public string SrcRes { get; set; }
[Column(Name = "RestreamTargets")] public string RestreamTargets { get; set; }
[Column(Name = "RestreamUrls")] public string RestreamUrls { get; set; }
}

View File

@ -104,26 +104,6 @@ else {
</div>
</form>
if (user.SrcRes == "unspecified") {
<div class="alert alert-warning" role="alert">
<b>Hey, you!</b>
<span>You have not yet specified the resolution and bitrate in which you stream. Please do so below. Thank you!</span>
</div>
}
<form method="POST">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" style="width:23ch">Source Resolution</span>
</div>
<input type="hidden" value="srcres_set" name="action">
<input type="text" class="form-control" name="value" placeholder="example: 1080p60 @@ 10Mbit (Shown in profile page tooltip)" value="@(user.SrcRes == "unspecified" ? "" : user.SrcRes)">
<div class="input-group-append">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
@if (user.AllowRestream) {
<form method="POST">
<div class="input-group mb-3">

View File

@ -75,15 +75,6 @@ namespace RTMPDash.Pages {
Response.Redirect("/Dashboard");
}
if (Request.Form["action"] == "srcres_set") {
var target = string.IsNullOrWhiteSpace(Request.Form["value"])
? "unspecified"
: Request.Form["value"].ToString();
user!.SrcRes = target;
db.Update(user);
Response.Redirect("/Dashboard");
}
if (Request.Form["action"] == "streamkey_reset") {
user!.StreamKey = Guid.NewGuid().ToString().Substring(9, 14);
db.Update(user);

View File

@ -31,8 +31,7 @@ namespace RTMPDash.Pages {
Password = Request.Form["pass"].ToString().Sha256(),
StreamKey = Guid.NewGuid().ToString().Substring(9, 14),
PronounSubject = "they",
PronounPossessive = "their",
SrcRes = "unspecified"
PronounPossessive = "their"
};
db.Insert(user);

View File

@ -10,6 +10,10 @@
}
var user = db.Users.First(p => p.Username == Model.User);
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);
}
var pronounAdditional = user.PronounSubject == "they" ? "are" : "is"; // TODO make this configurable too
}
@ -23,14 +27,14 @@
<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="@user.SrcRes">Source</a>
<a href="@Program.PlayerDomain/@user.Username" target="_blank" role="button" class="btn btn-success" data-toggle="tooltip" data-placement="bottom" title="@(stream.Meta.Video.Width)x@(stream.Meta.Video.Height) @@ @(Math.Round(float.Parse(stream.BwIn) / 1000000, 2)) Mbps">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="@user.SrcRes">Twitch Restream</a>
<a href="@user.RestreamUrls!.Split(",")[0]" target="_blank" role="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="@(stream.Meta.Video.Width)x@(stream.Meta.Video.Height) @@ @(Math.Round(float.Parse(stream.BwIn) / 1000000, 2)) Mbps">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)) {
<a href="@user.RestreamUrls" target="_blank" role="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="@user.SrcRes">Twitch Restream</a>
<a href="@user.RestreamUrls" target="_blank" role="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" title="@(stream.Meta.Video.Width)x@(stream.Meta.Video.Height) @@ @(Math.Round(float.Parse(stream.BwIn) / 1000000, 2)) Mbps">Source - @(stream.Meta.Video.Height)p">Twitch Restream</a>
}
}

View File

@ -8,7 +8,7 @@
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": false,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"applicationUrl": "http://localhost:60001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@ -38,7 +38,6 @@ namespace RTMPDash {
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSession();

View File

@ -3,22 +3,17 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Xml.Serialization;
using RTMPDash.DataModels;
namespace RTMPDash {
public class StreamUtils {
private const string Hlsroot = "/mnt/ssd_data/hls/src";
public static bool IsLive(string user) => GetStatsObject()
.Server.Applications.First(p => p.Name == "ingress")
.MethodLive.Streams.Any(p => p.Name == user);
public static bool IsLive(string user) => File.Exists(Path.Combine(Hlsroot, $"{user}.m3u8"));
public static List<string> ListLiveUsers() {
var db = new AppDb.DbConn();
return (from file in Directory.EnumerateFiles(Path.Combine(Hlsroot))
where file.EndsWith(".m3u8")
&& db.Users.Any(p => p.Username == Path.GetFileNameWithoutExtension(file))
select Path.GetFileNameWithoutExtension(file)).OrderBy(p => p)
.ToList();
}
public static List<string> ListLiveUsers() => GetStatsObject()
.Server.Applications.First(p => p.Name == "ingress")
.MethodLive.Streams.Select(p => p.Name)
.ToList();
public static StatsObject GetStatsObject() {
var serializer = new XmlSerializer(typeof(StatsObject));