Record coordinated reception results and prepare scoped web H264 option
This commit is contained in:
@@ -5,11 +5,26 @@ using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data;
|
||||
using Jellyfin.Database.Implementations.Enums;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.LiveTv;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Jellyfin.Plugin.Enigma2;
|
||||
public sealed class WebPlaybackPolicy
|
||||
{
|
||||
public bool IsEnigmaChannel { get; set; }
|
||||
public bool PreferH264 { get; set; }
|
||||
public static WebPlaybackPolicy For(BaseItem item, bool enabled)
|
||||
{
|
||||
var owned = item is LiveTvChannel && string.Equals(item.ServiceName, "Enigma2", StringComparison.OrdinalIgnoreCase);
|
||||
return new() { IsEnigmaChannel = owned, PreferH264 = owned && enabled };
|
||||
}
|
||||
}
|
||||
public sealed class ChannelPreferences
|
||||
{
|
||||
public string[] FavoriteIds { get; set; } = Array.Empty<string>();
|
||||
@@ -52,7 +67,9 @@ public sealed class PreferencesController : ControllerBase
|
||||
private readonly InternetEpg epg;
|
||||
private readonly LiveStreamRelay relay;
|
||||
private readonly LiveStreamProbe probe;
|
||||
public PreferencesController(PreferencesStore store,InternetEpg epg,LiveStreamRelay relay,LiveStreamProbe probe) { this.store=store; this.epg=epg; this.relay=relay; this.probe=probe; }
|
||||
private readonly ILibraryManager library;
|
||||
private readonly IUserManager users;
|
||||
public PreferencesController(PreferencesStore store,InternetEpg epg,LiveStreamRelay relay,LiveStreamProbe probe,ILibraryManager library,IUserManager users) { this.store=store; this.epg=epg; this.relay=relay; this.probe=probe; this.library=library; this.users=users; }
|
||||
private Guid UserId => Guid.TryParse(User.FindFirst("Jellyfin-UserId")?.Value,out var id) ? id : Guid.Empty;
|
||||
[HttpGet("Channels")]
|
||||
[AllowAnonymous]
|
||||
@@ -66,6 +83,19 @@ public sealed class PreferencesController : ControllerBase
|
||||
[HttpPut("Preferences")]
|
||||
public async Task<IActionResult> Put(ChannelPreferences value,CancellationToken token)
|
||||
{ if (UserId == Guid.Empty) return Unauthorized(); await store.Save(UserId,value,token); return NoContent(); }
|
||||
[HttpGet("WebPlaybackPolicy")]
|
||||
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
|
||||
public ActionResult<WebPlaybackPolicy> GetWebPlaybackPolicy([FromQuery] Guid channelId)
|
||||
{
|
||||
// Resolve the authenticated user explicitly: the native library lookup with a
|
||||
// null user would skip visibility checks. Never accept a userId from the query.
|
||||
if (UserId == Guid.Empty) return Unauthorized();
|
||||
var user = users.GetUserById(UserId);
|
||||
if (user == null) return Unauthorized();
|
||||
if (!user.HasPermission(PermissionKind.EnableLiveTvAccess)) return Forbid();
|
||||
var item = channelId == Guid.Empty ? null : library.GetItemById<BaseItem>(channelId, user);
|
||||
return WebPlaybackPolicy.For(item, Plugin.Instance?.Configuration?.PreferH264ForWebLiveTv ?? false);
|
||||
}
|
||||
[HttpGet("Status")]
|
||||
[Authorize(Policy="RequiresElevation")]
|
||||
public IActionResult Status() => Ok(new { epg.LastSuccess,epg.MatchedImages,epg.LastError, Source="https://epg.polishteam.one/guide.xml", Streams=relay.Status(), ProbeError=probe.LastError });
|
||||
|
||||
Reference in New Issue
Block a user