diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 7647827fb6..0201ed7a34 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -46,7 +46,6 @@ using Emby.Server.Implementations.SyncPlay;
using Emby.Server.Implementations.TV;
using Emby.Server.Implementations.Updates;
using Jellyfin.Api.Helpers;
-using MediaBrowser.Api;
using MediaBrowser.Common;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Events;
@@ -1032,9 +1031,6 @@ namespace Emby.Server.Implementations
}
}
- // Include composable parts in the Api assembly
- yield return typeof(ApiEntryPoint).Assembly;
-
// Include composable parts in the Model assembly
yield return typeof(SystemInfo).Assembly;
diff --git a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
index 495ff9d128..aa366f5672 100644
--- a/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
+++ b/Jellyfin.Api/Auth/BaseAuthorizationHandler.cs
@@ -1,5 +1,4 @@
-using System.Net;
-using System.Security.Claims;
+using System.Security.Claims;
using Jellyfin.Api.Helpers;
using Jellyfin.Data.Enums;
using MediaBrowser.Common.Net;
diff --git a/Jellyfin.Api/Controllers/AudioController.cs b/Jellyfin.Api/Controllers/AudioController.cs
index ebae1caa0e..4de87616c5 100644
--- a/Jellyfin.Api/Controllers/AudioController.cs
+++ b/Jellyfin.Api/Controllers/AudioController.cs
@@ -144,10 +144,10 @@ namespace Jellyfin.Api.Controllers
/// Optional. The streaming options.
/// Audio stream returned.
/// A containing the audio file.
- [HttpGet("{itemId}/{stream=stream}.{container?}")]
- [HttpGet("{itemId}/stream")]
- [HttpHead("{itemId}/{stream=stream}.{container?}")]
- [HttpHead("{itemId}/stream")]
+ [HttpGet("{itemId}/{stream=stream}.{container?}", Name = "GetAudioStreamByContainer")]
+ [HttpGet("{itemId}/stream", Name = "GetAudioStream")]
+ [HttpHead("{itemId}/{stream=stream}.{container?}", Name = "HeadAudioStreamByContainer")]
+ [HttpHead("{itemId}/stream", Name = "HeadAudioStream")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetAudioStream(
[FromRoute] Guid itemId,
diff --git a/Jellyfin.Api/Controllers/BrandingController.cs b/Jellyfin.Api/Controllers/BrandingController.cs
index 67790c0e4a..1d4836f278 100644
--- a/Jellyfin.Api/Controllers/BrandingController.cs
+++ b/Jellyfin.Api/Controllers/BrandingController.cs
@@ -44,7 +44,7 @@ namespace Jellyfin.Api.Controllers
/// or a if the css is not configured.
///
[HttpGet("Css")]
- [HttpGet("Css.css")]
+ [HttpGet("Css.css", Name = "GetBrandingCss_2")]
[Produces("text/css")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
diff --git a/Jellyfin.Api/Controllers/DlnaServerController.cs b/Jellyfin.Api/Controllers/DlnaServerController.cs
index 2f5561adb9..ef507f2ed6 100644
--- a/Jellyfin.Api/Controllers/DlnaServerController.cs
+++ b/Jellyfin.Api/Controllers/DlnaServerController.cs
@@ -42,8 +42,8 @@ namespace Jellyfin.Api.Controllers
/// Server UUID.
/// Description xml returned.
/// An containing the description xml.
- [HttpGet("{serverId}/description.xml")]
[HttpGet("{serverId}/description")]
+ [HttpGet("{serverId}/description.xml", Name = "GetDescriptionXml_2")]
[Produces(XMLContentType)]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult GetDescriptionXml([FromRoute] string serverId)
@@ -60,8 +60,8 @@ namespace Jellyfin.Api.Controllers
/// Server UUID.
/// Dlna content directory returned.
/// An containing the dlna content directory xml.
- [HttpGet("{serverId}/ContentDirectory/ContentDirectory.xml")]
[HttpGet("{serverId}/ContentDirectory/ContentDirectory")]
+ [HttpGet("{serverId}/ContentDirectory/ContentDirectory.xml", Name = "GetContentDirectory_2")]
[Produces(XMLContentType)]
[ProducesResponseType(StatusCodes.Status200OK)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
@@ -75,8 +75,8 @@ namespace Jellyfin.Api.Controllers
///
/// Server UUID.
/// Dlna media receiver registrar xml.
- [HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar.xml")]
[HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar")]
+ [HttpGet("{serverId}/MediaReceiverRegistrar/MediaReceiverRegistrar.xml", Name = "GetMediaReceiverRegistrar_2")]
[Produces(XMLContentType)]
[ProducesResponseType(StatusCodes.Status200OK)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
@@ -90,8 +90,8 @@ namespace Jellyfin.Api.Controllers
///
/// Server UUID.
/// Dlna media receiver registrar xml.
- [HttpGet("{serverId}/ConnectionManager/ConnectionManager.xml")]
[HttpGet("{serverId}/ConnectionManager/ConnectionManager")]
+ [HttpGet("{serverId}/ConnectionManager/ConnectionManager.xml", Name = "GetConnectionManager_2")]
[Produces(XMLContentType)]
[ProducesResponseType(StatusCodes.Status200OK)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
@@ -181,7 +181,7 @@ namespace Jellyfin.Api.Controllers
/// Server UUID.
/// The icon filename.
/// Icon stream.
- [HttpGet("{serverId}/icons/{filename}")]
+ [HttpGet("{serverId}/icons/{fileName}")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "serverId", Justification = "Required for DLNA")]
public ActionResult GetIconId([FromRoute] string serverId, [FromRoute] string fileName)
{
@@ -193,7 +193,7 @@ namespace Jellyfin.Api.Controllers
///
/// The icon filename.
/// Icon stream.
- [HttpGet("icons/{filename}")]
+ [HttpGet("icons/{fileName}")]
public ActionResult GetIcon([FromRoute] string fileName)
{
return GetIconInternal(fileName);
diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.cs
index b7e1837c97..c4f79ce950 100644
--- a/Jellyfin.Api/Controllers/DynamicHlsController.cs
+++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs
@@ -165,7 +165,7 @@ namespace Jellyfin.Api.Controllers
/// Video stream returned.
/// A containing the playlist file.
[HttpGet("/Videos/{itemId}/master.m3u8")]
- [HttpHead("/Videos/{itemId}/master.m3u8")]
+ [HttpHead("/Videos/{itemId}/master.m3u8", Name = "HeadMasterHlsVideoPlaylist")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetMasterHlsVideoPlaylist(
[FromRoute] Guid itemId,
@@ -335,7 +335,7 @@ namespace Jellyfin.Api.Controllers
/// Audio stream returned.
/// A containing the playlist file.
[HttpGet("/Audio/{itemId}/master.m3u8")]
- [HttpHead("/Audio/{itemId}/master.m3u8")]
+ [HttpHead("/Audio/{itemId}/master.m3u8", Name = "HeadMasterHlsAudioPlaylist")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetMasterHlsAudioPlaylist(
[FromRoute] Guid itemId,
diff --git a/Jellyfin.Api/Controllers/HlsSegmentController.cs b/Jellyfin.Api/Controllers/HlsSegmentController.cs
index efdb6a3691..7bf9326a71 100644
--- a/Jellyfin.Api/Controllers/HlsSegmentController.cs
+++ b/Jellyfin.Api/Controllers/HlsSegmentController.cs
@@ -50,8 +50,8 @@ namespace Jellyfin.Api.Controllers
/// A containing the audio stream.
// Can't require authentication just yet due to seeing some requests come from Chrome without full query string
// [Authenticated]
- [HttpGet("/Audio/{itemId}/hls/{segmentId}/stream.mp3")]
- [HttpGet("/Audio/{itemId}/hls/{segmentId}/stream.aac")]
+ [HttpGet("/Audio/{itemId}/hls/{segmentId}/stream.mp3", Name = "GetHlsAudioSegmentLegacyMp3")]
+ [HttpGet("/Audio/{itemId}/hls/{segmentId}/stream.aac", Name = "GetHlsAudioSegmentLegacyAac")]
[ProducesResponseType(StatusCodes.Status200OK)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "itemId", Justification = "Required for ServiceStack")]
public ActionResult GetHlsAudioSegmentLegacy([FromRoute] string itemId, [FromRoute] string segmentId)
diff --git a/Jellyfin.Api/Controllers/ImageController.cs b/Jellyfin.Api/Controllers/ImageController.cs
index 18220c5f34..3a445b1b3c 100644
--- a/Jellyfin.Api/Controllers/ImageController.cs
+++ b/Jellyfin.Api/Controllers/ImageController.cs
@@ -82,7 +82,7 @@ namespace Jellyfin.Api.Controllers
/// User does not have permission to delete the image.
/// A .
[HttpPost("/Users/{userId}/Images/{imageType}")]
- [HttpPost("/Users/{userId}/Images/{imageType}/{index?}")]
+ [HttpPost("/Users/{userId}/Images/{imageType}/{index?}", Name = "PostUserImage_2")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status403Forbidden)]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "imageType", Justification = "Imported from ServiceStack")]
@@ -128,7 +128,7 @@ namespace Jellyfin.Api.Controllers
/// User does not have permission to delete the image.
/// A .
[HttpDelete("/Users/{userId}/Images/{itemType}")]
- [HttpDelete("/Users/{userId}/Images/{itemType}/{index?}")]
+ [HttpDelete("/Users/{userId}/Images/{itemType}/{index?}", Name = "DeleteUserImage_2")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "imageType", Justification = "Imported from ServiceStack")]
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "index", Justification = "Imported from ServiceStack")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
@@ -167,7 +167,7 @@ namespace Jellyfin.Api.Controllers
/// Item not found.
/// A on success, or a if item not found.
[HttpDelete("/Items/{itemId}/Images/{imageType}")]
- [HttpDelete("/Items/{itemId}/Images/{imageType}/{imageIndex?}")]
+ [HttpDelete("/Items/{itemId}/Images/{imageType}/{imageIndex?}", Name = "DeleteItemImage_2")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
@@ -196,7 +196,7 @@ namespace Jellyfin.Api.Controllers
/// Item not found.
/// A on success, or a if item not found.
[HttpPost("/Items/{itemId}/Images/{imageType}")]
- [HttpPost("/Items/{itemId}/Images/{imageType}/{imageIndex?}")]
+ [HttpPost("/Items/{itemId}/Images/{imageType}/{imageIndex?}", Name = "SetItemImage_2")]
[Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
@@ -342,9 +342,9 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Items/{itemId}/Images/{imageType}")]
- [HttpHead("/Items/{itemId}/Images/{imageType}")]
- [HttpGet("/Items/{itemId}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/Items/{itemId}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/Items/{itemId}/Images/{imageType}", Name = "HeadItemImage")]
+ [HttpGet("/Items/{itemId}/Images/{imageType}/{imageIndex?}", Name = "GetItemImage_2")]
+ [HttpHead("/Items/{itemId}/Images/{imageType}/{imageIndex?}", Name = "HeadItemImage_2")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetItemImage(
@@ -422,7 +422,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Items/{itemId}/Images/{imageType}/{imageIndex}/{tag}/{format}/{maxWidth}/{maxHeight}/{percentPlayed}/{unplayedCount}")]
- [HttpHead("/Items/{itemId}/Images/{imageType}/{imageIndex}/{tag}/{format}/{maxWidth}/{maxHeight}/{percentPlayed}/{unplayedCount}")]
+ [HttpHead("/Items/{itemId}/Images/{imageType}/{imageIndex}/{tag}/{format}/{maxWidth}/{maxHeight}/{percentPlayed}/{unplayedCount}", Name = "HeadItemImage2")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetItemImage2(
@@ -500,7 +500,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Artists/{name}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/Artists/{name}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/Artists/{name}/Images/{imageType}/{imageIndex?}", Name = "HeadArtistImage")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetArtistImage(
@@ -578,7 +578,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Genres/{name}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/Genres/{name}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/Genres/{name}/Images/{imageType}/{imageIndex?}", Name = "HeadGenreImage")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetGenreImage(
@@ -656,7 +656,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/MusicGenres/{name}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/MusicGenres/{name}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/MusicGenres/{name}/Images/{imageType}/{imageIndex?}", Name = "HeadMusicGenreImage")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetMusicGenreImage(
@@ -734,7 +734,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Persons/{name}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/Persons/{name}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/Persons/{name}/Images/{imageType}/{imageIndex?}", Name = "HeadPersonImage")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetPersonImage(
@@ -812,7 +812,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Studios/{name}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/Studios/{name}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/Studios/{name}/Images/{imageType}/{imageIndex?}", Name = "HeadStudioImage")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetStudioImage(
@@ -890,7 +890,7 @@ namespace Jellyfin.Api.Controllers
/// or a if item not found.
///
[HttpGet("/Users/{userId}/Images/{imageType}/{imageIndex?}")]
- [HttpHead("/Users/{userId}/Images/{imageType}/{imageIndex?}")]
+ [HttpHead("/Users/{userId}/Images/{imageType}/{imageIndex?}", Name = "HeadUserImage")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task GetUserImage(
diff --git a/Jellyfin.Api/Controllers/ItemsController.cs b/Jellyfin.Api/Controllers/ItemsController.cs
index 41fe47db10..354741ced1 100644
--- a/Jellyfin.Api/Controllers/ItemsController.cs
+++ b/Jellyfin.Api/Controllers/ItemsController.cs
@@ -30,7 +30,7 @@ namespace Jellyfin.Api.Controllers
private readonly ILibraryManager _libraryManager;
private readonly ILocalizationManager _localization;
private readonly IDtoService _dtoService;
- private readonly ILogger _logger;
+ private readonly ILogger _logger;
///
/// Initializes a new instance of the class.
@@ -140,7 +140,7 @@ namespace Jellyfin.Api.Controllers
/// Optional, include image information in output.
/// A with the items.
[HttpGet("/Items")]
- [HttpGet("/Users/{uId}/Items")]
+ [HttpGet("/Users/{uId}/Items", Name = "GetItems_2")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult> GetItems(
[FromRoute] Guid? uId,
diff --git a/Jellyfin.Api/Controllers/LibraryController.cs b/Jellyfin.Api/Controllers/LibraryController.cs
index 5ad466c557..0ec7e2b8c0 100644
--- a/Jellyfin.Api/Controllers/LibraryController.cs
+++ b/Jellyfin.Api/Controllers/LibraryController.cs
@@ -521,7 +521,7 @@ namespace Jellyfin.Api.Controllers
/// The tvdbId.
/// Report success.
/// A .
- [HttpPost("/Library/Series/Added")]
+ [HttpPost("/Library/Series/Added", Name = "PostAddedSeries")]
[HttpPost("/Library/Series/Updated")]
[Authorize(Policy = Policies.DefaultAuthorization)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
@@ -551,7 +551,7 @@ namespace Jellyfin.Api.Controllers
/// The imdbId.
/// Report success.
/// A .
- [HttpPost("/Library/Movies/Added")]
+ [HttpPost("/Library/Movies/Added", Name = "PostAddedMovies")]
[HttpPost("/Library/Movies/Updated")]
[Authorize(Policy = Policies.DefaultAuthorization)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
@@ -679,12 +679,12 @@ namespace Jellyfin.Api.Controllers
/// Optional. Specify additional fields of information to return in the output. This allows multiple, comma delimited. Options: Budget, Chapters, DateCreated, Genres, HomePageUrl, IndexOptions, MediaStreams, Overview, ParentId, Path, People, ProviderIds, PrimaryImageAspectRatio, Revenue, SortName, Studios, Taglines, TrailerUrls.
/// Similar items returned.
/// A containing the similar items.
- [HttpGet("/Artists/{itemId}/Similar")]
+ [HttpGet("/Artists/{itemId}/Similar", Name = "GetSimilarArtists2")]
[HttpGet("/Items/{itemId}/Similar")]
- [HttpGet("/Albums/{itemId}/Similar")]
- [HttpGet("/Shows/{itemId}/Similar")]
- [HttpGet("/Movies/{itemId}/Similar")]
- [HttpGet("/Trailers/{itemId}/Similar")]
+ [HttpGet("/Albums/{itemId}/Similar", Name = "GetSimilarAlbums2")]
+ [HttpGet("/Shows/{itemId}/Similar", Name = "GetSimilarShows2")]
+ [HttpGet("/Movies/{itemId}/Similar", Name = "GetSimilarMovies2")]
+ [HttpGet("/Trailers/{itemId}/Similar", Name = "GetSimilarTrailers2")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult> GetSimilarItems(
[FromRoute] Guid itemId,
diff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.cs
index b7f3c9b07c..827879e0a8 100644
--- a/Jellyfin.Api/Controllers/LibraryStructureController.cs
+++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs
@@ -249,7 +249,7 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult UpdateMediaPath(
[FromQuery] string? name,
- [FromQuery] MediaPathInfo? pathInfo)
+ [FromBody] MediaPathInfo? pathInfo)
{
if (string.IsNullOrWhiteSpace(name))
{
@@ -320,7 +320,7 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult UpdateLibraryOptions(
[FromQuery] string? id,
- [FromQuery] LibraryOptions? libraryOptions)
+ [FromBody] LibraryOptions? libraryOptions)
{
var collectionFolder = (CollectionFolder)_libraryManager.GetItemById(id);
diff --git a/Jellyfin.Api/Controllers/LiveTvController.cs b/Jellyfin.Api/Controllers/LiveTvController.cs
index 9144d6f285..89112eea7d 100644
--- a/Jellyfin.Api/Controllers/LiveTvController.cs
+++ b/Jellyfin.Api/Controllers/LiveTvController.cs
@@ -23,7 +23,6 @@ using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Querying;
@@ -128,7 +127,7 @@ namespace Jellyfin.Api.Controllers
[HttpGet("Channels")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Authorize(Policy = Policies.DefaultAuthorization)]
- public ActionResult> GetChannels(
+ public ActionResult> GetLiveTvChannels(
[FromQuery] ChannelType? type,
[FromQuery] Guid? userId,
[FromQuery] int? startIndex,
@@ -536,7 +535,7 @@ namespace Jellyfin.Api.Controllers
[HttpGet("Programs")]
[ProducesResponseType(StatusCodes.Status200OK)]
[Authorize(Policy = Policies.DefaultAuthorization)]
- public async Task>> GetPrograms(
+ public async Task>> GetLiveTvPrograms(
[FromQuery] string? channelIds,
[FromQuery] Guid? userId,
[FromQuery] DateTime? minStartDate,
@@ -934,7 +933,7 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[Obsolete("This endpoint is obsolete.")]
- public ActionResult GetRecordingGroup([FromQuery] Guid? groupId)
+ public ActionResult GetRecordingGroup([FromRoute] Guid? groupId)
{
return NotFound();
}
diff --git a/Jellyfin.Api/Controllers/MediaInfoController.cs b/Jellyfin.Api/Controllers/MediaInfoController.cs
index c2c02c02ca..5b0f46b02e 100644
--- a/Jellyfin.Api/Controllers/MediaInfoController.cs
+++ b/Jellyfin.Api/Controllers/MediaInfoController.cs
@@ -7,6 +7,7 @@ using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Jellyfin.Api.Constants;
+using Jellyfin.Api.Models.MediaInfoDtos;
using Jellyfin.Api.Models.VideoDtos;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums;
@@ -43,7 +44,7 @@ namespace Jellyfin.Api.Controllers
private readonly IMediaEncoder _mediaEncoder;
private readonly IUserManager _userManager;
private readonly IAuthorizationContext _authContext;
- private readonly ILogger _logger;
+ private readonly ILogger _logger;
private readonly IServerConfigurationManager _serverConfigurationManager;
///
@@ -91,7 +92,7 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task> GetPlaybackInfo([FromRoute] Guid itemId, [FromQuery] Guid? userId)
{
- return await GetPlaybackInfoInternal(itemId, userId, null, null).ConfigureAwait(false);
+ return await GetPlaybackInfoInternal(itemId, userId).ConfigureAwait(false);
}
///
@@ -231,8 +232,7 @@ namespace Jellyfin.Api.Controllers
/// The subtitle stream index.
/// The maximum number of audio channels.
/// The item id.
- /// The device profile.
- /// The direct play protocols. Default: .
+ /// The open live stream dto.
/// Whether to enable direct play. Default: true.
/// Whether to enable direct stream. Default: true.
/// Media source opened.
@@ -249,8 +249,7 @@ namespace Jellyfin.Api.Controllers
[FromQuery] int? subtitleStreamIndex,
[FromQuery] int? maxAudioChannels,
[FromQuery] Guid? itemId,
- [FromQuery] DeviceProfile? deviceProfile,
- [FromQuery] MediaProtocol[] directPlayProtocols,
+ [FromBody] OpenLiveStreamDto openLiveStreamDto,
[FromQuery] bool enableDirectPlay = true,
[FromQuery] bool enableDirectStream = true)
{
@@ -265,10 +264,10 @@ namespace Jellyfin.Api.Controllers
SubtitleStreamIndex = subtitleStreamIndex,
MaxAudioChannels = maxAudioChannels,
ItemId = itemId ?? Guid.Empty,
- DeviceProfile = deviceProfile,
+ DeviceProfile = openLiveStreamDto?.DeviceProfile,
EnableDirectPlay = enableDirectPlay,
EnableDirectStream = enableDirectStream,
- DirectPlayProtocols = directPlayProtocols ?? new[] { MediaProtocol.Http }
+ DirectPlayProtocols = openLiveStreamDto?.DirectPlayProtocols ?? new[] { MediaProtocol.Http }
};
return await OpenMediaSource(request).ConfigureAwait(false);
}
diff --git a/Jellyfin.Api/Controllers/SessionController.cs b/Jellyfin.Api/Controllers/SessionController.cs
index 0c98a8e711..1b300e0d8a 100644
--- a/Jellyfin.Api/Controllers/SessionController.cs
+++ b/Jellyfin.Api/Controllers/SessionController.cs
@@ -241,7 +241,7 @@ namespace Jellyfin.Api.Controllers
/// The command to send.
/// General command sent to session.
/// A .
- [HttpPost("/Sessions/{sessionId}/Command/{Command}")]
+ [HttpPost("/Sessions/{sessionId}/Command/{command}")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SendGeneralCommand(
[FromRoute] string? sessionId,
diff --git a/Jellyfin.Api/Controllers/StartupController.cs b/Jellyfin.Api/Controllers/StartupController.cs
index f9e4e61b5e..c8e3cc4f52 100644
--- a/Jellyfin.Api/Controllers/StartupController.cs
+++ b/Jellyfin.Api/Controllers/StartupController.cs
@@ -106,7 +106,7 @@ namespace Jellyfin.Api.Controllers
/// Initial user retrieved.
/// The first user.
[HttpGet("User")]
- [HttpGet("FirstUser")]
+ [HttpGet("FirstUser", Name = "GetFirstUser_2")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetFirstUser()
{
@@ -131,7 +131,7 @@ namespace Jellyfin.Api.Controllers
///
[HttpPost("User")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public async Task UpdateUser([FromForm] StartupUserDto startupUserDto)
+ public async Task UpdateStartupUser([FromForm] StartupUserDto startupUserDto)
{
var user = _userManager.Users.First();
diff --git a/Jellyfin.Api/Controllers/SubtitleController.cs b/Jellyfin.Api/Controllers/SubtitleController.cs
index b62ff80fcf..f8c19d15c4 100644
--- a/Jellyfin.Api/Controllers/SubtitleController.cs
+++ b/Jellyfin.Api/Controllers/SubtitleController.cs
@@ -182,7 +182,7 @@ namespace Jellyfin.Api.Controllers
/// File returned.
/// A with the subtitle file.
[HttpGet("/Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/Stream.{format}")]
- [HttpGet("/Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/{startPositionTicks?}/Stream.{format}")]
+ [HttpGet("/Videos/{itemId}/{mediaSourceId}/Subtitles/{index}/{startPositionTicks?}/Stream.{format}", Name = "GetSubtitle_2")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetSubtitle(
[FromRoute, Required] Guid itemId,
diff --git a/Jellyfin.Api/Controllers/SyncPlayController.cs b/Jellyfin.Api/Controllers/SyncPlayController.cs
index 55ed42227d..2b1b95b1b5 100644
--- a/Jellyfin.Api/Controllers/SyncPlayController.cs
+++ b/Jellyfin.Api/Controllers/SyncPlayController.cs
@@ -47,7 +47,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("New")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult CreateNewGroup()
+ public ActionResult SyncPlayCreateGroup()
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
_syncPlayManager.NewGroup(currentSession, CancellationToken.None);
@@ -62,7 +62,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Join")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult JoinGroup([FromQuery, Required] Guid groupId)
+ public ActionResult SyncPlayJoinGroup([FromQuery, Required] Guid groupId)
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
@@ -82,7 +82,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Leave")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult LeaveGroup()
+ public ActionResult SyncPlayLeaveGroup()
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
_syncPlayManager.LeaveGroup(currentSession, CancellationToken.None);
@@ -97,7 +97,7 @@ namespace Jellyfin.Api.Controllers
/// An containing the available SyncPlay groups.
[HttpGet("List")]
[ProducesResponseType(StatusCodes.Status200OK)]
- public ActionResult> GetSyncPlayGroups([FromQuery] Guid? filterItemId)
+ public ActionResult> SyncPlayGetGroups([FromQuery] Guid? filterItemId)
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
return Ok(_syncPlayManager.ListGroups(currentSession, filterItemId.HasValue ? filterItemId.Value : Guid.Empty));
@@ -110,7 +110,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Play")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult Play()
+ public ActionResult SyncPlayPlay()
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PlaybackRequest()
@@ -128,7 +128,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Pause")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult Pause()
+ public ActionResult SyncPlayPause()
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PlaybackRequest()
@@ -147,7 +147,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Seek")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult Seek([FromQuery] long positionTicks)
+ public ActionResult SyncPlaySeek([FromQuery] long positionTicks)
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PlaybackRequest()
@@ -169,7 +169,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Buffering")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult Buffering([FromQuery] DateTime when, [FromQuery] long positionTicks, [FromQuery] bool bufferingDone)
+ public ActionResult SyncPlayBuffering([FromQuery] DateTime when, [FromQuery] long positionTicks, [FromQuery] bool bufferingDone)
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PlaybackRequest()
@@ -190,7 +190,7 @@ namespace Jellyfin.Api.Controllers
/// A indicating success.
[HttpPost("Ping")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
- public ActionResult Ping([FromQuery] double ping)
+ public ActionResult SyncPlayPing([FromQuery] double ping)
{
var currentSession = RequestHelpers.GetSession(_sessionManager, _authorizationContext, Request);
var syncPlayRequest = new PlaybackRequest()
diff --git a/Jellyfin.Api/Controllers/SystemController.cs b/Jellyfin.Api/Controllers/SystemController.cs
index bc606f7aad..e0bce3a417 100644
--- a/Jellyfin.Api/Controllers/SystemController.cs
+++ b/Jellyfin.Api/Controllers/SystemController.cs
@@ -85,8 +85,8 @@ namespace Jellyfin.Api.Controllers
///
/// Information retrieved.
/// The server name.
- [HttpGet("Ping")]
- [HttpPost("Ping")]
+ [HttpGet("Ping", Name = "GetPingSystem")]
+ [HttpPost("Ping", Name = "PostPingSystem")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult PingSystem()
{
diff --git a/Jellyfin.Api/Controllers/TrailersController.cs b/Jellyfin.Api/Controllers/TrailersController.cs
index 645495551b..fbab7948ff 100644
--- a/Jellyfin.Api/Controllers/TrailersController.cs
+++ b/Jellyfin.Api/Controllers/TrailersController.cs
@@ -1,14 +1,10 @@
using System;
using Jellyfin.Api.Constants;
-using MediaBrowser.Controller.Dto;
-using MediaBrowser.Controller.Library;
using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers
{
@@ -18,32 +14,15 @@ namespace Jellyfin.Api.Controllers
[Authorize(Policy = Policies.DefaultAuthorization)]
public class TrailersController : BaseJellyfinApiController
{
- private readonly IUserManager _userManager;
- private readonly ILibraryManager _libraryManager;
- private readonly ILogger _logger;
- private readonly IDtoService _dtoService;
- private readonly ILocalizationManager _localizationManager;
+ private readonly ItemsController _itemsController;
///
/// Initializes a new instance of the class.
///
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- public TrailersController(
- ILoggerFactory loggerFactory,
- IUserManager userManager,
- ILibraryManager libraryManager,
- IDtoService dtoService,
- ILocalizationManager localizationManager)
+ /// Instance of .
+ public TrailersController(ItemsController itemsController)
{
- _userManager = userManager;
- _libraryManager = libraryManager;
- _dtoService = dtoService;
- _localizationManager = localizationManager;
- _logger = loggerFactory.CreateLogger();
+ _itemsController = itemsController;
}
///
@@ -214,12 +193,7 @@ namespace Jellyfin.Api.Controllers
{
var includeItemTypes = "Trailer";
- return new ItemsController(
- _userManager,
- _libraryManager,
- _localizationManager,
- _dtoService,
- _logger)
+ return _itemsController
.GetItems(
userId,
userId,
diff --git a/Jellyfin.Api/Controllers/UniversalAudioController.cs b/Jellyfin.Api/Controllers/UniversalAudioController.cs
index 87d9a611a0..5a9bec2b05 100644
--- a/Jellyfin.Api/Controllers/UniversalAudioController.cs
+++ b/Jellyfin.Api/Controllers/UniversalAudioController.cs
@@ -7,21 +7,12 @@ using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Helpers;
using Jellyfin.Api.Models.VideoDtos;
-using MediaBrowser.Common.Net;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Devices;
-using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dlna;
-using MediaBrowser.Model.IO;
using MediaBrowser.Model.MediaInfo;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
namespace Jellyfin.Api.Controllers
{
@@ -30,72 +21,28 @@ namespace Jellyfin.Api.Controllers
///
public class UniversalAudioController : BaseJellyfinApiController
{
- private readonly ILoggerFactory _loggerFactory;
- private readonly IUserManager _userManager;
- private readonly ILibraryManager _libraryManager;
- private readonly IDeviceManager _deviceManager;
- private readonly IDlnaManager _dlnaManager;
- private readonly IMediaEncoder _mediaEncoder;
- private readonly IFileSystem _fileSystem;
- private readonly IMediaSourceManager _mediaSourceManager;
private readonly IAuthorizationContext _authorizationContext;
- private readonly INetworkManager _networkManager;
- private readonly IServerConfigurationManager _serverConfigurationManager;
- private readonly TranscodingJobHelper _transcodingJobHelper;
- private readonly IConfiguration _configuration;
- private readonly ISubtitleEncoder _subtitleEncoder;
- private readonly IHttpClientFactory _httpClientFactory;
+ private readonly MediaInfoController _mediaInfoController;
+ private readonly DynamicHlsController _dynamicHlsController;
+ private readonly AudioController _audioController;
///
/// Initializes a new instance of the class.
///
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
/// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
- /// Instance of the interface.
+ /// Instance of the .
+ /// Instance of the .
+ /// Instance of the .
public UniversalAudioController(
- ILoggerFactory loggerFactory,
- IServerConfigurationManager serverConfigurationManager,
- IUserManager userManager,
- ILibraryManager libraryManager,
- IMediaEncoder mediaEncoder,
- IFileSystem fileSystem,
- IDlnaManager dlnaManager,
- IDeviceManager deviceManager,
- IMediaSourceManager mediaSourceManager,
IAuthorizationContext authorizationContext,
- INetworkManager networkManager,
- TranscodingJobHelper transcodingJobHelper,
- IConfiguration configuration,
- ISubtitleEncoder subtitleEncoder,
- IHttpClientFactory httpClientFactory)
+ MediaInfoController mediaInfoController,
+ DynamicHlsController dynamicHlsController,
+ AudioController audioController)
{
- _userManager = userManager;
- _libraryManager = libraryManager;
- _mediaEncoder = mediaEncoder;
- _fileSystem = fileSystem;
- _dlnaManager = dlnaManager;
- _deviceManager = deviceManager;
- _mediaSourceManager = mediaSourceManager;
_authorizationContext = authorizationContext;
- _networkManager = networkManager;
- _loggerFactory = loggerFactory;
- _serverConfigurationManager = serverConfigurationManager;
- _transcodingJobHelper = transcodingJobHelper;
- _configuration = configuration;
- _subtitleEncoder = subtitleEncoder;
- _httpClientFactory = httpClientFactory;
+ _mediaInfoController = mediaInfoController;
+ _dynamicHlsController = dynamicHlsController;
+ _audioController = audioController;
}
///
@@ -122,9 +69,9 @@ namespace Jellyfin.Api.Controllers
/// Redirected to remote audio stream.
/// A containing the audio file.
[HttpGet("/Audio/{itemId}/universal")]
- [HttpGet("/Audio/{itemId}/{universal=universal}.{container?}")]
- [HttpHead("/Audio/{itemId}/universal")]
- [HttpHead("/Audio/{itemId}/{universal=universal}.{container?}")]
+ [HttpGet("/Audio/{itemId}/{universal=universal}.{container?}", Name = "GetUniversalAudioStream_2")]
+ [HttpHead("/Audio/{itemId}/universal", Name = "HeadUniversalAudioStream")]
+ [HttpHead("/Audio/{itemId}/{universal=universal}.{container?}", Name = "HeadUniversalAudioStream_2")]
[Authorize(Policy = Policies.DefaultAuthorization)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status302Found)]
@@ -151,8 +98,7 @@ namespace Jellyfin.Api.Controllers
var deviceProfile = GetDeviceProfile(container, transcodingContainer, audioCodec, transcodingProtocol, breakOnNonKeyFrames, transcodingAudioChannels, maxAudioSampleRate, maxAudioBitDepth, maxAudioChannels);
_authorizationContext.GetAuthorizationInfo(Request).DeviceId = deviceId;
- var mediaInfoController = new MediaInfoController(_mediaSourceManager, _deviceManager, _libraryManager, _networkManager, _mediaEncoder, _userManager, _authorizationContext, _loggerFactory.CreateLogger(), _serverConfigurationManager);
- var playbackInfoResult = await mediaInfoController.GetPostedPlaybackInfo(
+ var playbackInfoResult = await _mediaInfoController.GetPostedPlaybackInfo(
itemId,
userId,
maxStreamingBitrate,
@@ -180,21 +126,6 @@ namespace Jellyfin.Api.Controllers
var isStatic = mediaSource.SupportsDirectStream;
if (!isStatic && string.Equals(mediaSource.TranscodingSubProtocol, "hls", StringComparison.OrdinalIgnoreCase))
{
- var dynamicHlsController = new DynamicHlsController(
- _libraryManager,
- _userManager,
- _dlnaManager,
- _authorizationContext,
- _mediaSourceManager,
- _serverConfigurationManager,
- _mediaEncoder,
- _fileSystem,
- _subtitleEncoder,
- _configuration,
- _deviceManager,
- _transcodingJobHelper,
- _networkManager,
- _loggerFactory.CreateLogger());
var transcodingProfile = deviceProfile.TranscodingProfiles[0];
// hls segment container can only be mpegts or fmp4 per ffmpeg documentation
@@ -203,10 +134,10 @@ namespace Jellyfin.Api.Controllers
if (isHeadRequest)
{
- dynamicHlsController.Request.Method = HttpMethod.Head.Method;
+ _dynamicHlsController.Request.Method = HttpMethod.Head.Method;
}
- return await dynamicHlsController.GetMasterHlsAudioPlaylist(
+ return await _dynamicHlsController.GetMasterHlsAudioPlaylist(
itemId,
".m3u8",
isStatic,
@@ -261,27 +192,12 @@ namespace Jellyfin.Api.Controllers
}
else
{
- var audioController = new AudioController(
- _dlnaManager,
- _userManager,
- _authorizationContext,
- _libraryManager,
- _mediaSourceManager,
- _serverConfigurationManager,
- _mediaEncoder,
- _fileSystem,
- _subtitleEncoder,
- _configuration,
- _deviceManager,
- _transcodingJobHelper,
- _httpClientFactory);
-
if (isHeadRequest)
{
- audioController.Request.Method = HttpMethod.Head.Method;
+ _audioController.Request.Method = HttpMethod.Head.Method;
}
- return await audioController.GetAudioStream(
+ return await _audioController.GetAudioStream(
itemId,
isStatic ? null : ("." + mediaSource.TranscodingContainer),
isStatic,
diff --git a/Jellyfin.Api/Controllers/VideoHlsController.cs b/Jellyfin.Api/Controllers/VideoHlsController.cs
index 3f8a2048e4..8520dd1638 100644
--- a/Jellyfin.Api/Controllers/VideoHlsController.cs
+++ b/Jellyfin.Api/Controllers/VideoHlsController.cs
@@ -49,7 +49,7 @@ namespace Jellyfin.Api.Controllers
private readonly IConfiguration _configuration;
private readonly IDeviceManager _deviceManager;
private readonly TranscodingJobHelper _transcodingJobHelper;
- private readonly ILogger _logger;
+ private readonly ILogger _logger;
private readonly EncodingOptions _encodingOptions;
///
diff --git a/Jellyfin.Api/Controllers/VideosController.cs b/Jellyfin.Api/Controllers/VideosController.cs
index d1ef817eb6..ebe88a9c05 100644
--- a/Jellyfin.Api/Controllers/VideosController.cs
+++ b/Jellyfin.Api/Controllers/VideosController.cs
@@ -316,10 +316,10 @@ namespace Jellyfin.Api.Controllers
/// Optional. The streaming options.
/// Video stream returned.
/// A containing the audio file.
- [HttpGet("{itemId}/{stream=stream}.{container?}")]
+ [HttpGet("{itemId}/{stream=stream}.{container?}", Name = "GetVideoStream_2")]
[HttpGet("{itemId}/stream")]
- [HttpHead("{itemId}/{stream=stream}.{container?}")]
- [HttpHead("{itemId}/stream")]
+ [HttpHead("{itemId}/{stream=stream}.{container?}", Name = "HeadVideoStream_2")]
+ [HttpHead("{itemId}/stream", Name = "HeadVideoStream")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task GetVideoStream(
[FromRoute] Guid itemId,
diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs
index d9e993d496..fbaa692700 100644
--- a/Jellyfin.Api/Helpers/RequestHelpers.cs
+++ b/Jellyfin.Api/Helpers/RequestHelpers.cs
@@ -5,7 +5,6 @@ using System.Net;
using Jellyfin.Data.Enums;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
-using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Querying;
using Microsoft.AspNetCore.Http;
diff --git a/Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs b/Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs
new file mode 100644
index 0000000000..f797a38076
--- /dev/null
+++ b/Jellyfin.Api/Models/MediaInfoDtos/OpenLiveStreamDto.cs
@@ -0,0 +1,24 @@
+using System.Diagnostics.CodeAnalysis;
+using MediaBrowser.Model.Dlna;
+using MediaBrowser.Model.MediaInfo;
+
+namespace Jellyfin.Api.Models.MediaInfoDtos
+{
+ ///
+ /// Open live stream dto.
+ ///
+ public class OpenLiveStreamDto
+ {
+ ///
+ /// Gets or sets the device profile.
+ ///
+ public DeviceProfile? DeviceProfile { get; set; }
+
+ ///
+ /// Gets or sets the device play protocols.
+ ///
+ [SuppressMessage("Microsoft.Performance", "CA1819:DontReturnArrays", MessageId = "DevicePlayProtocols", Justification = "Imported from ServiceStack")]
+ [SuppressMessage("Microsoft.Performance", "SA1011:ClosingBracketsSpace", MessageId = "DevicePlayProtocols", Justification = "Imported from ServiceStack")]
+ public MediaProtocol[]? DirectPlayProtocols { get; set; }
+ }
+}
diff --git a/MediaBrowser.Api/System/ActivityLogWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs
similarity index 75%
rename from MediaBrowser.Api/System/ActivityLogWebSocketListener.cs
rename to Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs
index 39976371a9..6395b8d62f 100644
--- a/MediaBrowser.Api/System/ActivityLogWebSocketListener.cs
+++ b/Jellyfin.Api/WebSocketListeners/ActivityLogWebSocketListener.cs
@@ -5,34 +5,35 @@ using MediaBrowser.Model.Activity;
using MediaBrowser.Model.Events;
using Microsoft.Extensions.Logging;
-namespace MediaBrowser.Api.System
+namespace Jellyfin.Api.WebSocketListeners
{
///
/// Class SessionInfoWebSocketListener.
///
public class ActivityLogWebSocketListener : BasePeriodicWebSocketListener
{
- ///
- /// Gets the name.
- ///
- /// The name.
- protected override string Name => "ActivityLogEntry";
-
///
/// The _kernel.
///
private readonly IActivityManager _activityManager;
- public ActivityLogWebSocketListener(ILogger logger, IActivityManager activityManager) : base(logger)
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ /// Instance of the interface.
+ public ActivityLogWebSocketListener(ILogger logger, IActivityManager activityManager)
+ : base(logger)
{
_activityManager = activityManager;
_activityManager.EntryCreated += OnEntryCreated;
}
- private void OnEntryCreated(object sender, GenericEventArgs e)
- {
- SendData(true);
- }
+ ///
+ /// Gets the name.
+ ///
+ /// The name.
+ protected override string Name => "ActivityLogEntry";
///
/// Gets the data to send.
@@ -50,5 +51,10 @@ namespace MediaBrowser.Api.System
base.Dispose(dispose);
}
+
+ private void OnEntryCreated(object sender, GenericEventArgs e)
+ {
+ SendData(true);
+ }
}
}
diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs
similarity index 60%
rename from MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs
rename to Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs
index 25dd39f2de..12f815ff75 100644
--- a/MediaBrowser.Api/ScheduledTasks/ScheduledTasksWebSocketListener.cs
+++ b/Jellyfin.Api/WebSocketListeners/ScheduledTasksWebSocketListener.cs
@@ -6,7 +6,7 @@ using MediaBrowser.Model.Events;
using MediaBrowser.Model.Tasks;
using Microsoft.Extensions.Logging;
-namespace MediaBrowser.Api.ScheduledTasks
+namespace Jellyfin.Api.WebSocketListeners
{
///
/// Class ScheduledTasksWebSocketListener.
@@ -17,42 +17,27 @@ namespace MediaBrowser.Api.ScheduledTasks
/// Gets or sets the task manager.
///
/// The task manager.
- private ITaskManager TaskManager { get; set; }
+ private readonly ITaskManager _taskManager;
///
- /// Gets the name.
- ///
- /// The name.
- protected override string Name => "ScheduledTasksInfo";
-
- ///
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
///
+ /// Instance of the interface.
+ /// Instance of the interface.
public ScheduledTasksWebSocketListener(ILogger logger, ITaskManager taskManager)
: base(logger)
{
- TaskManager = taskManager;
+ _taskManager = taskManager;
- TaskManager.TaskExecuting += TaskManager_TaskExecuting;
- TaskManager.TaskCompleted += TaskManager_TaskCompleted;
+ _taskManager.TaskExecuting += OnTaskExecuting;
+ _taskManager.TaskCompleted += OnTaskCompleted;
}
- void TaskManager_TaskCompleted(object sender, TaskCompletionEventArgs e)
- {
- SendData(true);
- e.Task.TaskProgress -= Argument_TaskProgress;
- }
-
- void TaskManager_TaskExecuting(object sender, GenericEventArgs e)
- {
- SendData(true);
- e.Argument.TaskProgress += Argument_TaskProgress;
- }
-
- void Argument_TaskProgress(object sender, GenericEventArgs e)
- {
- SendData(false);
- }
+ ///
+ /// Gets the name.
+ ///
+ /// The name.
+ protected override string Name => "ScheduledTasksInfo";
///
/// Gets the data to send.
@@ -60,18 +45,36 @@ namespace MediaBrowser.Api.ScheduledTasks
/// Task{IEnumerable{TaskInfo}}.
protected override Task> GetDataToSend()
{
- return Task.FromResult(TaskManager.ScheduledTasks
+ return Task.FromResult(_taskManager.ScheduledTasks
.OrderBy(i => i.Name)
.Select(ScheduledTaskHelpers.GetTaskInfo)
.Where(i => !i.IsHidden));
}
+ ///
protected override void Dispose(bool dispose)
{
- TaskManager.TaskExecuting -= TaskManager_TaskExecuting;
- TaskManager.TaskCompleted -= TaskManager_TaskCompleted;
+ _taskManager.TaskExecuting -= OnTaskExecuting;
+ _taskManager.TaskCompleted -= OnTaskCompleted;
base.Dispose(dispose);
}
+
+ private void OnTaskCompleted(object sender, TaskCompletionEventArgs e)
+ {
+ SendData(true);
+ e.Task.TaskProgress -= OnTaskProgress;
+ }
+
+ private void OnTaskExecuting(object sender, GenericEventArgs e)
+ {
+ SendData(true);
+ e.Argument.TaskProgress += OnTaskProgress;
+ }
+
+ private void OnTaskProgress(object sender, GenericEventArgs e)
+ {
+ SendData(false);
+ }
}
}
diff --git a/MediaBrowser.Api/Sessions/SessionInfoWebSocketListener.cs b/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs
similarity index 92%
rename from MediaBrowser.Api/Sessions/SessionInfoWebSocketListener.cs
rename to Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs
index 2400d6defe..1fb5dc412c 100644
--- a/MediaBrowser.Api/Sessions/SessionInfoWebSocketListener.cs
+++ b/Jellyfin.Api/WebSocketListeners/SessionInfoWebSocketListener.cs
@@ -5,27 +5,20 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Session;
using Microsoft.Extensions.Logging;
-namespace MediaBrowser.Api.Sessions
+namespace Jellyfin.Api.WebSocketListeners
{
///
/// Class SessionInfoWebSocketListener.
///
public class SessionInfoWebSocketListener : BasePeriodicWebSocketListener, WebSocketListenerState>
{
- ///
- /// Gets the name.
- ///
- /// The name.
- protected override string Name => "Sessions";
-
- ///
- /// The _kernel.
- ///
private readonly ISessionManager _sessionManager;
///
/// Initializes a new instance of the class.
///
+ /// Instance of the interface.
+ /// Instance of the interface.
public SessionInfoWebSocketListener(ILogger logger, ISessionManager sessionManager)
: base(logger)
{
@@ -40,6 +33,32 @@ namespace MediaBrowser.Api.Sessions
_sessionManager.SessionActivity += OnSessionManagerSessionActivity;
}
+ ///
+ protected override string Name => "Sessions";
+
+ ///
+ /// Gets the data to send.
+ ///
+ /// Task{SystemInfo}.
+ protected override Task> GetDataToSend()
+ {
+ return Task.FromResult(_sessionManager.Sessions);
+ }
+
+ ///
+ protected override void Dispose(bool dispose)
+ {
+ _sessionManager.SessionStarted -= OnSessionManagerSessionStarted;
+ _sessionManager.SessionEnded -= OnSessionManagerSessionEnded;
+ _sessionManager.PlaybackStart -= OnSessionManagerPlaybackStart;
+ _sessionManager.PlaybackStopped -= OnSessionManagerPlaybackStopped;
+ _sessionManager.PlaybackProgress -= OnSessionManagerPlaybackProgress;
+ _sessionManager.CapabilitiesChanged -= OnSessionManagerCapabilitiesChanged;
+ _sessionManager.SessionActivity -= OnSessionManagerSessionActivity;
+
+ base.Dispose(dispose);
+ }
+
private async void OnSessionManagerSessionActivity(object sender, SessionEventArgs e)
{
await SendData(false).ConfigureAwait(false);
@@ -74,28 +93,5 @@ namespace MediaBrowser.Api.Sessions
{
await SendData(true).ConfigureAwait(false);
}
-
- ///
- /// Gets the data to send.
- ///
- /// Task{SystemInfo}.
- protected override Task> GetDataToSend()
- {
- return Task.FromResult(_sessionManager.Sessions);
- }
-
- ///
- protected override void Dispose(bool dispose)
- {
- _sessionManager.SessionStarted -= OnSessionManagerSessionStarted;
- _sessionManager.SessionEnded -= OnSessionManagerSessionEnded;
- _sessionManager.PlaybackStart -= OnSessionManagerPlaybackStart;
- _sessionManager.PlaybackStopped -= OnSessionManagerPlaybackStopped;
- _sessionManager.PlaybackProgress -= OnSessionManagerPlaybackProgress;
- _sessionManager.CapabilitiesChanged -= OnSessionManagerCapabilitiesChanged;
- _sessionManager.SessionActivity -= OnSessionManagerSessionActivity;
-
- base.Dispose(dispose);
- }
}
}
diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
index cfbabf7954..6e91042dfd 100644
--- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
+++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs
@@ -198,8 +198,15 @@ namespace Jellyfin.Server.Extensions
$"{description.ActionDescriptor.RouteValues["controller"]}_{description.RelativePath}");
// Use method name as operationId
- c.CustomOperationIds(description =>
- description.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : null);
+ c.CustomOperationIds(
+ description =>
+ {
+ description.TryGetMethodInfo(out MethodInfo methodInfo);
+ // Attribute name, method name, none.
+ return description?.ActionDescriptor?.AttributeRouteInfo?.Name
+ ?? methodInfo?.Name
+ ?? null;
+ });
// TODO - remove when all types are supported in System.Text.Json
c.AddSwaggerTypeMappings();
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs
deleted file mode 100644
index b041effb2e..0000000000
--- a/MediaBrowser.Api/ApiEntryPoint.cs
+++ /dev/null
@@ -1,678 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Api.Playback;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.MediaEncoding;
-using MediaBrowser.Controller.Plugins;
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Session;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Api
-{
- ///
- /// Class ServerEntryPoint.
- ///
- public class ApiEntryPoint : IServerEntryPoint
- {
- ///
- /// The instance.
- ///
- public static ApiEntryPoint Instance;
-
- ///
- /// The logger.
- ///
- private ILogger _logger;
-
- ///
- /// The configuration manager.
- ///
- private IServerConfigurationManager _serverConfigurationManager;
-
- private readonly ISessionManager _sessionManager;
- private readonly IFileSystem _fileSystem;
- private readonly IMediaSourceManager _mediaSourceManager;
-
- ///
- /// The active transcoding jobs.
- ///
- private readonly List _activeTranscodingJobs = new List();
-
- private readonly Dictionary _transcodingLocks =
- new Dictionary();
-
- private bool _disposed = false;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The logger.
- /// The session manager.
- /// The configuration.
- /// The file system.
- /// The media source manager.
- public ApiEntryPoint(
- ILogger logger,
- ISessionManager sessionManager,
- IServerConfigurationManager config,
- IFileSystem fileSystem,
- IMediaSourceManager mediaSourceManager)
- {
- _logger = logger;
- _sessionManager = sessionManager;
- _serverConfigurationManager = config;
- _fileSystem = fileSystem;
- _mediaSourceManager = mediaSourceManager;
-
- _sessionManager.PlaybackProgress += OnPlaybackProgress;
- _sessionManager.PlaybackStart += OnPlaybackStart;
-
- Instance = this;
- }
-
- public static string[] Split(string value, char separator, bool removeEmpty)
- {
- if (string.IsNullOrWhiteSpace(value))
- {
- return Array.Empty();
- }
-
- return removeEmpty
- ? value.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries)
- : value.Split(separator);
- }
-
- public SemaphoreSlim GetTranscodingLock(string outputPath)
- {
- lock (_transcodingLocks)
- {
- if (!_transcodingLocks.TryGetValue(outputPath, out SemaphoreSlim result))
- {
- result = new SemaphoreSlim(1, 1);
- _transcodingLocks[outputPath] = result;
- }
-
- return result;
- }
- }
-
- private void OnPlaybackStart(object sender, PlaybackProgressEventArgs e)
- {
- if (!string.IsNullOrWhiteSpace(e.PlaySessionId))
- {
- PingTranscodingJob(e.PlaySessionId, e.IsPaused);
- }
- }
-
- private void OnPlaybackProgress(object sender, PlaybackProgressEventArgs e)
- {
- if (!string.IsNullOrWhiteSpace(e.PlaySessionId))
- {
- PingTranscodingJob(e.PlaySessionId, e.IsPaused);
- }
- }
-
- ///
- /// Runs this instance.
- ///
- public Task RunAsync()
- {
- try
- {
- DeleteEncodedMediaCache();
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error deleting encoded media cache");
- }
-
- return Task.CompletedTask;
- }
-
- ///
- /// Deletes the encoded media cache.
- ///
- private void DeleteEncodedMediaCache()
- {
- var path = _serverConfigurationManager.GetTranscodePath();
- if (!Directory.Exists(path))
- {
- return;
- }
-
- foreach (var file in _fileSystem.GetFilePaths(path, true))
- {
- _fileSystem.DeleteFile(file);
- }
- }
-
- ///
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- ///
- /// Releases unmanaged and - optionally - managed resources.
- ///
- /// true to release both managed and unmanaged resources; false to release only unmanaged resources.
- protected virtual void Dispose(bool dispose)
- {
- if (_disposed)
- {
- return;
- }
-
- if (dispose)
- {
- // TODO: dispose
- }
-
- var jobs = _activeTranscodingJobs.ToList();
- var jobCount = jobs.Count;
-
- IEnumerable GetKillJobs()
- {
- foreach (var job in jobs)
- {
- yield return KillTranscodingJob(job, false, path => true);
- }
- }
-
- // Wait for all processes to be killed
- if (jobCount > 0)
- {
- Task.WaitAll(GetKillJobs().ToArray());
- }
-
- _activeTranscodingJobs.Clear();
- _transcodingLocks.Clear();
-
- _sessionManager.PlaybackProgress -= OnPlaybackProgress;
- _sessionManager.PlaybackStart -= OnPlaybackStart;
-
- _disposed = true;
- }
-
-
- ///
- /// Called when [transcode beginning].
- ///
- /// The path.
- /// The play session identifier.
- /// The live stream identifier.
- /// The transcoding job identifier.
- /// The type.
- /// The process.
- /// The device id.
- /// The state.
- /// The cancellation token source.
- /// TranscodingJob.
- public TranscodingJob OnTranscodeBeginning(
- string path,
- string playSessionId,
- string liveStreamId,
- string transcodingJobId,
- TranscodingJobType type,
- Process process,
- string deviceId,
- StreamState state,
- CancellationTokenSource cancellationTokenSource)
- {
- lock (_activeTranscodingJobs)
- {
- var job = new TranscodingJob(_logger)
- {
- Type = type,
- Path = path,
- Process = process,
- ActiveRequestCount = 1,
- DeviceId = deviceId,
- CancellationTokenSource = cancellationTokenSource,
- Id = transcodingJobId,
- PlaySessionId = playSessionId,
- LiveStreamId = liveStreamId,
- MediaSource = state.MediaSource
- };
-
- _activeTranscodingJobs.Add(job);
-
- ReportTranscodingProgress(job, state, null, null, null, null, null);
-
- return job;
- }
- }
-
- public void ReportTranscodingProgress(TranscodingJob job, StreamState state, TimeSpan? transcodingPosition, float? framerate, double? percentComplete, long? bytesTranscoded, int? bitRate)
- {
- var ticks = transcodingPosition?.Ticks;
-
- if (job != null)
- {
- job.Framerate = framerate;
- job.CompletionPercentage = percentComplete;
- job.TranscodingPositionTicks = ticks;
- job.BytesTranscoded = bytesTranscoded;
- job.BitRate = bitRate;
- }
-
- var deviceId = state.Request.DeviceId;
-
- if (!string.IsNullOrWhiteSpace(deviceId))
- {
- var audioCodec = state.ActualOutputAudioCodec;
- var videoCodec = state.ActualOutputVideoCodec;
-
- _sessionManager.ReportTranscodingInfo(deviceId, new TranscodingInfo
- {
- Bitrate = bitRate ?? state.TotalOutputBitrate,
- AudioCodec = audioCodec,
- VideoCodec = videoCodec,
- Container = state.OutputContainer,
- Framerate = framerate,
- CompletionPercentage = percentComplete,
- Width = state.OutputWidth,
- Height = state.OutputHeight,
- AudioChannels = state.OutputAudioChannels,
- IsAudioDirect = EncodingHelper.IsCopyCodec(state.OutputAudioCodec),
- IsVideoDirect = EncodingHelper.IsCopyCodec(state.OutputVideoCodec),
- TranscodeReasons = state.TranscodeReasons
- });
- }
- }
-
- ///
- ///
- /// The progressive.
- ///
- /// Called when [transcode failed to start].
- ///
- /// The path.
- /// The type.
- /// The state.
- public void OnTranscodeFailedToStart(string path, TranscodingJobType type, StreamState state)
- {
- lock (_activeTranscodingJobs)
- {
- var job = _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && string.Equals(j.Path, path, StringComparison.OrdinalIgnoreCase));
-
- if (job != null)
- {
- _activeTranscodingJobs.Remove(job);
- }
- }
-
- lock (_transcodingLocks)
- {
- _transcodingLocks.Remove(path);
- }
-
- if (!string.IsNullOrWhiteSpace(state.Request.DeviceId))
- {
- _sessionManager.ClearTranscodingInfo(state.Request.DeviceId);
- }
- }
-
- ///
- /// Determines whether [has active transcoding job] [the specified path].
- ///
- /// The path.
- /// The type.
- /// true if [has active transcoding job] [the specified path]; otherwise, false.
- public bool HasActiveTranscodingJob(string path, TranscodingJobType type)
- {
- return GetTranscodingJob(path, type) != null;
- }
-
- public TranscodingJob GetTranscodingJob(string path, TranscodingJobType type)
- {
- lock (_activeTranscodingJobs)
- {
- return _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && string.Equals(j.Path, path, StringComparison.OrdinalIgnoreCase));
- }
- }
-
- public TranscodingJob GetTranscodingJob(string playSessionId)
- {
- lock (_activeTranscodingJobs)
- {
- return _activeTranscodingJobs.FirstOrDefault(j => string.Equals(j.PlaySessionId, playSessionId, StringComparison.OrdinalIgnoreCase));
- }
- }
-
- ///
- /// Called when [transcode begin request].
- ///
- /// The path.
- /// The type.
- public TranscodingJob OnTranscodeBeginRequest(string path, TranscodingJobType type)
- {
- lock (_activeTranscodingJobs)
- {
- var job = _activeTranscodingJobs.FirstOrDefault(j => j.Type == type && string.Equals(j.Path, path, StringComparison.OrdinalIgnoreCase));
-
- if (job == null)
- {
- return null;
- }
-
- OnTranscodeBeginRequest(job);
-
- return job;
- }
- }
-
- public void OnTranscodeBeginRequest(TranscodingJob job)
- {
- job.ActiveRequestCount++;
-
- if (string.IsNullOrWhiteSpace(job.PlaySessionId) || job.Type == TranscodingJobType.Progressive)
- {
- job.StopKillTimer();
- }
- }
-
- public void OnTranscodeEndRequest(TranscodingJob job)
- {
- job.ActiveRequestCount--;
- _logger.LogDebug("OnTranscodeEndRequest job.ActiveRequestCount={0}", job.ActiveRequestCount);
- if (job.ActiveRequestCount <= 0)
- {
- PingTimer(job, false);
- }
- }
-
- internal void PingTranscodingJob(string playSessionId, bool? isUserPaused)
- {
- if (string.IsNullOrEmpty(playSessionId))
- {
- throw new ArgumentNullException(nameof(playSessionId));
- }
-
- _logger.LogDebug("PingTranscodingJob PlaySessionId={0} isUsedPaused: {1}", playSessionId, isUserPaused);
-
- List jobs;
-
- lock (_activeTranscodingJobs)
- {
- // This is really only needed for HLS.
- // Progressive streams can stop on their own reliably
- jobs = _activeTranscodingJobs.Where(j => string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase)).ToList();
- }
-
- foreach (var job in jobs)
- {
- if (isUserPaused.HasValue)
- {
- _logger.LogDebug("Setting job.IsUserPaused to {0}. jobId: {1}", isUserPaused, job.Id);
- job.IsUserPaused = isUserPaused.Value;
- }
-
- PingTimer(job, true);
- }
- }
-
- private void PingTimer(TranscodingJob job, bool isProgressCheckIn)
- {
- if (job.HasExited)
- {
- job.StopKillTimer();
- return;
- }
-
- var timerDuration = 10000;
-
- if (job.Type != TranscodingJobType.Progressive)
- {
- timerDuration = 60000;
- }
-
- job.PingTimeout = timerDuration;
- job.LastPingDate = DateTime.UtcNow;
-
- // Don't start the timer for playback checkins with progressive streaming
- if (job.Type != TranscodingJobType.Progressive || !isProgressCheckIn)
- {
- job.StartKillTimer(OnTranscodeKillTimerStopped);
- }
- else
- {
- job.ChangeKillTimerIfStarted();
- }
- }
-
- ///
- /// Called when [transcode kill timer stopped].
- ///
- /// The state.
- private async void OnTranscodeKillTimerStopped(object state)
- {
- var job = (TranscodingJob)state;
-
- if (!job.HasExited && job.Type != TranscodingJobType.Progressive)
- {
- var timeSinceLastPing = (DateTime.UtcNow - job.LastPingDate).TotalMilliseconds;
-
- if (timeSinceLastPing < job.PingTimeout)
- {
- job.StartKillTimer(OnTranscodeKillTimerStopped, job.PingTimeout);
- return;
- }
- }
-
- _logger.LogInformation("Transcoding kill timer stopped for JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId);
-
- await KillTranscodingJob(job, true, path => true);
- }
-
- ///
- /// Kills the single transcoding job.
- ///
- /// The device id.
- /// The play session identifier.
- /// The delete files.
- /// Task.
- internal Task KillTranscodingJobs(string deviceId, string playSessionId, Func deleteFiles)
- {
- return KillTranscodingJobs(j => string.IsNullOrWhiteSpace(playSessionId)
- ? string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase)
- : string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase), deleteFiles);
- }
-
- ///
- /// Kills the transcoding jobs.
- ///
- /// The kill job.
- /// The delete files.
- /// Task.
- private Task KillTranscodingJobs(Func killJob, Func deleteFiles)
- {
- var jobs = new List();
-
- lock (_activeTranscodingJobs)
- {
- // This is really only needed for HLS.
- // Progressive streams can stop on their own reliably
- jobs.AddRange(_activeTranscodingJobs.Where(killJob));
- }
-
- if (jobs.Count == 0)
- {
- return Task.CompletedTask;
- }
-
- IEnumerable GetKillJobs()
- {
- foreach (var job in jobs)
- {
- yield return KillTranscodingJob(job, false, deleteFiles);
- }
- }
-
- return Task.WhenAll(GetKillJobs());
- }
-
- ///
- /// Kills the transcoding job.
- ///
- /// The job.
- /// if set to true [close live stream].
- /// The delete.
- private async Task KillTranscodingJob(TranscodingJob job, bool closeLiveStream, Func delete)
- {
- job.DisposeKillTimer();
-
- _logger.LogDebug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId);
-
- lock (_activeTranscodingJobs)
- {
- _activeTranscodingJobs.Remove(job);
-
- if (!job.CancellationTokenSource.IsCancellationRequested)
- {
- job.CancellationTokenSource.Cancel();
- }
- }
-
- lock (_transcodingLocks)
- {
- _transcodingLocks.Remove(job.Path);
- }
-
- lock (job.ProcessLock)
- {
- job.TranscodingThrottler?.Stop().GetAwaiter().GetResult();
-
- var process = job.Process;
-
- var hasExited = job.HasExited;
-
- if (!hasExited)
- {
- try
- {
- _logger.LogInformation("Stopping ffmpeg process with q command for {Path}", job.Path);
-
- process.StandardInput.WriteLine("q");
-
- // Need to wait because killing is asynchronous
- if (!process.WaitForExit(5000))
- {
- _logger.LogInformation("Killing ffmpeg process for {Path}", job.Path);
- process.Kill();
- }
- }
- catch (InvalidOperationException)
- {
- }
- }
- }
-
- if (delete(job.Path))
- {
- await DeletePartialStreamFiles(job.Path, job.Type, 0, 1500).ConfigureAwait(false);
- }
-
- if (closeLiveStream && !string.IsNullOrWhiteSpace(job.LiveStreamId))
- {
- try
- {
- await _mediaSourceManager.CloseLiveStream(job.LiveStreamId).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error closing live stream for {Path}", job.Path);
- }
- }
- }
-
- private async Task DeletePartialStreamFiles(string path, TranscodingJobType jobType, int retryCount, int delayMs)
- {
- if (retryCount >= 10)
- {
- return;
- }
-
- _logger.LogInformation("Deleting partial stream file(s) {Path}", path);
-
- await Task.Delay(delayMs).ConfigureAwait(false);
-
- try
- {
- if (jobType == TranscodingJobType.Progressive)
- {
- DeleteProgressivePartialStreamFiles(path);
- }
- else
- {
- DeleteHlsPartialStreamFiles(path);
- }
- }
- catch (IOException ex)
- {
- _logger.LogError(ex, "Error deleting partial stream file(s) {Path}", path);
-
- await DeletePartialStreamFiles(path, jobType, retryCount + 1, 500).ConfigureAwait(false);
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, "Error deleting partial stream file(s) {Path}", path);
- }
- }
-
- ///
- /// Deletes the progressive partial stream files.
- ///
- /// The output file path.
- private void DeleteProgressivePartialStreamFiles(string outputFilePath)
- {
- if (File.Exists(outputFilePath))
- {
- _fileSystem.DeleteFile(outputFilePath);
- }
- }
-
- ///
- /// Deletes the HLS partial stream files.
- ///
- /// The output file path.
- private void DeleteHlsPartialStreamFiles(string outputFilePath)
- {
- var directory = Path.GetDirectoryName(outputFilePath);
- var name = Path.GetFileNameWithoutExtension(outputFilePath);
-
- var filesToDelete = _fileSystem.GetFilePaths(directory)
- .Where(f => f.IndexOf(name, StringComparison.OrdinalIgnoreCase) != -1);
-
- List exs = null;
- foreach (var file in filesToDelete)
- {
- try
- {
- _logger.LogDebug("Deleting HLS file {0}", file);
- _fileSystem.DeleteFile(file);
- }
- catch (IOException ex)
- {
- (exs ??= new List(4)).Add(ex);
- _logger.LogError(ex, "Error deleting HLS file {Path}", file);
- }
- }
-
- if (exs != null)
- {
- throw new AggregateException("Error deleting HLS files", exs);
- }
- }
- }
-}
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs
deleted file mode 100644
index 63a31a7452..0000000000
--- a/MediaBrowser.Api/BaseApiService.cs
+++ /dev/null
@@ -1,416 +0,0 @@
-using System;
-using System.IO;
-using System.Linq;
-using Jellyfin.Data.Enums;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Dto;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Entities.Audio;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Controller.Session;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.Querying;
-using MediaBrowser.Model.Services;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Api
-{
- ///
- /// Class BaseApiService.
- ///
- public abstract class BaseApiService : IService, IRequiresRequest
- {
- public BaseApiService(
- ILogger logger,
- IServerConfigurationManager serverConfigurationManager,
- IHttpResultFactory httpResultFactory)
- {
- Logger = logger;
- ServerConfigurationManager = serverConfigurationManager;
- ResultFactory = httpResultFactory;
- }
-
- ///
- /// Gets the logger.
- ///
- /// The logger.
- protected ILogger Logger { get; }
-
- ///
- /// Gets or sets the server configuration manager.
- ///
- /// The server configuration manager.
- protected IServerConfigurationManager ServerConfigurationManager { get; }
-
- ///
- /// Gets the HTTP result factory.
- ///
- /// The HTTP result factory.
- protected IHttpResultFactory ResultFactory { get; }
-
- ///
- /// Gets or sets the request context.
- ///
- /// The request context.
- public IRequest Request { get; set; }
-
- public string GetHeader(string name) => Request.Headers[name];
-
- public static string[] SplitValue(string value, char delim)
- {
- return value == null
- ? Array.Empty()
- : value.Split(new[] { delim }, StringSplitOptions.RemoveEmptyEntries);
- }
-
- public static Guid[] GetGuids(string value)
- {
- if (value == null)
- {
- return Array.Empty();
- }
-
- return value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(i => new Guid(i))
- .ToArray();
- }
-
- ///
- /// To the optimized result.
- ///
- ///
- /// The result.
- /// System.Object.
- protected object ToOptimizedResult(T result)
- where T : class
- {
- return ResultFactory.GetResult(Request, result);
- }
-
- protected void AssertCanUpdateUser(IAuthorizationContext authContext, IUserManager userManager, Guid userId, bool restrictUserPreferences)
- {
- var auth = authContext.GetAuthorizationInfo(Request);
-
- var authenticatedUser = auth.User;
-
- // If they're going to update the record of another user, they must be an administrator
- if ((!userId.Equals(auth.UserId) && !authenticatedUser.HasPermission(PermissionKind.IsAdministrator))
- || (restrictUserPreferences && !authenticatedUser.EnableUserPreferenceAccess))
- {
- throw new SecurityException("Unauthorized access.");
- }
- }
-
- ///
- /// Gets the session.
- ///
- /// SessionInfo.
- protected SessionInfo GetSession(ISessionContext sessionContext)
- {
- var session = sessionContext.GetSession(Request);
-
- if (session == null)
- {
- throw new ArgumentException("Session not found.");
- }
-
- return session;
- }
-
- protected DtoOptions GetDtoOptions(IAuthorizationContext authContext, object request)
- {
- var options = new DtoOptions();
-
- if (request is IHasItemFields hasFields)
- {
- options.Fields = hasFields.GetItemFields();
- }
-
- if (!options.ContainsField(ItemFields.RecursiveItemCount)
- || !options.ContainsField(ItemFields.ChildCount))
- {
- var client = authContext.GetAuthorizationInfo(Request).Client ?? string.Empty;
- if (client.IndexOf("kodi", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("wmc", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("media center", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("classic", StringComparison.OrdinalIgnoreCase) != -1)
- {
- int oldLen = options.Fields.Length;
- var arr = new ItemFields[oldLen + 1];
- options.Fields.CopyTo(arr, 0);
- arr[oldLen] = ItemFields.RecursiveItemCount;
- options.Fields = arr;
- }
-
- if (client.IndexOf("kodi", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("wmc", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("media center", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("classic", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("roku", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("samsung", StringComparison.OrdinalIgnoreCase) != -1 ||
- client.IndexOf("androidtv", StringComparison.OrdinalIgnoreCase) != -1)
- {
-
- int oldLen = options.Fields.Length;
- var arr = new ItemFields[oldLen + 1];
- options.Fields.CopyTo(arr, 0);
- arr[oldLen] = ItemFields.ChildCount;
- options.Fields = arr;
- }
- }
-
- if (request is IHasDtoOptions hasDtoOptions)
- {
- options.EnableImages = hasDtoOptions.EnableImages ?? true;
-
- if (hasDtoOptions.ImageTypeLimit.HasValue)
- {
- options.ImageTypeLimit = hasDtoOptions.ImageTypeLimit.Value;
- }
-
- if (hasDtoOptions.EnableUserData.HasValue)
- {
- options.EnableUserData = hasDtoOptions.EnableUserData.Value;
- }
-
- if (!string.IsNullOrWhiteSpace(hasDtoOptions.EnableImageTypes))
- {
- options.ImageTypes = hasDtoOptions.EnableImageTypes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
- .Select(v => (ImageType)Enum.Parse(typeof(ImageType), v, true))
- .ToArray();
- }
- }
-
- return options;
- }
-
- protected MusicArtist GetArtist(string name, ILibraryManager libraryManager, DtoOptions dtoOptions)
- {
- if (name.IndexOf(BaseItem.SlugChar) != -1)
- {
- var result = GetItemFromSlugName(libraryManager, name, dtoOptions);
-
- if (result != null)
- {
- return result;
- }
- }
-
- return libraryManager.GetArtist(name, dtoOptions);
- }
-
- protected Studio GetStudio(string name, ILibraryManager libraryManager, DtoOptions dtoOptions)
- {
- if (name.IndexOf(BaseItem.SlugChar) != -1)
- {
- var result = GetItemFromSlugName(libraryManager, name, dtoOptions);
-
- if (result != null)
- {
- return result;
- }
- }
-
- return libraryManager.GetStudio(name);
- }
-
- protected Genre GetGenre(string name, ILibraryManager libraryManager, DtoOptions dtoOptions)
- {
- if (name.IndexOf(BaseItem.SlugChar) != -1)
- {
- var result = GetItemFromSlugName(libraryManager, name, dtoOptions);
-
- if (result != null)
- {
- return result;
- }
- }
-
- return libraryManager.GetGenre(name);
- }
-
- protected MusicGenre GetMusicGenre(string name, ILibraryManager libraryManager, DtoOptions dtoOptions)
- {
- if (name.IndexOf(BaseItem.SlugChar) != -1)
- {
- var result = GetItemFromSlugName(libraryManager, name, dtoOptions);
-
- if (result != null)
- {
- return result;
- }
- }
-
- return libraryManager.GetMusicGenre(name);
- }
-
- protected Person GetPerson(string name, ILibraryManager libraryManager, DtoOptions dtoOptions)
- {
- if (name.IndexOf(BaseItem.SlugChar) != -1)
- {
- var result = GetItemFromSlugName(libraryManager, name, dtoOptions);
-
- if (result != null)
- {
- return result;
- }
- }
-
- return libraryManager.GetPerson(name);
- }
-
- private T GetItemFromSlugName(ILibraryManager libraryManager, string name, DtoOptions dtoOptions)
- where T : BaseItem, new()
- {
- var result = libraryManager.GetItemList(new InternalItemsQuery
- {
- Name = name.Replace(BaseItem.SlugChar, '&'),
- IncludeItemTypes = new[] { typeof(T).Name },
- DtoOptions = dtoOptions
- }).OfType().FirstOrDefault();
-
- result ??= libraryManager.GetItemList(new InternalItemsQuery
- {
- Name = name.Replace(BaseItem.SlugChar, '/'),
- IncludeItemTypes = new[] { typeof(T).Name },
- DtoOptions = dtoOptions
- }).OfType().FirstOrDefault();
-
- result ??= libraryManager.GetItemList(new InternalItemsQuery
- {
- Name = name.Replace(BaseItem.SlugChar, '?'),
- IncludeItemTypes = new[] { typeof(T).Name },
- DtoOptions = dtoOptions
- }).OfType().FirstOrDefault();
-
- return result;
- }
-
- ///
- /// Gets the path segment at the specified index.
- ///
- /// The index of the path segment.
- /// The path segment at the specified index.
- /// Path doesn't contain enough segments.
- /// Path doesn't start with the base url.
- protected internal ReadOnlySpan GetPathValue(int index)
- {
- static void ThrowIndexOutOfRangeException()
- => throw new IndexOutOfRangeException("Path doesn't contain enough segments.");
-
- static void ThrowInvalidDataException()
- => throw new InvalidDataException("Path doesn't start with the base url.");
-
- ReadOnlySpan path = Request.PathInfo;
-
- // Remove the protocol part from the url
- int pos = path.LastIndexOf("://");
- if (pos != -1)
- {
- path = path.Slice(pos + 3);
- }
-
- // Remove the query string
- pos = path.LastIndexOf('?');
- if (pos != -1)
- {
- path = path.Slice(0, pos);
- }
-
- // Remove the domain
- pos = path.IndexOf('/');
- if (pos != -1)
- {
- path = path.Slice(pos);
- }
-
- // Remove base url
- string baseUrl = ServerConfigurationManager.Configuration.BaseUrl;
- int baseUrlLen = baseUrl.Length;
- if (baseUrlLen != 0)
- {
- if (path.StartsWith(baseUrl, StringComparison.OrdinalIgnoreCase))
- {
- path = path.Slice(baseUrlLen);
- }
- else
- {
- // The path doesn't start with the base url,
- // how did we get here?
- ThrowInvalidDataException();
- }
- }
-
- // Remove leading /
- path = path.Slice(1);
-
- // Backwards compatibility
- const string Emby = "emby/";
- if (path.StartsWith(Emby, StringComparison.OrdinalIgnoreCase))
- {
- path = path.Slice(Emby.Length);
- }
-
- const string MediaBrowser = "mediabrowser/";
- if (path.StartsWith(MediaBrowser, StringComparison.OrdinalIgnoreCase))
- {
- path = path.Slice(MediaBrowser.Length);
- }
-
- // Skip segments until we are at the right index
- for (int i = 0; i < index; i++)
- {
- pos = path.IndexOf('/');
- if (pos == -1)
- {
- ThrowIndexOutOfRangeException();
- }
-
- path = path.Slice(pos + 1);
- }
-
- // Remove the rest
- pos = path.IndexOf('/');
- if (pos != -1)
- {
- path = path.Slice(0, pos);
- }
-
- return path;
- }
-
- ///
- /// Gets the name of the item by.
- ///
- protected BaseItem GetItemByName(string name, string type, ILibraryManager libraryManager, DtoOptions dtoOptions)
- {
- if (type.Equals("Person", StringComparison.OrdinalIgnoreCase))
- {
- return GetPerson(name, libraryManager, dtoOptions);
- }
- else if (type.Equals("Artist", StringComparison.OrdinalIgnoreCase))
- {
- return GetArtist(name, libraryManager, dtoOptions);
- }
- else if (type.Equals("Genre", StringComparison.OrdinalIgnoreCase))
- {
- return GetGenre(name, libraryManager, dtoOptions);
- }
- else if (type.Equals("MusicGenre", StringComparison.OrdinalIgnoreCase))
- {
- return GetMusicGenre(name, libraryManager, dtoOptions);
- }
- else if (type.Equals("Studio", StringComparison.OrdinalIgnoreCase))
- {
- return GetStudio(name, libraryManager, dtoOptions);
- }
- else if (type.Equals("Year", StringComparison.OrdinalIgnoreCase))
- {
- return libraryManager.GetYear(int.Parse(name));
- }
-
- throw new ArgumentException("Invalid type", nameof(type));
- }
- }
-}
diff --git a/MediaBrowser.Api/IHasDtoOptions.cs b/MediaBrowser.Api/IHasDtoOptions.cs
deleted file mode 100644
index 33d498e8bd..0000000000
--- a/MediaBrowser.Api/IHasDtoOptions.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace MediaBrowser.Api
-{
- public interface IHasDtoOptions : IHasItemFields
- {
- bool? EnableImages { get; set; }
-
- bool? EnableUserData { get; set; }
-
- int? ImageTypeLimit { get; set; }
-
- string EnableImageTypes { get; set; }
- }
-}
diff --git a/MediaBrowser.Api/IHasItemFields.cs b/MediaBrowser.Api/IHasItemFields.cs
deleted file mode 100644
index ad4f1b4891..0000000000
--- a/MediaBrowser.Api/IHasItemFields.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System;
-using System.Linq;
-using MediaBrowser.Model.Querying;
-
-namespace MediaBrowser.Api
-{
- ///
- /// Interface IHasItemFields.
- ///
- public interface IHasItemFields
- {
- ///
- /// Gets or sets the fields.
- ///
- /// The fields.
- string Fields { get; set; }
- }
-
- ///
- /// Class ItemFieldsExtensions.
- ///
- public static class ItemFieldsExtensions
- {
- ///
- /// Gets the item fields.
- ///
- /// The request.
- /// IEnumerable{ItemFields}.
- public static ItemFields[] GetItemFields(this IHasItemFields request)
- {
- var val = request.Fields;
-
- if (string.IsNullOrEmpty(val))
- {
- return Array.Empty();
- }
-
- return val.Split(',').Select(v =>
- {
- if (Enum.TryParse(v, true, out ItemFields value))
- {
- return (ItemFields?)value;
- }
-
- return null;
- }).Where(i => i.HasValue).Select(i => i.Value).ToArray();
- }
- }
-}
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
deleted file mode 100644
index 3f75a3b296..0000000000
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
- {4FD51AC5-2C16-4308-A993-C3A84F3B4582}
-
-
-
-
-
-
-
-
-
-
-
-
-
- netstandard2.1
- false
- true
-
-
-
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
deleted file mode 100644
index 84ed5dcac4..0000000000
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ /dev/null
@@ -1,1008 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using Jellyfin.Data.Enums;
-using MediaBrowser.Common.Configuration;
-using MediaBrowser.Common.Extensions;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Devices;
-using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.MediaEncoding;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.Configuration;
-using MediaBrowser.Model.Dlna;
-using MediaBrowser.Model.Dto;
-using MediaBrowser.Model.Entities;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.MediaInfo;
-using MediaBrowser.Model.Serialization;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Api.Playback
-{
- ///
- /// Class BaseStreamingService.
- ///
- public abstract class BaseStreamingService : BaseApiService
- {
- protected virtual bool EnableOutputInSubFolder => false;
-
- ///
- /// Gets or sets the user manager.
- ///
- /// The user manager.
- protected IUserManager UserManager { get; private set; }
-
- ///
- /// Gets or sets the library manager.
- ///
- /// The library manager.
- protected ILibraryManager LibraryManager { get; private set; }
-
- ///
- /// Gets or sets the iso manager.
- ///
- /// The iso manager.
- protected IIsoManager IsoManager { get; private set; }
-
- ///
- /// Gets or sets the media encoder.
- ///
- /// The media encoder.
- protected IMediaEncoder MediaEncoder { get; private set; }
-
- protected IFileSystem FileSystem { get; private set; }
-
- protected IDlnaManager DlnaManager { get; private set; }
-
- protected IDeviceManager DeviceManager { get; private set; }
-
- protected IMediaSourceManager MediaSourceManager { get; private set; }
-
- protected IJsonSerializer JsonSerializer { get; private set; }
-
- protected IAuthorizationContext AuthorizationContext { get; private set; }
-
- protected EncodingHelper EncodingHelper { get; set; }
-
- ///
- /// Gets the type of the transcoding job.
- ///
- /// The type of the transcoding job.
- protected abstract TranscodingJobType TranscodingJobType { get; }
-
- ///
- /// Initializes a new instance of the class.
- ///
- protected BaseStreamingService(
- ILogger logger,
- IServerConfigurationManager serverConfigurationManager,
- IHttpResultFactory httpResultFactory,
- IUserManager userManager,
- ILibraryManager libraryManager,
- IIsoManager isoManager,
- IMediaEncoder mediaEncoder,
- IFileSystem fileSystem,
- IDlnaManager dlnaManager,
- IDeviceManager deviceManager,
- IMediaSourceManager mediaSourceManager,
- IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- EncodingHelper encodingHelper)
- : base(logger, serverConfigurationManager, httpResultFactory)
- {
- UserManager = userManager;
- LibraryManager = libraryManager;
- IsoManager = isoManager;
- MediaEncoder = mediaEncoder;
- FileSystem = fileSystem;
- DlnaManager = dlnaManager;
- DeviceManager = deviceManager;
- MediaSourceManager = mediaSourceManager;
- JsonSerializer = jsonSerializer;
- AuthorizationContext = authorizationContext;
-
- EncodingHelper = encodingHelper;
- }
-
- ///
- /// Gets the command line arguments.
- ///
- protected abstract string GetCommandLineArguments(string outputPath, EncodingOptions encodingOptions, StreamState state, bool isEncoding);
-
- ///
- /// Gets the output file extension.
- ///
- /// The state.
- /// System.String.
- protected virtual string GetOutputFileExtension(StreamState state)
- {
- return Path.GetExtension(state.RequestedUrl);
- }
-
- ///
- /// Gets the output file path.
- ///
- private string GetOutputFilePath(StreamState state, EncodingOptions encodingOptions, string outputFileExtension)
- {
- var data = $"{state.MediaPath}-{state.UserAgent}-{state.Request.DeviceId}-{state.Request.PlaySessionId}";
-
- var filename = data.GetMD5().ToString("N", CultureInfo.InvariantCulture);
- var ext = outputFileExtension?.ToLowerInvariant();
- var folder = ServerConfigurationManager.GetTranscodePath();
-
- return EnableOutputInSubFolder
- ? Path.Combine(folder, filename, filename + ext)
- : Path.Combine(folder, filename + ext);
- }
-
- protected virtual string GetDefaultEncoderPreset()
- {
- return "superfast";
- }
-
- private async Task AcquireResources(StreamState state, CancellationTokenSource cancellationTokenSource)
- {
- if (state.VideoType == VideoType.Iso && state.IsoType.HasValue && IsoManager.CanMount(state.MediaPath))
- {
- state.IsoMount = await IsoManager.Mount(state.MediaPath, cancellationTokenSource.Token).ConfigureAwait(false);
- }
-
- if (state.MediaSource.RequiresOpening && string.IsNullOrWhiteSpace(state.Request.LiveStreamId))
- {
- var liveStreamResponse = await MediaSourceManager.OpenLiveStream(new LiveStreamRequest
- {
- OpenToken = state.MediaSource.OpenToken
- }, cancellationTokenSource.Token).ConfigureAwait(false);
-
- EncodingHelper.AttachMediaSourceInfo(state, liveStreamResponse.MediaSource, state.RequestedUrl);
-
- if (state.VideoRequest != null)
- {
- EncodingHelper.TryStreamCopy(state);
- }
- }
-
- if (state.MediaSource.BufferMs.HasValue)
- {
- await Task.Delay(state.MediaSource.BufferMs.Value, cancellationTokenSource.Token).ConfigureAwait(false);
- }
- }
-
- ///
- /// Starts the FFMPEG.
- ///
- /// The state.
- /// The output path.
- /// The cancellation token source.
- /// The working directory.
- /// Task.
- protected async Task StartFfMpeg(
- StreamState state,
- string outputPath,
- CancellationTokenSource cancellationTokenSource,
- string workingDirectory = null)
- {
- Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
-
- await AcquireResources(state, cancellationTokenSource).ConfigureAwait(false);
-
- if (state.VideoRequest != null && !EncodingHelper.IsCopyCodec(state.OutputVideoCodec))
- {
- var auth = AuthorizationContext.GetAuthorizationInfo(Request);
- if (auth.User != null && !auth.User.HasPermission(PermissionKind.EnableVideoPlaybackTranscoding))
- {
- ApiEntryPoint.Instance.OnTranscodeFailedToStart(outputPath, TranscodingJobType, state);
-
- throw new ArgumentException("User does not have access to video transcoding");
- }
- }
-
- var encodingOptions = ServerConfigurationManager.GetEncodingOptions();
-
- var process = new Process()
- {
- StartInfo = new ProcessStartInfo()
- {
- WindowStyle = ProcessWindowStyle.Hidden,
- CreateNoWindow = true,
- UseShellExecute = false,
-
- // Must consume both stdout and stderr or deadlocks may occur
- // RedirectStandardOutput = true,
- RedirectStandardError = true,
- RedirectStandardInput = true,
-
- FileName = MediaEncoder.EncoderPath,
- Arguments = GetCommandLineArguments(outputPath, encodingOptions, state, true),
- WorkingDirectory = string.IsNullOrWhiteSpace(workingDirectory) ? null : workingDirectory,
-
- ErrorDialog = false
- },
- EnableRaisingEvents = true
- };
-
- var transcodingJob = ApiEntryPoint.Instance.OnTranscodeBeginning(outputPath,
- state.Request.PlaySessionId,
- state.MediaSource.LiveStreamId,
- Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture),
- TranscodingJobType,
- process,
- state.Request.DeviceId,
- state,
- cancellationTokenSource);
-
- var commandLineLogMessage = process.StartInfo.FileName + " " + process.StartInfo.Arguments;
- Logger.LogInformation(commandLineLogMessage);
-
- var logFilePrefix = "ffmpeg-transcode";
- if (state.VideoRequest != null
- && EncodingHelper.IsCopyCodec(state.OutputVideoCodec))
- {
- logFilePrefix = EncodingHelper.IsCopyCodec(state.OutputAudioCodec)
- ? "ffmpeg-remux" : "ffmpeg-directstream";
- }
-
- var logFilePath = Path.Combine(ServerConfigurationManager.ApplicationPaths.LogDirectoryPath, logFilePrefix + "-" + Guid.NewGuid() + ".txt");
-
- // FFMpeg writes debug/error info to stderr. This is useful when debugging so let's put it in the log directory.
- Stream logStream = new FileStream(logFilePath, FileMode.Create, FileAccess.Write, FileShare.Read, IODefaults.FileStreamBufferSize, true);
-
- var commandLineLogMessageBytes = Encoding.UTF8.GetBytes(Request.AbsoluteUri + Environment.NewLine + Environment.NewLine + JsonSerializer.SerializeToString(state.MediaSource) + Environment.NewLine + Environment.NewLine + commandLineLogMessage + Environment.NewLine + Environment.NewLine);
- await logStream.WriteAsync(commandLineLogMessageBytes, 0, commandLineLogMessageBytes.Length, cancellationTokenSource.Token).ConfigureAwait(false);
-
- process.Exited += (sender, args) => OnFfMpegProcessExited(process, transcodingJob, state);
-
- try
- {
- process.Start();
- }
- catch (Exception ex)
- {
- Logger.LogError(ex, "Error starting ffmpeg");
-
- ApiEntryPoint.Instance.OnTranscodeFailedToStart(outputPath, TranscodingJobType, state);
-
- throw;
- }
-
- Logger.LogDebug("Launched ffmpeg process");
- state.TranscodingJob = transcodingJob;
-
- // Important - don't await the log task or we won't be able to kill ffmpeg when the user stops playback
- _ = new JobLogger(Logger).StartStreamingLog(state, process.StandardError.BaseStream, logStream);
-
- // Wait for the file to exist before proceeeding
- var ffmpegTargetFile = state.WaitForPath ?? outputPath;
- Logger.LogDebug("Waiting for the creation of {0}", ffmpegTargetFile);
- while (!File.Exists(ffmpegTargetFile) && !transcodingJob.HasExited)
- {
- await Task.Delay(100, cancellationTokenSource.Token).ConfigureAwait(false);
- }
-
- Logger.LogDebug("File {0} created or transcoding has finished", ffmpegTargetFile);
-
- if (state.IsInputVideo && transcodingJob.Type == TranscodingJobType.Progressive && !transcodingJob.HasExited)
- {
- await Task.Delay(1000, cancellationTokenSource.Token).ConfigureAwait(false);
-
- if (state.ReadInputAtNativeFramerate && !transcodingJob.HasExited)
- {
- await Task.Delay(1500, cancellationTokenSource.Token).ConfigureAwait(false);
- }
- }
-
- if (!transcodingJob.HasExited)
- {
- StartThrottler(state, transcodingJob);
- }
-
- Logger.LogDebug("StartFfMpeg() finished successfully");
-
- return transcodingJob;
- }
-
- private void StartThrottler(StreamState state, TranscodingJob transcodingJob)
- {
- if (EnableThrottling(state))
- {
- transcodingJob.TranscodingThrottler = state.TranscodingThrottler = new TranscodingThrottler(transcodingJob, Logger, ServerConfigurationManager, FileSystem);
- state.TranscodingThrottler.Start();
- }
- }
-
- private bool EnableThrottling(StreamState state)
- {
- var encodingOptions = ServerConfigurationManager.GetEncodingOptions();
-
- // enable throttling when NOT using hardware acceleration
- if (string.IsNullOrEmpty(encodingOptions.HardwareAccelerationType))
- {
- return state.InputProtocol == MediaProtocol.File &&
- state.RunTimeTicks.HasValue &&
- state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks &&
- state.IsInputVideo &&
- state.VideoType == VideoType.VideoFile &&
- !EncodingHelper.IsCopyCodec(state.OutputVideoCodec);
- }
-
- return false;
- }
-
- ///
- /// Processes the exited.
- ///
- /// The process.
- /// The job.
- /// The state.
- private void OnFfMpegProcessExited(Process process, TranscodingJob job, StreamState state)
- {
- if (job != null)
- {
- job.HasExited = true;
- }
-
- Logger.LogDebug("Disposing stream resources");
- state.Dispose();
-
- if (process.ExitCode == 0)
- {
- Logger.LogInformation("FFMpeg exited with code 0");
- }
- else
- {
- Logger.LogError("FFMpeg exited with code {0}", process.ExitCode);
- }
-
- process.Dispose();
- }
-
- ///
- /// Parses the parameters.
- ///
- /// The request.
- private void ParseParams(StreamRequest request)
- {
- var vals = request.Params.Split(';');
-
- var videoRequest = request as VideoStreamRequest;
-
- for (var i = 0; i < vals.Length; i++)
- {
- var val = vals[i];
-
- if (string.IsNullOrWhiteSpace(val))
- {
- continue;
- }
-
- switch (i)
- {
- case 0:
- request.DeviceProfileId = val;
- break;
- case 1:
- request.DeviceId = val;
- break;
- case 2:
- request.MediaSourceId = val;
- break;
- case 3:
- request.Static = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- break;
- case 4:
- if (videoRequest != null)
- {
- videoRequest.VideoCodec = val;
- }
-
- break;
- case 5:
- request.AudioCodec = val;
- break;
- case 6:
- if (videoRequest != null)
- {
- videoRequest.AudioStreamIndex = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 7:
- if (videoRequest != null)
- {
- videoRequest.SubtitleStreamIndex = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 8:
- if (videoRequest != null)
- {
- videoRequest.VideoBitRate = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 9:
- request.AudioBitRate = int.Parse(val, CultureInfo.InvariantCulture);
- break;
- case 10:
- request.MaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture);
- break;
- case 11:
- if (videoRequest != null)
- {
- videoRequest.MaxFramerate = float.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 12:
- if (videoRequest != null)
- {
- videoRequest.MaxWidth = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 13:
- if (videoRequest != null)
- {
- videoRequest.MaxHeight = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 14:
- request.StartTimeTicks = long.Parse(val, CultureInfo.InvariantCulture);
- break;
- case 15:
- if (videoRequest != null)
- {
- videoRequest.Level = val;
- }
-
- break;
- case 16:
- if (videoRequest != null)
- {
- videoRequest.MaxRefFrames = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 17:
- if (videoRequest != null)
- {
- videoRequest.MaxVideoBitDepth = int.Parse(val, CultureInfo.InvariantCulture);
- }
-
- break;
- case 18:
- if (videoRequest != null)
- {
- videoRequest.Profile = val;
- }
-
- break;
- case 19:
- // cabac no longer used
- break;
- case 20:
- request.PlaySessionId = val;
- break;
- case 21:
- // api_key
- break;
- case 22:
- request.LiveStreamId = val;
- break;
- case 23:
- // Duplicating ItemId because of MediaMonkey
- break;
- case 24:
- if (videoRequest != null)
- {
- videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- }
-
- break;
- case 25:
- if (!string.IsNullOrWhiteSpace(val) && videoRequest != null)
- {
- if (Enum.TryParse(val, out SubtitleDeliveryMethod method))
- {
- videoRequest.SubtitleMethod = method;
- }
- }
-
- break;
- case 26:
- request.TranscodingMaxAudioChannels = int.Parse(val, CultureInfo.InvariantCulture);
- break;
- case 27:
- if (videoRequest != null)
- {
- videoRequest.EnableSubtitlesInManifest = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- }
-
- break;
- case 28:
- request.Tag = val;
- break;
- case 29:
- if (videoRequest != null)
- {
- videoRequest.RequireAvc = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- }
-
- break;
- case 30:
- request.SubtitleCodec = val;
- break;
- case 31:
- if (videoRequest != null)
- {
- videoRequest.RequireNonAnamorphic = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- }
-
- break;
- case 32:
- if (videoRequest != null)
- {
- videoRequest.DeInterlace = string.Equals("true", val, StringComparison.OrdinalIgnoreCase);
- }
-
- break;
- case 33:
- request.TranscodeReasons = val;
- break;
- }
- }
- }
-
- ///
- /// Parses query parameters as StreamOptions.
- ///
- /// The stream request.
- private void ParseStreamOptions(StreamRequest request)
- {
- foreach (var param in Request.QueryString)
- {
- if (char.IsLower(param.Key[0]))
- {
- // This was probably not parsed initially and should be a StreamOptions
- // TODO: This should be incorporated either in the lower framework for parsing requests
- // or the generated URL should correctly serialize it
- request.StreamOptions[param.Key] = param.Value;
- }
- }
- }
-
- ///
- /// Parses the dlna headers.
- ///
- /// The request.
- private void ParseDlnaHeaders(StreamRequest request)
- {
- if (!request.StartTimeTicks.HasValue)
- {
- var timeSeek = GetHeader("TimeSeekRange.dlna.org");
-
- request.StartTimeTicks = ParseTimeSeekHeader(timeSeek);
- }
- }
-
- ///
- /// Parses the time seek header.
- ///
- private long? ParseTimeSeekHeader(string value)
- {
- if (string.IsNullOrWhiteSpace(value))
- {
- return null;
- }
-
- const string Npt = "npt=";
- if (!value.StartsWith(Npt, StringComparison.OrdinalIgnoreCase))
- {
- throw new ArgumentException("Invalid timeseek header");
- }
-
- int index = value.IndexOf('-');
- value = index == -1
- ? value.Substring(Npt.Length)
- : value.Substring(Npt.Length, index - Npt.Length);
-
- if (value.IndexOf(':') == -1)
- {
- // Parses npt times in the format of '417.33'
- if (double.TryParse(value, NumberStyles.Any, CultureInfo.InvariantCulture, out var seconds))
- {
- return TimeSpan.FromSeconds(seconds).Ticks;
- }
-
- throw new ArgumentException("Invalid timeseek header");
- }
-
- // Parses npt times in the format of '10:19:25.7'
- var tokens = value.Split(new[] { ':' }, 3);
- double secondsSum = 0;
- var timeFactor = 3600;
-
- foreach (var time in tokens)
- {
- if (double.TryParse(time, NumberStyles.Any, CultureInfo.InvariantCulture, out var digit))
- {
- secondsSum += digit * timeFactor;
- }
- else
- {
- throw new ArgumentException("Invalid timeseek header");
- }
-
- timeFactor /= 60;
- }
-
- return TimeSpan.FromSeconds(secondsSum).Ticks;
- }
-
- ///
- /// Gets the state.
- ///
- /// The request.
- /// The cancellation token.
- /// StreamState.
- protected async Task GetState(StreamRequest request, CancellationToken cancellationToken)
- {
- ParseDlnaHeaders(request);
-
- if (!string.IsNullOrWhiteSpace(request.Params))
- {
- ParseParams(request);
- }
-
- ParseStreamOptions(request);
-
- var url = Request.PathInfo;
-
- if (string.IsNullOrEmpty(request.AudioCodec))
- {
- request.AudioCodec = EncodingHelper.InferAudioCodec(url);
- }
-
- var enableDlnaHeaders = !string.IsNullOrWhiteSpace(request.Params) ||
- string.Equals(GetHeader("GetContentFeatures.DLNA.ORG"), "1", StringComparison.OrdinalIgnoreCase);
-
- var state = new StreamState(MediaSourceManager, TranscodingJobType)
- {
- Request = request,
- RequestedUrl = url,
- UserAgent = Request.UserAgent,
- EnableDlnaHeaders = enableDlnaHeaders
- };
-
- var auth = AuthorizationContext.GetAuthorizationInfo(Request);
- if (!auth.UserId.Equals(Guid.Empty))
- {
- state.User = UserManager.GetUserById(auth.UserId);
- }
-
- // if ((Request.UserAgent ?? string.Empty).IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 ||
- // (Request.UserAgent ?? string.Empty).IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1 ||
- // (Request.UserAgent ?? string.Empty).IndexOf("ipod", StringComparison.OrdinalIgnoreCase) != -1)
- //{
- // state.SegmentLength = 6;
- //}
-
- if (state.VideoRequest != null && !string.IsNullOrWhiteSpace(state.VideoRequest.VideoCodec))
- {
- state.SupportedVideoCodecs = state.VideoRequest.VideoCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();
- state.VideoRequest.VideoCodec = state.SupportedVideoCodecs.FirstOrDefault();
- }
-
- if (!string.IsNullOrWhiteSpace(request.AudioCodec))
- {
- state.SupportedAudioCodecs = request.AudioCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();
- state.Request.AudioCodec = state.SupportedAudioCodecs.FirstOrDefault(i => MediaEncoder.CanEncodeToAudioCodec(i))
- ?? state.SupportedAudioCodecs.FirstOrDefault();
- }
-
- if (!string.IsNullOrWhiteSpace(request.SubtitleCodec))
- {
- state.SupportedSubtitleCodecs = request.SubtitleCodec.Split(',').Where(i => !string.IsNullOrWhiteSpace(i)).ToArray();
- state.Request.SubtitleCodec = state.SupportedSubtitleCodecs.FirstOrDefault(i => MediaEncoder.CanEncodeToSubtitleCodec(i))
- ?? state.SupportedSubtitleCodecs.FirstOrDefault();
- }
-
- var item = LibraryManager.GetItemById(request.Id);
-
- state.IsInputVideo = string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase);
-
- // var primaryImage = item.GetImageInfo(ImageType.Primary, 0) ??
- // item.Parents.Select(i => i.GetImageInfo(ImageType.Primary, 0)).FirstOrDefault(i => i != null);
- // if (primaryImage != null)
- //{
- // state.AlbumCoverPath = primaryImage.Path;
- //}
-
- MediaSourceInfo mediaSource = null;
- if (string.IsNullOrWhiteSpace(request.LiveStreamId))
- {
- var currentJob = !string.IsNullOrWhiteSpace(request.PlaySessionId) ?
- ApiEntryPoint.Instance.GetTranscodingJob(request.PlaySessionId)
- : null;
-
- if (currentJob != null)
- {
- mediaSource = currentJob.MediaSource;
- }
-
- if (mediaSource == null)
- {
- var mediaSources = await MediaSourceManager.GetPlaybackMediaSources(LibraryManager.GetItemById(request.Id), null, false, false, cancellationToken).ConfigureAwait(false);
-
- mediaSource = string.IsNullOrEmpty(request.MediaSourceId)
- ? mediaSources[0]
- : mediaSources.Find(i => string.Equals(i.Id, request.MediaSourceId));
-
- if (mediaSource == null && Guid.Parse(request.MediaSourceId) == request.Id)
- {
- mediaSource = mediaSources[0];
- }
- }
- }
- else
- {
- var liveStreamInfo = await MediaSourceManager.GetLiveStreamWithDirectStreamProvider(request.LiveStreamId, cancellationToken).ConfigureAwait(false);
- mediaSource = liveStreamInfo.Item1;
- state.DirectStreamProvider = liveStreamInfo.Item2;
- }
-
- var videoRequest = request as VideoStreamRequest;
-
- EncodingHelper.AttachMediaSourceInfo(state, mediaSource, url);
-
- var container = Path.GetExtension(state.RequestedUrl);
-
- if (string.IsNullOrEmpty(container))
- {
- container = request.Container;
- }
-
- if (string.IsNullOrEmpty(container))
- {
- container = request.Static ?
- StreamBuilder.NormalizeMediaSourceFormatIntoSingleContainer(state.InputContainer, state.MediaPath, null, DlnaProfileType.Audio) :
- GetOutputFileExtension(state);
- }
-
- state.OutputContainer = (container ?? string.Empty).TrimStart('.');
-
- state.OutputAudioBitrate = EncodingHelper.GetAudioBitrateParam(state.Request, state.AudioStream);
-
- state.OutputAudioCodec = state.Request.AudioCodec;
-
- state.OutputAudioChannels = EncodingHelper.GetNumAudioChannelsParam(state, state.AudioStream, state.OutputAudioCodec);
-
- if (videoRequest != null)
- {
- state.OutputVideoCodec = state.VideoRequest.VideoCodec;
- state.OutputVideoBitrate = EncodingHelper.GetVideoBitrateParamValue(state.VideoRequest, state.VideoStream, state.OutputVideoCodec);
-
- if (videoRequest != null)
- {
- EncodingHelper.TryStreamCopy(state);
- }
-
- if (state.OutputVideoBitrate.HasValue && !EncodingHelper.IsCopyCodec(state.OutputVideoCodec))
- {
- var resolution = ResolutionNormalizer.Normalize(
- state.VideoStream?.BitRate,
- state.VideoStream?.Width,
- state.VideoStream?.Height,
- state.OutputVideoBitrate.Value,
- state.VideoStream?.Codec,
- state.OutputVideoCodec,
- videoRequest.MaxWidth,
- videoRequest.MaxHeight);
-
- videoRequest.MaxWidth = resolution.MaxWidth;
- videoRequest.MaxHeight = resolution.MaxHeight;
- }
- }
-
- ApplyDeviceProfileSettings(state);
-
- var ext = string.IsNullOrWhiteSpace(state.OutputContainer)
- ? GetOutputFileExtension(state)
- : ('.' + state.OutputContainer);
-
- var encodingOptions = ServerConfigurationManager.GetEncodingOptions();
-
- state.OutputFilePath = GetOutputFilePath(state, encodingOptions, ext);
-
- return state;
- }
-
- private void ApplyDeviceProfileSettings(StreamState state)
- {
- var headers = Request.Headers;
-
- if (!string.IsNullOrWhiteSpace(state.Request.DeviceProfileId))
- {
- state.DeviceProfile = DlnaManager.GetProfile(state.Request.DeviceProfileId);
- }
- else if (!string.IsNullOrWhiteSpace(state.Request.DeviceId))
- {
- var caps = DeviceManager.GetCapabilities(state.Request.DeviceId);
-
- state.DeviceProfile = caps == null ? DlnaManager.GetProfile(headers) : caps.DeviceProfile;
- }
-
- var profile = state.DeviceProfile;
-
- if (profile == null)
- {
- // Don't use settings from the default profile.
- // Only use a specific profile if it was requested.
- return;
- }
-
- var audioCodec = state.ActualOutputAudioCodec;
- var videoCodec = state.ActualOutputVideoCodec;
-
- var mediaProfile = state.VideoRequest == null ?
- profile.GetAudioMediaProfile(state.OutputContainer, audioCodec, state.OutputAudioChannels, state.OutputAudioBitrate, state.OutputAudioSampleRate, state.OutputAudioBitDepth) :
- profile.GetVideoMediaProfile(state.OutputContainer,
- audioCodec,
- videoCodec,
- state.OutputWidth,
- state.OutputHeight,
- state.TargetVideoBitDepth,
- state.OutputVideoBitrate,
- state.TargetVideoProfile,
- state.TargetVideoLevel,
- state.TargetFramerate,
- state.TargetPacketLength,
- state.TargetTimestamp,
- state.IsTargetAnamorphic,
- state.IsTargetInterlaced,
- state.TargetRefFrames,
- state.TargetVideoStreamCount,
- state.TargetAudioStreamCount,
- state.TargetVideoCodecTag,
- state.IsTargetAVC);
-
- if (mediaProfile != null)
- {
- state.MimeType = mediaProfile.MimeType;
- }
-
- if (!state.Request.Static)
- {
- var transcodingProfile = state.VideoRequest == null ?
- profile.GetAudioTranscodingProfile(state.OutputContainer, audioCodec) :
- profile.GetVideoTranscodingProfile(state.OutputContainer, audioCodec, videoCodec);
-
- if (transcodingProfile != null)
- {
- state.EstimateContentLength = transcodingProfile.EstimateContentLength;
- // state.EnableMpegtsM2TsMode = transcodingProfile.EnableMpegtsM2TsMode;
- state.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo;
-
- if (state.VideoRequest != null)
- {
- state.VideoRequest.CopyTimestamps = transcodingProfile.CopyTimestamps;
- state.VideoRequest.EnableSubtitlesInManifest = transcodingProfile.EnableSubtitlesInManifest;
- }
- }
- }
- }
-
- ///
- /// Adds the dlna headers.
- ///
- /// The state.
- /// The response headers.
- /// if set to true [is statically streamed].
- /// true if XXXX, false otherwise
- protected void AddDlnaHeaders(StreamState state, IDictionary responseHeaders, bool isStaticallyStreamed)
- {
- if (!state.EnableDlnaHeaders)
- {
- return;
- }
-
- var profile = state.DeviceProfile;
-
- var transferMode = GetHeader("transferMode.dlna.org");
- responseHeaders["transferMode.dlna.org"] = string.IsNullOrEmpty(transferMode) ? "Streaming" : transferMode;
- responseHeaders["realTimeInfo.dlna.org"] = "DLNA.ORG_TLAG=*";
-
- if (state.RunTimeTicks.HasValue)
- {
- if (string.Equals(GetHeader("getMediaInfo.sec"), "1", StringComparison.OrdinalIgnoreCase))
- {
- var ms = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalMilliseconds;
- responseHeaders["MediaInfo.sec"] = string.Format(
- CultureInfo.InvariantCulture,
- "SEC_Duration={0};",
- Convert.ToInt32(ms));
- }
-
- if (!isStaticallyStreamed && profile != null)
- {
- AddTimeSeekResponseHeaders(state, responseHeaders);
- }
- }
-
- if (profile == null)
- {
- profile = DlnaManager.GetDefaultProfile();
- }
-
- var audioCodec = state.ActualOutputAudioCodec;
-
- if (state.VideoRequest == null)
- {
- responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile).BuildAudioHeader(
- state.OutputContainer,
- audioCodec,
- state.OutputAudioBitrate,
- state.OutputAudioSampleRate,
- state.OutputAudioChannels,
- state.OutputAudioBitDepth,
- isStaticallyStreamed,
- state.RunTimeTicks,
- state.TranscodeSeekInfo);
- }
- else
- {
- var videoCodec = state.ActualOutputVideoCodec;
-
- responseHeaders["contentFeatures.dlna.org"] = new ContentFeatureBuilder(profile).BuildVideoHeader(
- state.OutputContainer,
- videoCodec,
- audioCodec,
- state.OutputWidth,
- state.OutputHeight,
- state.TargetVideoBitDepth,
- state.OutputVideoBitrate,
- state.TargetTimestamp,
- isStaticallyStreamed,
- state.RunTimeTicks,
- state.TargetVideoProfile,
- state.TargetVideoLevel,
- state.TargetFramerate,
- state.TargetPacketLength,
- state.TranscodeSeekInfo,
- state.IsTargetAnamorphic,
- state.IsTargetInterlaced,
- state.TargetRefFrames,
- state.TargetVideoStreamCount,
- state.TargetAudioStreamCount,
- state.TargetVideoCodecTag,
- state.IsTargetAVC).FirstOrDefault() ?? string.Empty;
- }
- }
-
- private void AddTimeSeekResponseHeaders(StreamState state, IDictionary responseHeaders)
- {
- var runtimeSeconds = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds.ToString(CultureInfo.InvariantCulture);
- var startSeconds = TimeSpan.FromTicks(state.Request.StartTimeTicks ?? 0).TotalSeconds.ToString(CultureInfo.InvariantCulture);
-
- responseHeaders["TimeSeekRange.dlna.org"] = string.Format(
- CultureInfo.InvariantCulture,
- "npt={0}-{1}/{1}",
- startSeconds,
- runtimeSeconds);
- responseHeaders["X-AvailableSeekRange"] = string.Format(
- CultureInfo.InvariantCulture,
- "1 npt={0}-{1}",
- startSeconds,
- runtimeSeconds);
- }
- }
-}
diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs
deleted file mode 100644
index c80e8e64f7..0000000000
--- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs
+++ /dev/null
@@ -1,344 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using MediaBrowser.Controller.Configuration;
-using MediaBrowser.Controller.Devices;
-using MediaBrowser.Controller.Dlna;
-using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.MediaEncoding;
-using MediaBrowser.Controller.Net;
-using MediaBrowser.Model.Configuration;
-using MediaBrowser.Model.IO;
-using MediaBrowser.Model.Net;
-using MediaBrowser.Model.Serialization;
-using Microsoft.Extensions.Logging;
-
-namespace MediaBrowser.Api.Playback.Hls
-{
- ///
- /// Class BaseHlsService.
- ///
- public abstract class BaseHlsService : BaseStreamingService
- {
- public BaseHlsService(
- ILogger logger,
- IServerConfigurationManager serverConfigurationManager,
- IHttpResultFactory httpResultFactory,
- IUserManager userManager,
- ILibraryManager libraryManager,
- IIsoManager isoManager,
- IMediaEncoder mediaEncoder,
- IFileSystem fileSystem,
- IDlnaManager dlnaManager,
- IDeviceManager deviceManager,
- IMediaSourceManager mediaSourceManager,
- IJsonSerializer jsonSerializer,
- IAuthorizationContext authorizationContext,
- EncodingHelper encodingHelper)
- : base(
- logger,
- serverConfigurationManager,
- httpResultFactory,
- userManager,
- libraryManager,
- isoManager,
- mediaEncoder,
- fileSystem,
- dlnaManager,
- deviceManager,
- mediaSourceManager,
- jsonSerializer,
- authorizationContext,
- encodingHelper)
- {
- }
-
- ///
- /// Gets the audio arguments.
- ///
- protected abstract string GetAudioArguments(StreamState state, EncodingOptions encodingOptions);
-
- ///
- /// Gets the video arguments.
- ///
- protected abstract string GetVideoArguments(StreamState state, EncodingOptions encodingOptions);
-
- ///
- /// Gets the segment file extension.
- ///
- protected string GetSegmentFileExtension(StreamRequest request)
- {
- var segmentContainer = request.SegmentContainer;
- if (!string.IsNullOrWhiteSpace(segmentContainer))
- {
- return "." + segmentContainer;
- }
-
- return ".ts";
- }
-
- ///
- /// Gets the type of the transcoding job.
- ///
- /// The type of the transcoding job.
- protected override TranscodingJobType TranscodingJobType => TranscodingJobType.Hls;
-
- ///
- /// Processes the request async.
- ///
- /// The request.
- /// if set to true [is live].
- /// Task{System.Object}.
- /// A video bitrate is required
- /// or
- /// An audio bitrate is required
- protected async Task