diff options
Diffstat (limited to 'MediaBrowser.Api')
38 files changed, 147 insertions, 104 deletions
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index 2177f90c2..8e6ca4401 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -37,6 +37,8 @@ namespace MediaBrowser.Api private readonly ISessionManager _sessionManager; + public readonly SemaphoreSlim TranscodingStartLock = new SemaphoreSlim(1,1); + /// <summary> /// Initializes a new instance of the <see cref="ApiEntryPoint" /> class. /// </summary> @@ -301,8 +303,9 @@ namespace MediaBrowser.Api /// </summary> /// <param name="deviceId">The device id.</param> /// <param name="deleteMode">The delete mode.</param> + /// <param name="acquireLock">if set to <c>true</c> [acquire lock].</param> /// <exception cref="System.ArgumentNullException">sourcePath</exception> - internal void KillTranscodingJobs(string deviceId, FileDeleteMode deleteMode) + internal async Task KillTranscodingJobs(string deviceId, FileDeleteMode deleteMode, bool acquireLock) { if (string.IsNullOrEmpty(deviceId)) { @@ -318,9 +321,29 @@ namespace MediaBrowser.Api jobs.AddRange(_activeTranscodingJobs.Where(i => string.Equals(deviceId, i.DeviceId, StringComparison.OrdinalIgnoreCase))); } - foreach (var job in jobs) + if (jobs.Count == 0) + { + return; + } + + if (acquireLock) { - KillTranscodingJob(job, deleteMode); + await TranscodingStartLock.WaitAsync(CancellationToken.None).ConfigureAwait(false); + } + + try + { + foreach (var job in jobs) + { + KillTranscodingJob(job, deleteMode); + } + } + finally + { + if (acquireLock) + { + TranscodingStartLock.Release(); + } } } @@ -328,10 +351,11 @@ namespace MediaBrowser.Api /// Kills the transcoding jobs. /// </summary> /// <param name="deviceId">The device identifier.</param> - /// <param name="outputPath">The output path.</param> + /// <param name="type">The type.</param> /// <param name="deleteMode">The delete mode.</param> + /// <param name="acquireLock">if set to <c>true</c> [acquire lock].</param> /// <exception cref="System.ArgumentNullException">deviceId</exception> - internal void KillTranscodingJobs(string deviceId, string outputPath, FileDeleteMode deleteMode) + internal async Task KillTranscodingJobs(string deviceId, TranscodingJobType type, FileDeleteMode deleteMode, bool acquireLock) { if (string.IsNullOrEmpty(deviceId)) { @@ -344,12 +368,32 @@ namespace MediaBrowser.Api { // This is really only needed for HLS. // Progressive streams can stop on their own reliably - jobs.AddRange(_activeTranscodingJobs.Where(i => string.Equals(deviceId, i.DeviceId, StringComparison.OrdinalIgnoreCase) && string.Equals(outputPath, i.Path, StringComparison.OrdinalIgnoreCase))); + jobs.AddRange(_activeTranscodingJobs.Where(i => string.Equals(deviceId, i.DeviceId, StringComparison.OrdinalIgnoreCase) && i.Type == type)); } - foreach (var job in jobs) + if (jobs.Count == 0) { - KillTranscodingJob(job, deleteMode); + return; + } + + if (acquireLock) + { + await TranscodingStartLock.WaitAsync(CancellationToken.None).ConfigureAwait(false); + } + + try + { + foreach (var job in jobs) + { + KillTranscodingJob(job, deleteMode); + } + } + finally + { + if (acquireLock) + { + TranscodingStartLock.Release(); + } } } diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index 8bc867a2e..21ba47bd4 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -5,6 +5,7 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; @@ -86,6 +87,7 @@ namespace MediaBrowser.Api.DefaultTheme public Guid UserId { get; set; } } + [Authenticated] public class DefaultThemeService : BaseApiService { private readonly IUserManager _userManager; diff --git a/MediaBrowser.Api/Dlna/DlnaService.cs b/MediaBrowser.Api/Dlna/DlnaService.cs index 9e6ca3aea..fec6d698a 100644 --- a/MediaBrowser.Api/Dlna/DlnaService.cs +++ b/MediaBrowser.Api/Dlna/DlnaService.cs @@ -1,4 +1,5 @@ using MediaBrowser.Controller.Dlna; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Dlna; using ServiceStack; using System.Collections.Generic; @@ -42,6 +43,7 @@ namespace MediaBrowser.Api.Dlna { } + [Authenticated] public class DlnaService : BaseApiService { private readonly IDlnaManager _dlnaManager; diff --git a/MediaBrowser.Api/ItemLookupService.cs b/MediaBrowser.Api/ItemLookupService.cs index e68aa73f6..35b1b5385 100644 --- a/MediaBrowser.Api/ItemLookupService.cs +++ b/MediaBrowser.Api/ItemLookupService.cs @@ -6,6 +6,7 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; @@ -104,6 +105,7 @@ namespace MediaBrowser.Api public string Id { get; set; } } + [Authenticated] public class ItemLookupService : BaseApiService { private readonly IProviderManager _providerManager; diff --git a/MediaBrowser.Api/ItemRefreshService.cs b/MediaBrowser.Api/ItemRefreshService.cs index 0094282c8..b95e18a0d 100644 --- a/MediaBrowser.Api/ItemRefreshService.cs +++ b/MediaBrowser.Api/ItemRefreshService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Providers; using ServiceStack; using System; @@ -30,6 +31,7 @@ namespace MediaBrowser.Api public string Id { get; set; } } + [Authenticated] public class ItemRefreshService : BaseApiService { private readonly ILibraryManager _libraryManager; diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index ad7da8e3c..db6c6ce53 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -1,11 +1,12 @@ -using System.Collections.Generic; -using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Dto; using ServiceStack; using System; +using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -19,6 +20,7 @@ namespace MediaBrowser.Api public string ItemId { get; set; } } + [Authenticated] public class ItemUpdateService : BaseApiService { private readonly ILibraryManager _libraryManager; diff --git a/MediaBrowser.Api/Library/ChapterService.cs b/MediaBrowser.Api/Library/ChapterService.cs index 72ffa3fca..6b8dd18f1 100644 --- a/MediaBrowser.Api/Library/ChapterService.cs +++ b/MediaBrowser.Api/Library/ChapterService.cs @@ -1,4 +1,5 @@ using MediaBrowser.Controller.Chapters; +using MediaBrowser.Controller.Net; using ServiceStack; using System.Linq; @@ -9,6 +10,7 @@ namespace MediaBrowser.Api.Library { } + [Authenticated] public class ChapterService : BaseApiService { private readonly IChapterManager _chapterManager; diff --git a/MediaBrowser.Api/Library/FileOrganizationService.cs b/MediaBrowser.Api/Library/FileOrganizationService.cs index 01531a7ae..adf6a522b 100644 --- a/MediaBrowser.Api/Library/FileOrganizationService.cs +++ b/MediaBrowser.Api/Library/FileOrganizationService.cs @@ -1,4 +1,5 @@ using MediaBrowser.Controller.FileOrganization; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.FileOrganization; using MediaBrowser.Model.Querying; using ServiceStack; @@ -78,6 +79,7 @@ namespace MediaBrowser.Api.Library public bool RememberCorrection { get; set; } } + [Authenticated] public class FileOrganizationService : BaseApiService { private readonly IFileOrganizationService _iFileOrganizationService; diff --git a/MediaBrowser.Api/Library/LibraryStructureService.cs b/MediaBrowser.Api/Library/LibraryStructureService.cs index 947da29fe..c3ef58768 100644 --- a/MediaBrowser.Api/Library/LibraryStructureService.cs +++ b/MediaBrowser.Api/Library/LibraryStructureService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using ServiceStack; @@ -130,36 +131,11 @@ namespace MediaBrowser.Api.Library /// <value><c>true</c> if [refresh library]; otherwise, <c>false</c>.</value> public bool RefreshLibrary { get; set; } } - - [Route("/Library/Downloaded", "POST")] - public class ReportContentDownloaded : IReturnVoid - { - [ApiMember(Name = "Path", Description = "The path being downloaded to.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] - public string Path { get; set; } - - [ApiMember(Name = "ImageUrl", Description = "Optional thumbnail image url of the content.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string ImageUrl { get; set; } - - [ApiMember(Name = "Name", Description = "The name of the content.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string Name { get; set; } - } - - [Route("/Library/Downloading", "POST")] - public class ReportContentDownloading : IReturnVoid - { - [ApiMember(Name = "Path", Description = "The path being downloaded to.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")] - public string Path { get; set; } - - [ApiMember(Name = "ImageUrl", Description = "Optional thumbnail image url of the content.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string ImageUrl { get; set; } - - [ApiMember(Name = "Name", Description = "The name of the content.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")] - public string Name { get; set; } - } /// <summary> /// Class LibraryStructureService /// </summary> + [Authenticated] public class LibraryStructureService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/Library/SubtitleService.cs b/MediaBrowser.Api/Library/SubtitleService.cs index 62c7ac7c0..4fc3e00c0 100644 --- a/MediaBrowser.Api/Library/SubtitleService.cs +++ b/MediaBrowser.Api/Library/SubtitleService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.MediaEncoding; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Subtitles; using MediaBrowser.Model.Entities; @@ -86,6 +87,7 @@ namespace MediaBrowser.Api.Library public string Id { get; set; } } + [Authenticated] public class SubtitleService : BaseApiService { private readonly ILibraryManager _libraryManager; diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index de01628f8..497f2d0a3 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -1,5 +1,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; @@ -267,6 +268,7 @@ namespace MediaBrowser.Api.LiveTv public string UserId { get; set; } } + [Authenticated] public class LiveTvService : BaseApiService { private readonly ILiveTvManager _liveTvManager; diff --git a/MediaBrowser.Api/LocalizationService.cs b/MediaBrowser.Api/LocalizationService.cs index d3c47dfa1..5696d8df7 100644 --- a/MediaBrowser.Api/LocalizationService.cs +++ b/MediaBrowser.Api/LocalizationService.cs @@ -1,4 +1,5 @@ using MediaBrowser.Controller.Localization; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Globalization; using ServiceStack; @@ -42,6 +43,7 @@ namespace MediaBrowser.Api /// <summary> /// Class CulturesService /// </summary> + [Authenticated] public class LocalizationService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/Movies/CollectionService.cs b/MediaBrowser.Api/Movies/CollectionService.cs index b9e3888fd..19e47eb85 100644 --- a/MediaBrowser.Api/Movies/CollectionService.cs +++ b/MediaBrowser.Api/Movies/CollectionService.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Collections; using MediaBrowser.Controller.Dto; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Querying; using ServiceStack; using System; @@ -45,6 +46,7 @@ namespace MediaBrowser.Api.Movies public Guid Id { get; set; } } + [Authenticated] public class CollectionService : BaseApiService { private readonly ICollectionManager _collectionManager; diff --git a/MediaBrowser.Api/Movies/MoviesService.cs b/MediaBrowser.Api/Movies/MoviesService.cs index db02ed428..f0bf22c5e 100644 --- a/MediaBrowser.Api/Movies/MoviesService.cs +++ b/MediaBrowser.Api/Movies/MoviesService.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; @@ -64,6 +65,7 @@ namespace MediaBrowser.Api.Movies /// <summary> /// Class MoviesService /// </summary> + [Authenticated] public class MoviesService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/Movies/TrailersService.cs b/MediaBrowser.Api/Movies/TrailersService.cs index 05e6a9577..b0ee6b6d5 100644 --- a/MediaBrowser.Api/Movies/TrailersService.cs +++ b/MediaBrowser.Api/Movies/TrailersService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using ServiceStack; @@ -18,6 +19,7 @@ namespace MediaBrowser.Api.Movies /// <summary> /// Class TrailersService /// </summary> + [Authenticated] public class TrailersService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/Music/AlbumsService.cs b/MediaBrowser.Api/Music/AlbumsService.cs index 0732c951a..34a933dee 100644 --- a/MediaBrowser.Api/Music/AlbumsService.cs +++ b/MediaBrowser.Api/Music/AlbumsService.cs @@ -2,10 +2,10 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using ServiceStack; using System; -using System.Collections.Generic; using System.Linq; namespace MediaBrowser.Api.Music @@ -15,6 +15,7 @@ namespace MediaBrowser.Api.Music { } + [Authenticated] public class AlbumsService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/Music/InstantMixService.cs b/MediaBrowser.Api/Music/InstantMixService.cs index f50c87f47..ff029d5b5 100644 --- a/MediaBrowser.Api/Music/InstantMixService.cs +++ b/MediaBrowser.Api/Music/InstantMixService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Querying; using ServiceStack; using System.Collections.Generic; @@ -33,6 +34,7 @@ namespace MediaBrowser.Api.Music public string Name { get; set; } } + [Authenticated] public class InstantMixService : BaseApiService { private readonly IUserManager _userManager; diff --git a/MediaBrowser.Api/PackageReviewService.cs b/MediaBrowser.Api/PackageReviewService.cs index 94ff1b62e..112a2c5ce 100644 --- a/MediaBrowser.Api/PackageReviewService.cs +++ b/MediaBrowser.Api/PackageReviewService.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Constants; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Serialization; using ServiceStack; @@ -96,6 +97,7 @@ namespace MediaBrowser.Api } + [Authenticated] public class PackageReviewService : BaseApiService { private readonly IHttpClient _httpClient; diff --git a/MediaBrowser.Api/PackageService.cs b/MediaBrowser.Api/PackageService.cs index b54b05fcf..84b42baa3 100644 --- a/MediaBrowser.Api/PackageService.cs +++ b/MediaBrowser.Api/PackageService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Updates; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Updates; using ServiceStack; using System; @@ -121,6 +122,7 @@ namespace MediaBrowser.Api /// <summary> /// Class PackageService /// </summary> + [Authenticated] public class PackageService : BaseApiService { private readonly IInstallationManager _installationManager; diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 9ff482a1a..75e13f92c 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -13,7 +13,6 @@ using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; -using MediaBrowser.Model.Library; using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.MediaInfo; using System; @@ -1955,12 +1954,6 @@ namespace MediaBrowser.Api.Playback /// <param name="videoRequest">The video request.</param> private void EnforceResolutionLimit(StreamState state, VideoStreamRequest videoRequest) { - // If enabled, allow whatever the client asks for - if (ServerConfigurationManager.Configuration.AllowVideoUpscaling) - { - return; - } - // Switch the incoming params to be ceilings rather than fixed values videoRequest.MaxWidth = videoRequest.MaxWidth ?? videoRequest.Width; videoRequest.MaxHeight = videoRequest.MaxHeight ?? videoRequest.Height; diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index fa78fa020..8a65e2b56 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -66,7 +66,6 @@ namespace MediaBrowser.Api.Playback.Hls return ProcessRequestAsync(request, isLive).Result; } - private static readonly SemaphoreSlim FfmpegStartLock = new SemaphoreSlim(1, 1); /// <summary> /// Processes the request async. /// </summary> @@ -82,6 +81,11 @@ namespace MediaBrowser.Api.Playback.Hls var state = await GetState(request, cancellationTokenSource.Token).ConfigureAwait(false); + if (isLive) + { + state.Request.StartTimeTicks = null; + } + var playlist = state.OutputFilePath; if (File.Exists(playlist)) @@ -90,7 +94,7 @@ namespace MediaBrowser.Api.Playback.Hls } else { - await FfmpegStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); + await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); try { if (File.Exists(playlist)) @@ -99,6 +103,8 @@ namespace MediaBrowser.Api.Playback.Hls } else { + await ApiEntryPoint.Instance.KillTranscodingJobs(state.Request.DeviceId, TranscodingJobType.Hls, FileDeleteMode.All, false).ConfigureAwait(false); + // If the playlist doesn't already exist, startup ffmpeg try { @@ -116,7 +122,7 @@ namespace MediaBrowser.Api.Playback.Hls } finally { - FfmpegStartLock.Release(); + ApiEntryPoint.Instance.TranscodingStartLock.Release(); } } diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 5bb610686..0af336c55 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -65,7 +65,6 @@ namespace MediaBrowser.Api.Playback.Hls return GetDynamicSegment(request).Result; } - private static readonly SemaphoreSlim FfmpegStartLock = new SemaphoreSlim(1, 1); private async Task<object> GetDynamicSegment(GetDynamicHlsVideoSegment request) { if ((request.StartTimeTicks ?? 0) > 0) @@ -90,7 +89,7 @@ namespace MediaBrowser.Api.Playback.Hls return await GetSegmentResult(playlistPath, segmentPath, index, cancellationToken).ConfigureAwait(false); } - await FfmpegStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); + await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); try { if (File.Exists(segmentPath)) @@ -107,10 +106,11 @@ namespace MediaBrowser.Api.Playback.Hls // If the playlist doesn't already exist, startup ffmpeg try { + // TODO: Delete files from other jobs, but not this one + await ApiEntryPoint.Instance.KillTranscodingJobs(state.Request.DeviceId, TranscodingJobType.Hls, FileDeleteMode.None, false).ConfigureAwait(false); + if (currentTranscodingIndex.HasValue) { - ApiEntryPoint.Instance.KillTranscodingJobs(state.Request.DeviceId, playlistPath, FileDeleteMode.None); - DeleteLastFile(playlistPath, 0); } @@ -131,7 +131,7 @@ namespace MediaBrowser.Api.Playback.Hls } finally { - FfmpegStartLock.Release(); + ApiEntryPoint.Instance.TranscodingStartLock.Release(); } Logger.Info("waiting for {0}", segmentPath); diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index f31671b1a..3848cb2de 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -74,7 +74,9 @@ namespace MediaBrowser.Api.Playback.Hls public void Delete(StopEncodingProcess request) { - ApiEntryPoint.Instance.KillTranscodingJobs(request.DeviceId, FileDeleteMode.All); + var task = ApiEntryPoint.Instance.KillTranscodingJobs(request.DeviceId, FileDeleteMode.All, true); + + Task.WaitAll(task); } /// <summary> diff --git a/MediaBrowser.Api/PluginService.cs b/MediaBrowser.Api/PluginService.cs index 31463dc3f..29cc7baf8 100644 --- a/MediaBrowser.Api/PluginService.cs +++ b/MediaBrowser.Api/PluginService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Security; using MediaBrowser.Common.Updates; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Plugins; using MediaBrowser.Model.Serialization; @@ -100,6 +101,7 @@ namespace MediaBrowser.Api /// <summary> /// Class PluginsService /// </summary> + [Authenticated] public class PluginService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs index aaf14ce71..483133c10 100644 --- a/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs +++ b/MediaBrowser.Api/ScheduledTasks/ScheduledTaskService.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Tasks; using ServiceStack; using ServiceStack.Text.Controller; @@ -78,6 +79,7 @@ namespace MediaBrowser.Api.ScheduledTasks /// <summary> /// Class ScheduledTasksService /// </summary> + [Authenticated] public class ScheduledTaskService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/SearchService.cs b/MediaBrowser.Api/SearchService.cs index e72edcc98..a6fcaf438 100644 --- a/MediaBrowser.Api/SearchService.cs +++ b/MediaBrowser.Api/SearchService.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Search; using ServiceStack; @@ -79,6 +80,7 @@ namespace MediaBrowser.Api /// <summary> /// Class SearchService /// </summary> + [Authenticated] public class SearchService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/TvShowsService.cs b/MediaBrowser.Api/TvShowsService.cs index 6776cbf17..c32e67216 100644 --- a/MediaBrowser.Api/TvShowsService.cs +++ b/MediaBrowser.Api/TvShowsService.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; @@ -175,6 +176,7 @@ namespace MediaBrowser.Api /// <summary> /// Class TvShowsService /// </summary> + [Authenticated] public class TvShowsService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/UserLibrary/ArtistsService.cs b/MediaBrowser.Api/UserLibrary/ArtistsService.cs index 13027d30b..07015ecae 100644 --- a/MediaBrowser.Api/UserLibrary/ArtistsService.cs +++ b/MediaBrowser.Api/UserLibrary/ArtistsService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; @@ -46,6 +47,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class ArtistsService /// </summary> + [Authenticated] public class ArtistsService : BaseItemsByNameService<MusicArtist> { /// <summary> diff --git a/MediaBrowser.Api/UserLibrary/GameGenresService.cs b/MediaBrowser.Api/UserLibrary/GameGenresService.cs index b1379ad5d..49e979e55 100644 --- a/MediaBrowser.Api/UserLibrary/GameGenresService.cs +++ b/MediaBrowser.Api/UserLibrary/GameGenresService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; @@ -41,6 +42,7 @@ namespace MediaBrowser.Api.UserLibrary public Guid? UserId { get; set; } } + [Authenticated] public class GameGenresService : BaseItemsByNameService<GameGenre> { public GameGenresService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IDtoService dtoService) diff --git a/MediaBrowser.Api/UserLibrary/GenresService.cs b/MediaBrowser.Api/UserLibrary/GenresService.cs index 68f0e21ed..c8c45c1bb 100644 --- a/MediaBrowser.Api/UserLibrary/GenresService.cs +++ b/MediaBrowser.Api/UserLibrary/GenresService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; @@ -46,6 +47,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class GenresService /// </summary> + [Authenticated] public class GenresService : BaseItemsByNameService<Genre> { public GenresService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IDtoService dtoService) diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index c926c16ff..ba07571bf 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -6,6 +6,7 @@ using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; @@ -246,6 +247,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class ItemsService /// </summary> + [Authenticated] public class ItemsService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/UserLibrary/MusicGenresService.cs b/MediaBrowser.Api/UserLibrary/MusicGenresService.cs index 538b16575..f50f0a0bd 100644 --- a/MediaBrowser.Api/UserLibrary/MusicGenresService.cs +++ b/MediaBrowser.Api/UserLibrary/MusicGenresService.cs @@ -2,6 +2,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; @@ -41,6 +42,7 @@ namespace MediaBrowser.Api.UserLibrary public Guid? UserId { get; set; } } + [Authenticated] public class MusicGenresService : BaseItemsByNameService<MusicGenre> { public MusicGenresService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IDtoService dtoService) diff --git a/MediaBrowser.Api/UserLibrary/PersonsService.cs b/MediaBrowser.Api/UserLibrary/PersonsService.cs index 962effded..cf9959e53 100644 --- a/MediaBrowser.Api/UserLibrary/PersonsService.cs +++ b/MediaBrowser.Api/UserLibrary/PersonsService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; @@ -51,6 +52,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class PersonsService /// </summary> + [Authenticated] public class PersonsService : BaseItemsByNameService<Person> { /// <summary> diff --git a/MediaBrowser.Api/UserLibrary/StudiosService.cs b/MediaBrowser.Api/UserLibrary/StudiosService.cs index 4c38ba0d1..2024d779b 100644 --- a/MediaBrowser.Api/UserLibrary/StudiosService.cs +++ b/MediaBrowser.Api/UserLibrary/StudiosService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; @@ -43,6 +44,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class StudiosService /// </summary> + [Authenticated] public class StudiosService : BaseItemsByNameService<Studio> { public StudiosService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IDtoService dtoService) diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index da12a9e3d..d1767e7fd 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Session; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; @@ -424,6 +425,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class UserLibraryService /// </summary> + [Authenticated] public class UserLibraryService : BaseApiService { /// <summary> diff --git a/MediaBrowser.Api/UserLibrary/YearsService.cs b/MediaBrowser.Api/UserLibrary/YearsService.cs index 4dda045c0..2b300f900 100644 --- a/MediaBrowser.Api/UserLibrary/YearsService.cs +++ b/MediaBrowser.Api/UserLibrary/YearsService.cs @@ -1,6 +1,7 @@ using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; @@ -43,6 +44,7 @@ namespace MediaBrowser.Api.UserLibrary /// <summary> /// Class YearsService /// </summary> + [Authenticated] public class YearsService : BaseItemsByNameService<Year> { public YearsService(IUserManager userManager, ILibraryManager libraryManager, IUserDataManager userDataRepository, IItemRepository itemRepo, IDtoService dtoService) diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index 764a28102..64d1fcb34 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -269,28 +269,6 @@ namespace MediaBrowser.Api /// <param name="request">The request.</param> public object Post(AuthenticateUser request) { - // No response needed. Will throw an exception on failure. - var result = AuthenticateUser(request).Result; - - return result; - } - - public object Post(AuthenticateUserByName request) - { - var user = _userManager.Users.FirstOrDefault(i => string.Equals(request.Username, i.Name, StringComparison.OrdinalIgnoreCase)); - - if (user == null) - { - throw new ArgumentException(string.Format("User {0} not found.", request.Username)); - } - - var result = AuthenticateUser(new AuthenticateUser { Id = user.Id, Password = request.Password }).Result; - - return ToOptimizedResult(result); - } - - private async Task<AuthenticationResult> AuthenticateUser(AuthenticateUser request) - { var user = _userManager.GetUserById(request.Id); if (user == null) @@ -298,38 +276,21 @@ namespace MediaBrowser.Api throw new ResourceNotFoundException("User not found"); } - var auth = AuthorizationContext.GetAuthorizationInfo(Request); - - // Login in the old way if the header is missing - if (string.IsNullOrEmpty(auth.Client) || - string.IsNullOrEmpty(auth.Device) || - string.IsNullOrEmpty(auth.DeviceId) || - string.IsNullOrEmpty(auth.Version)) + return Post(new AuthenticateUserByName { - var success = await _userManager.AuthenticateUser(user, request.Password).ConfigureAwait(false); - - if (!success) - { - // Unauthorized - throw new UnauthorizedAccessException("Invalid user or password entered."); - } - - return new AuthenticationResult - { - User = _dtoService.GetUserDto(user) - }; - } + Username = user.Name, + Password = request.Password + }); + } - var session = await _sessionMananger.AuthenticateNewSession(user, request.Password, auth.Client, auth.Version, - auth.DeviceId, auth.Device, Request.RemoteIp).ConfigureAwait(false); + public object Post(AuthenticateUserByName request) + { + var auth = AuthorizationContext.GetAuthorizationInfo(Request); - var result = new AuthenticationResult - { - User = _dtoService.GetUserDto(user), - SessionInfo = _sessionMananger.GetSessionInfoDto(session) - }; + var result = _sessionMananger.AuthenticateNewSession(request.Username, request.Password, auth.Client, auth.Version, + auth.DeviceId, auth.Device, Request.RemoteIp).Result; - return result; + return ToOptimizedResult(result); } /// <summary> @@ -353,7 +314,7 @@ namespace MediaBrowser.Api } else { - var success = _userManager.AuthenticateUser(user, request.CurrentPassword).Result; + var success = _userManager.AuthenticateUser(user.Name, request.CurrentPassword).Result; if (!success) { diff --git a/MediaBrowser.Api/VideosService.cs b/MediaBrowser.Api/VideosService.cs index f62e37f79..2407a1a39 100644 --- a/MediaBrowser.Api/VideosService.cs +++ b/MediaBrowser.Api/VideosService.cs @@ -3,6 +3,7 @@ using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Querying; using ServiceStack; @@ -41,6 +42,7 @@ namespace MediaBrowser.Api public string Ids { get; set; } } + [Authenticated] public class VideosService : BaseApiService { private readonly ILibraryManager _libraryManager; |
