mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-01 11:23:36 +02:00
Styling, format, minor code changes (crobibero)
This commit is contained in:
parent
07e6804f7a
commit
98e41d5a14
|
@ -6,18 +6,14 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Jellyfin.Api.Attributes;
|
using Jellyfin.Api.Attributes;
|
||||||
using Jellyfin.Api.Extensions;
|
using Jellyfin.Api.Extensions;
|
||||||
using Jellyfin.Api.Helpers;
|
|
||||||
using MediaBrowser.Common.Extensions;
|
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Trickplay;
|
using MediaBrowser.Controller.Trickplay;
|
||||||
using MediaBrowser.Model;
|
using MediaBrowser.Model;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Jellyfin.Api.Controllers;
|
namespace Jellyfin.Api.Controllers;
|
||||||
|
|
||||||
|
@ -28,26 +24,18 @@ namespace Jellyfin.Api.Controllers;
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class TrickplayController : BaseJellyfinApiController
|
public class TrickplayController : BaseJellyfinApiController
|
||||||
{
|
{
|
||||||
private readonly ILogger<TrickplayController> _logger;
|
|
||||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
private readonly ITrickplayManager _trickplayManager;
|
private readonly ITrickplayManager _trickplayManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TrickplayController"/> class.
|
/// Initializes a new instance of the <see cref="TrickplayController"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">Instance of the <see cref="ILogger{TrickplayController}"/> interface.</param>
|
|
||||||
/// <param name="httpContextAccessor">Instance of the <see cref="IHttpContextAccessor"/> interface.</param>
|
|
||||||
/// <param name="libraryManager">Instance of <see cref="ILibraryManager"/>.</param>
|
/// <param name="libraryManager">Instance of <see cref="ILibraryManager"/>.</param>
|
||||||
/// <param name="trickplayManager">Instance of <see cref="ITrickplayManager"/>.</param>
|
/// <param name="trickplayManager">Instance of <see cref="ITrickplayManager"/>.</param>
|
||||||
public TrickplayController(
|
public TrickplayController(
|
||||||
ILogger<TrickplayController> logger,
|
|
||||||
IHttpContextAccessor httpContextAccessor,
|
|
||||||
ILibraryManager libraryManager,
|
ILibraryManager libraryManager,
|
||||||
ITrickplayManager trickplayManager)
|
ITrickplayManager trickplayManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
|
||||||
_httpContextAccessor = httpContextAccessor;
|
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
_trickplayManager = trickplayManager;
|
_trickplayManager = trickplayManager;
|
||||||
}
|
}
|
||||||
|
@ -66,9 +54,9 @@ public class TrickplayController : BaseJellyfinApiController
|
||||||
public ActionResult GetTrickplayHlsPlaylist(
|
public ActionResult GetTrickplayHlsPlaylist(
|
||||||
[FromRoute, Required] Guid itemId,
|
[FromRoute, Required] Guid itemId,
|
||||||
[FromRoute, Required] int width,
|
[FromRoute, Required] int width,
|
||||||
[FromQuery] string? mediaSourceId)
|
[FromQuery] Guid? mediaSourceId)
|
||||||
{
|
{
|
||||||
return GetTrickplayPlaylistInternal(width, mediaSourceId ?? itemId.ToString("N"));
|
return GetTrickplayPlaylistInternal(width, mediaSourceId ?? itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -89,9 +77,9 @@ public class TrickplayController : BaseJellyfinApiController
|
||||||
[FromRoute, Required] Guid itemId,
|
[FromRoute, Required] Guid itemId,
|
||||||
[FromRoute, Required] int width,
|
[FromRoute, Required] int width,
|
||||||
[FromRoute, Required] int index,
|
[FromRoute, Required] int index,
|
||||||
[FromQuery] string? mediaSourceId)
|
[FromQuery] Guid? mediaSourceId)
|
||||||
{
|
{
|
||||||
var item = _libraryManager.GetItemById(mediaSourceId ?? itemId.ToString("N"));
|
var item = _libraryManager.GetItemById(mediaSourceId ?? itemId);
|
||||||
if (item is null)
|
if (item is null)
|
||||||
{
|
{
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
@ -106,28 +94,22 @@ public class TrickplayController : BaseJellyfinApiController
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActionResult GetTrickplayPlaylistInternal(int width, string mediaSourceId)
|
private ActionResult GetTrickplayPlaylistInternal(int width, Guid mediaSourceId)
|
||||||
{
|
{
|
||||||
if (_httpContextAccessor.HttpContext is null)
|
var tilesResolutions = _trickplayManager.GetTilesResolutions(mediaSourceId);
|
||||||
{
|
if (tilesResolutions is not null && tilesResolutions.TryGetValue(width, out var tilesInfo))
|
||||||
throw new ResourceNotFoundException(nameof(_httpContextAccessor.HttpContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
var tilesResolutions = _trickplayManager.GetTilesResolutions(Guid.Parse(mediaSourceId));
|
|
||||||
if (tilesResolutions is not null && tilesResolutions.ContainsKey(width))
|
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder(128);
|
var builder = new StringBuilder(128);
|
||||||
var tilesInfo = tilesResolutions[width];
|
|
||||||
|
|
||||||
if (tilesInfo.TileCount > 0)
|
if (tilesInfo.TileCount > 0)
|
||||||
{
|
{
|
||||||
const string urlFormat = "Trickplay/{0}/{1}.jpg?MediaSourceId={2}&api_key={3}";
|
const string urlFormat = "Trickplay/{0}/{1}.jpg?MediaSourceId={2}&api_key={3}";
|
||||||
const string decimalFormat = "{0:0.###}";
|
const string decimalFormat = "{0:0.###}";
|
||||||
|
|
||||||
var resolution = tilesInfo.Width.ToString(CultureInfo.InvariantCulture) + "x" + tilesInfo.Height.ToString(CultureInfo.InvariantCulture);
|
var resolution = $"{tilesInfo.Width}x{tilesInfo.Height}";
|
||||||
var layout = tilesInfo.TileWidth.ToString(CultureInfo.InvariantCulture) + "x" + tilesInfo.TileHeight.ToString(CultureInfo.InvariantCulture);
|
var layout = $"{tilesInfo.TileWidth}x{tilesInfo.TileHeight}";
|
||||||
var tilesPerGrid = tilesInfo.TileWidth * tilesInfo.TileHeight;
|
var tilesPerGrid = tilesInfo.TileWidth * tilesInfo.TileHeight;
|
||||||
var tileDuration = (decimal)tilesInfo.Interval / 1000;
|
var tileDuration = tilesInfo.Interval / 1000m;
|
||||||
var infDuration = tileDuration * tilesPerGrid;
|
var infDuration = tileDuration * tilesPerGrid;
|
||||||
var tileGridCount = (int)Math.Ceiling((decimal)tilesInfo.TileCount / tilesPerGrid);
|
var tileGridCount = (int)Math.Ceiling((decimal)tilesInfo.TileCount / tilesPerGrid);
|
||||||
|
|
||||||
|
@ -153,15 +135,22 @@ public class TrickplayController : BaseJellyfinApiController
|
||||||
urlFormat,
|
urlFormat,
|
||||||
width.ToString(CultureInfo.InvariantCulture),
|
width.ToString(CultureInfo.InvariantCulture),
|
||||||
i.ToString(CultureInfo.InvariantCulture),
|
i.ToString(CultureInfo.InvariantCulture),
|
||||||
mediaSourceId,
|
mediaSourceId.ToString("N"),
|
||||||
_httpContextAccessor.HttpContext.User.GetToken());
|
User.GetToken());
|
||||||
|
|
||||||
// EXTINF
|
// EXTINF
|
||||||
builder.Append("#EXTINF:").Append(string.Format(CultureInfo.InvariantCulture, decimalFormat, infDuration))
|
builder
|
||||||
|
.Append("#EXTINF:")
|
||||||
|
.Append(string.Format(CultureInfo.InvariantCulture, decimalFormat, infDuration))
|
||||||
.AppendLine(",");
|
.AppendLine(",");
|
||||||
|
|
||||||
// EXT-X-TILES
|
// EXT-X-TILES
|
||||||
builder.Append("#EXT-X-TILES:RESOLUTION=").Append(resolution).Append(",LAYOUT=").Append(layout).Append(",DURATION=")
|
builder
|
||||||
|
.Append("#EXT-X-TILES:RESOLUTION=")
|
||||||
|
.Append(resolution)
|
||||||
|
.Append(",LAYOUT=")
|
||||||
|
.Append(layout)
|
||||||
|
.Append(",DURATION=")
|
||||||
.AppendLine(string.Format(CultureInfo.InvariantCulture, decimalFormat, tileDuration));
|
.AppendLine(string.Format(CultureInfo.InvariantCulture, decimalFormat, tileDuration));
|
||||||
|
|
||||||
// URL
|
// URL
|
||||||
|
|
|
@ -94,7 +94,7 @@ public class TrickplayImagesTask : IScheduledTask
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError("Error creating trickplay files for {ItemName}: {Msg}", item.Name, ex);
|
_logger.LogError(ex, "Error creating trickplay files for {ItemName}", item.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
numComplete++;
|
numComplete++;
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class TrickplayManager : ITrickplayManager
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
|
|
||||||
private static readonly SemaphoreSlim _resourcePool = new(1, 1);
|
private static readonly SemaphoreSlim _resourcePool = new(1, 1);
|
||||||
|
private static readonly string[] _trickplayImgExtensions = { ".jpg" };
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TrickplayManager"/> class.
|
/// Initializes a new instance of the <see cref="TrickplayManager"/> class.
|
||||||
|
@ -95,10 +96,10 @@ public class TrickplayManager : ITrickplayManager
|
||||||
var imgTempDir = string.Empty;
|
var imgTempDir = string.Empty;
|
||||||
var outputDir = GetTrickplayDirectory(video, width);
|
var outputDir = GetTrickplayDirectory(video, width);
|
||||||
|
|
||||||
|
await _resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (!replace && Directory.Exists(outputDir) && GetTilesResolutions(video.Id).ContainsKey(width))
|
if (!replace && Directory.Exists(outputDir) && GetTilesResolutions(video.Id).ContainsKey(width))
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Found existing trickplay files for {ItemId}. Exiting.", video.Id);
|
_logger.LogDebug("Found existing trickplay files for {ItemId}. Exiting.", video.Id);
|
||||||
|
@ -139,8 +140,7 @@ public class TrickplayManager : ITrickplayManager
|
||||||
throw new InvalidOperationException("Null or invalid directory from media encoder.");
|
throw new InvalidOperationException("Null or invalid directory from media encoder.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var images = _fileSystem.GetFiles(imgTempDir, new string[] { ".jpg" }, false, false)
|
var images = _fileSystem.GetFiles(imgTempDir, _trickplayImgExtensions, false, false)
|
||||||
.Where(img => string.Equals(img.Extension, ".jpg", StringComparison.Ordinal))
|
|
||||||
.OrderBy(i => i.FullName)
|
.OrderBy(i => i.FullName)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ public class TrickplayProvider : ICustomMetadataProvider<Episode>,
|
||||||
IHasOrder,
|
IHasOrder,
|
||||||
IForcedProvider
|
IForcedProvider
|
||||||
{
|
{
|
||||||
private readonly ILogger<TrickplayProvider> _logger;
|
|
||||||
private readonly IServerConfigurationManager _config;
|
private readonly IServerConfigurationManager _config;
|
||||||
private readonly ITrickplayManager _trickplayManager;
|
private readonly ITrickplayManager _trickplayManager;
|
||||||
private readonly ILibraryManager _libraryManager;
|
private readonly ILibraryManager _libraryManager;
|
||||||
|
@ -33,17 +32,14 @@ public class TrickplayProvider : ICustomMetadataProvider<Episode>,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="TrickplayProvider"/> class.
|
/// Initializes a new instance of the <see cref="TrickplayProvider"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The logger.</param>
|
|
||||||
/// <param name="config">The configuration manager.</param>
|
/// <param name="config">The configuration manager.</param>
|
||||||
/// <param name="trickplayManager">The trickplay manager.</param>
|
/// <param name="trickplayManager">The trickplay manager.</param>
|
||||||
/// <param name="libraryManager">The library manager.</param>
|
/// <param name="libraryManager">The library manager.</param>
|
||||||
public TrickplayProvider(
|
public TrickplayProvider(
|
||||||
ILogger<TrickplayProvider> logger,
|
|
||||||
IServerConfigurationManager config,
|
IServerConfigurationManager config,
|
||||||
ITrickplayManager trickplayManager,
|
ITrickplayManager trickplayManager,
|
||||||
ILibraryManager libraryManager)
|
ILibraryManager libraryManager)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
|
||||||
_config = config;
|
_config = config;
|
||||||
_trickplayManager = trickplayManager;
|
_trickplayManager = trickplayManager;
|
||||||
_libraryManager = libraryManager;
|
_libraryManager = libraryManager;
|
||||||
|
|
Loading…
Reference in a new issue