Dont load recordings for streams by default
This commit is contained in:
@ -201,9 +201,9 @@ public class PlaylistController : Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var streamManager = await _streamManagerFactory.ForStream(id);
|
var streamManager = await _streamManagerFactory.ForStream(id);
|
||||||
var userStream = streamManager.GetStream();
|
var recordings = await streamManager.GetRecordings();
|
||||||
|
|
||||||
if (userStream.Recordings.Count == 0)
|
if (recordings.Count == 0)
|
||||||
{
|
{
|
||||||
Response.StatusCode = 404;
|
Response.StatusCode = 404;
|
||||||
return;
|
return;
|
||||||
@ -219,7 +219,7 @@ public class PlaylistController : Controller
|
|||||||
await sw.WriteLineAsync("#EXT-X-MEDIA-SEQUENCE:0");
|
await sw.WriteLineAsync("#EXT-X-MEDIA-SEQUENCE:0");
|
||||||
//await sw.WriteLineAsync($"#EXT-X-MAP:URI=\"{id}_init.mp4\"");
|
//await sw.WriteLineAsync($"#EXT-X-MAP:URI=\"{id}_init.mp4\"");
|
||||||
|
|
||||||
foreach (var seg in userStream.Recordings.OrderBy(a => a.Timestamp))
|
foreach (var seg in recordings.OrderBy(a => a.Timestamp))
|
||||||
{
|
{
|
||||||
await sw.WriteLineAsync($"#EXTINF:{seg.Duration},");
|
await sw.WriteLineAsync($"#EXTINF:{seg.Duration},");
|
||||||
await sw.WriteLineAsync($"#EXT-X-PROGRAM-DATE-TIME:{seg.Timestamp:yyyy-MM-ddTHH:mm:ss.fffzzz}");
|
await sw.WriteLineAsync($"#EXT-X-PROGRAM-DATE-TIME:{seg.Timestamp:yyyy-MM-ddTHH:mm:ss.fffzzz}");
|
||||||
@ -240,9 +240,9 @@ public class PlaylistController : Controller
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var streamManager = await _streamManagerFactory.ForStream(id);
|
var streamManager = await _streamManagerFactory.ForStream(id);
|
||||||
var userStream = streamManager.GetStream();
|
var recordings = await streamManager.GetRecordings();
|
||||||
|
|
||||||
var firstFrag = await _client.GetStreamAsync(userStream.Recordings.First().Url);
|
var firstFrag = await _client.GetStreamAsync(recordings.First().Url);
|
||||||
var tmpFrag = Path.GetTempFileName();
|
var tmpFrag = Path.GetTempFileName();
|
||||||
await firstFrag.CopyToAsync(new FileStream(tmpFrag, FileMode.Open, FileAccess.ReadWrite));
|
await firstFrag.CopyToAsync(new FileStream(tmpFrag, FileMode.Open, FileAccess.ReadWrite));
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ public class UserStreamRecordingConfiguration : IEntityTypeConfiguration<UserStr
|
|||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
builder.HasOne(a => a.Stream)
|
builder.HasOne(a => a.Stream)
|
||||||
.WithMany(a => a.Recordings)
|
.WithMany()
|
||||||
.HasForeignKey(a => a.UserStreamId);
|
.HasForeignKey(a => a.UserStreamId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ public class UserStream
|
|||||||
public string ForwardClientId { get; set; } = null!;
|
public string ForwardClientId { get; set; } = null!;
|
||||||
|
|
||||||
public List<UserStreamGuest> Guests { get; init; } = new();
|
public List<UserStreamGuest> Guests { get; init; } = new();
|
||||||
public List<UserStreamRecording> Recordings { get; init; } = new();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum UserStreamState
|
public enum UserStreamState
|
||||||
|
@ -78,5 +78,11 @@ public interface IStreamManager
|
|||||||
/// Republish stream event
|
/// Republish stream event
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task UpdateEvent();
|
Task UpdateEvent();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return a list of recordings segments
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<List<UserStreamRecording>> GetRecordings();
|
||||||
}
|
}
|
@ -155,6 +155,13 @@ public class NostrStreamManager : IStreamManager
|
|||||||
await UpdateStreamState(_context.UserStream.State);
|
await UpdateStreamState(_context.UserStream.State);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<List<UserStreamRecording>> GetRecordings()
|
||||||
|
{
|
||||||
|
return await _context.Db.Recordings.AsNoTracking()
|
||||||
|
.Where(a => a.UserStreamId == _context.UserStream.Id)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateViewers()
|
public async Task UpdateViewers()
|
||||||
{
|
{
|
||||||
if (_context.UserStream.State is not UserStreamState.Live) return;
|
if (_context.UserStream.State is not UserStreamState.Live) return;
|
||||||
|
@ -89,7 +89,6 @@ public class StreamManagerFactory
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Include(a => a.User)
|
.Include(a => a.User)
|
||||||
.Include(a => a.Endpoint)
|
.Include(a => a.Endpoint)
|
||||||
.Include(a => a.Recordings)
|
|
||||||
.FirstOrDefaultAsync(a => a.Id == id);
|
.FirstOrDefaultAsync(a => a.Id == id);
|
||||||
|
|
||||||
if (stream == default) throw new Exception("No live stream");
|
if (stream == default) throw new Exception("No live stream");
|
||||||
@ -110,7 +109,6 @@ public class StreamManagerFactory
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Include(a => a.User)
|
.Include(a => a.User)
|
||||||
.Include(a => a.Endpoint)
|
.Include(a => a.Endpoint)
|
||||||
.Include(a => a.Recordings)
|
|
||||||
.FirstOrDefaultAsync(a => a.PubKey.Equals(pubkey) && a.State == UserStreamState.Live);
|
.FirstOrDefaultAsync(a => a.PubKey.Equals(pubkey) && a.State == UserStreamState.Live);
|
||||||
|
|
||||||
if (stream == default) throw new Exception("No live stream");
|
if (stream == default) throw new Exception("No live stream");
|
||||||
@ -131,7 +129,6 @@ public class StreamManagerFactory
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Include(a => a.User)
|
.Include(a => a.User)
|
||||||
.Include(a => a.Endpoint)
|
.Include(a => a.Endpoint)
|
||||||
.Include(a => a.Recordings)
|
|
||||||
.OrderByDescending(a => a.Starts)
|
.OrderByDescending(a => a.Starts)
|
||||||
.FirstOrDefaultAsync(a =>
|
.FirstOrDefaultAsync(a =>
|
||||||
a.User.StreamKey.Equals(info.StreamKey) &&
|
a.User.StreamKey.Equals(info.StreamKey) &&
|
||||||
|
Reference in New Issue
Block a user