From 74c1e8e12afa3b163dd1c936d8b3145817d25a6d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 5 Sep 2015 17:15:36 -0400 Subject: update bitrate detection --- MediaBrowser.Model/Configuration/ServerConfiguration.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 9f95953cf9..15770c3289 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -274,7 +274,7 @@ namespace MediaBrowser.Model.Configuration PeopleMetadataOptions = new PeopleMetadataOptions(); EnableVideoFrameAnalysis = true; - VideoFrameAnalysisLimitBytes = 600000000; + VideoFrameAnalysisLimitBytes = 800000000; InsecureApps9 = new[] { -- cgit v1.2.3 From 0d45ab8d647aebd929b638c43712cba4fa18db30 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 8 Sep 2015 17:03:31 -0400 Subject: adjust default settings --- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 2 +- MediaBrowser.Model/Configuration/ServerConfiguration.cs | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 8eaf0a78eb..f8836ada99 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -244,7 +244,7 @@ namespace MediaBrowser.MediaEncoding.Encoder if (extractKeyFrameInterval && mediaInfo.RunTimeTicks.HasValue) { - if (ConfigurationManager.Configuration.EnableVideoFrameAnalysis && mediaInfo.Size.HasValue && mediaInfo.Size.Value <= ConfigurationManager.Configuration.VideoFrameAnalysisLimitBytes) + if (ConfigurationManager.Configuration.EnableVideoFrameByFrameAnalysis && mediaInfo.Size.HasValue) { foreach (var stream in mediaInfo.MediaStreams) { diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 15770c3289..0bf73eba12 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -222,8 +222,7 @@ namespace MediaBrowser.Model.Configuration public bool DisableXmlSavers { get; set; } public bool EnableWindowsShortcuts { get; set; } - public bool EnableVideoFrameAnalysis { get; set; } - public long VideoFrameAnalysisLimitBytes { get; set; } + public bool EnableVideoFrameByFrameAnalysis { get; set; } /// /// Initializes a new instance of the class. @@ -273,8 +272,7 @@ namespace MediaBrowser.Model.Configuration PeopleMetadataOptions = new PeopleMetadataOptions(); - EnableVideoFrameAnalysis = true; - VideoFrameAnalysisLimitBytes = 800000000; + EnableVideoFrameByFrameAnalysis = false; InsecureApps9 = new[] { -- cgit v1.2.3 From a0fa1b5f8f2a67c0a3f8cafce20540cb5349f89d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Sep 2015 14:09:44 -0400 Subject: update client sync --- MediaBrowser.Api/StartupWizardService.cs | 1 + MediaBrowser.Api/UserLibrary/UserViewsService.cs | 34 ++++++++ MediaBrowser.Controller/Entities/UserView.cs | 22 +++++- .../Entities/UserViewBuilder.cs | 37 +++++++++ .../Configuration/ServerConfiguration.cs | 12 +-- .../Folders/DefaultImageProvider.cs | 14 ++-- .../Library/LibraryManager.cs | 19 +++-- .../Library/UserViewManager.cs | 90 +++++++++++++--------- .../UserViews/DynamicImageProvider.cs | 13 +++- 9 files changed, 182 insertions(+), 60 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 7353847172..962334cdc3 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -72,6 +72,7 @@ namespace MediaBrowser.Api _config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.DisableXmlSavers = true; _config.Configuration.DisableStartupScan = true; + _config.Configuration.EnableUserViews = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Api/UserLibrary/UserViewsService.cs b/MediaBrowser.Api/UserLibrary/UserViewsService.cs index a49ab85562..9d7c38d6f0 100644 --- a/MediaBrowser.Api/UserLibrary/UserViewsService.cs +++ b/MediaBrowser.Api/UserLibrary/UserViewsService.cs @@ -39,6 +39,17 @@ namespace MediaBrowser.Api.UserLibrary public string UserId { get; set; } } + [Route("/Users/{UserId}/GroupingOptions", "GET")] + public class GetGroupingOptions : IReturn> + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string UserId { get; set; } + } + public class UserViewsService : BaseApiService { private readonly IUserManager _userManager; @@ -105,6 +116,29 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(list); } + public async Task Get(GetGroupingOptions request) + { + var user = _userManager.GetUserById(request.UserId); + + var views = user.RootFolder + .GetChildren(user, true) + .OfType() + .Where(i => !UserView.IsExcludedFromGrouping(i)) + .ToList(); + + var list = views + .Select(i => new SpecialViewOption + { + Name = i.Name, + Id = i.Id.ToString("N") + + }) + .OrderBy(i => i.Name) + .ToList(); + + return ToOptimizedResult(list); + } + private bool IsEligibleForSpecialView(ICollectionFolder view) { var types = new[] { CollectionType.Movies, CollectionType.TvShows, CollectionType.Games, CollectionType.Music, CollectionType.Photos }; diff --git a/MediaBrowser.Controller/Entities/UserView.cs b/MediaBrowser.Controller/Entities/UserView.cs index 488e54cc3c..f4577435f2 100644 --- a/MediaBrowser.Controller/Entities/UserView.cs +++ b/MediaBrowser.Controller/Entities/UserView.cs @@ -82,7 +82,27 @@ namespace MediaBrowser.Controller.Entities { CollectionType.Books, CollectionType.HomeVideos, - CollectionType.Photos + CollectionType.Photos, + CollectionType.Playlists, + CollectionType.BoxSets + }; + + var collectionFolder = folder as ICollectionFolder; + + if (collectionFolder == null) + { + return false; + } + + return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty); + } + + public static bool IsUserSpecific(Folder folder) + { + var standaloneTypes = new List + { + CollectionType.Playlists, + CollectionType.BoxSets }; var collectionFolder = folder as ICollectionFolder; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index cee5dadd25..c3605fa6d0 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1808,6 +1808,13 @@ namespace MediaBrowser.Controller.Entities private IEnumerable GetMediaFolders(User user) { + if (user == null) + { + return _libraryManager.RootFolder + .Children + .OfType() + .Where(i => !UserView.IsExcludedFromGrouping(i)); + } return user.RootFolder .GetChildren(user, true, true) .OfType() @@ -1816,6 +1823,16 @@ namespace MediaBrowser.Controller.Entities private IEnumerable GetMediaFolders(User user, IEnumerable viewTypes) { + if (user == null) + { + return GetMediaFolders(null) + .Where(i => + { + var folder = i as ICollectionFolder; + + return folder != null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase); + }); + } return GetMediaFolders(user) .Where(i => { @@ -1839,9 +1856,19 @@ namespace MediaBrowser.Controller.Entities { if (parent == null || parent is UserView) { + if (user == null) + { + return GetMediaFolders(null, viewTypes).SelectMany(i => i.GetRecursiveChildren()); + } + return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user)); } + if (user == null) + { + return parent.GetRecursiveChildren(); + } + return parent.GetRecursiveChildren(user); } @@ -1849,9 +1876,19 @@ namespace MediaBrowser.Controller.Entities { if (parent == null || parent is UserView) { + if (user == null) + { + return GetMediaFolders(null, viewTypes).SelectMany(i => i.GetRecursiveChildren(filter)); + } + return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user, filter)); } + if (user == null) + { + return parent.GetRecursiveChildren(filter); + } + return parent.GetRecursiveChildren(user, filter); } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 0bf73eba12..1fcad8c950 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -44,12 +44,6 @@ namespace MediaBrowser.Model.Configuration /// true if [use HTTPS]; otherwise, false. public bool EnableHttps { get; set; } - /// - /// Gets or sets a value indicating whether [enable user specific user views]. - /// - /// true if [enable user specific user views]; otherwise, false. - public bool EnableUserSpecificUserViews { get; set; } - /// /// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// @@ -103,6 +97,12 @@ namespace MediaBrowser.Model.Configuration /// /// true if [disable startup scan]; otherwise, false. public bool DisableStartupScan { get; set; } + + /// + /// Gets or sets a value indicating whether [enable user views]. + /// + /// true if [enable user views]; otherwise, false. + public bool EnableUserViews { get; set; } /// /// Gets or sets a value indicating whether [enable library metadata sub folder]. diff --git a/MediaBrowser.Providers/Folders/DefaultImageProvider.cs b/MediaBrowser.Providers/Folders/DefaultImageProvider.cs index 13e486ae9e..1143461911 100644 --- a/MediaBrowser.Providers/Folders/DefaultImageProvider.cs +++ b/MediaBrowser.Providers/Folders/DefaultImageProvider.cs @@ -77,11 +77,11 @@ namespace MediaBrowser.Providers.Folders if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "books.png"; + //return urlPrefix + "books.png"; } if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "games.png"; + //return urlPrefix + "games.png"; } if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) { @@ -109,23 +109,23 @@ namespace MediaBrowser.Providers.Folders } if (string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "playlists.png"; + //return urlPrefix + "playlists.png"; } if (string.Equals(viewType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "homevideos.png"; + //return urlPrefix + "homevideos.png"; } if (string.Equals(viewType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "musicvideos.png"; + //return urlPrefix + "musicvideos.png"; } if (string.Equals(viewType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "generic.png"; + //return urlPrefix + "generic.png"; } if (string.IsNullOrWhiteSpace(viewType)) { - return urlPrefix + "generic.png"; + //return urlPrefix + "generic.png"; } return null; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 8d843e1ca0..8ef363b645 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1637,7 +1637,8 @@ namespace MediaBrowser.Server.Implementations.Library .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); } - private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24); + //private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24); + private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromMinutes(1); public Task GetNamedView(User user, string name, @@ -1645,12 +1646,7 @@ namespace MediaBrowser.Server.Implementations.Library string sortName, CancellationToken cancellationToken) { - if (ConfigurationManager.Configuration.EnableUserSpecificUserViews) - { - return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken); - } - - return GetNamedView(name, viewType, sortName, cancellationToken); + return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken); } public async Task GetNamedView(string name, @@ -1767,7 +1763,8 @@ namespace MediaBrowser.Server.Implementations.Library DateCreated = DateTime.UtcNow, Name = name, ViewType = viewType, - ForcedSortName = sortName + ForcedSortName = sortName, + UserId = user.Id }; if (!string.IsNullOrWhiteSpace(parentId)) @@ -1780,6 +1777,12 @@ namespace MediaBrowser.Server.Implementations.Library isNew = true; } + if (!item.UserId.HasValue) + { + item.UserId = user.Id; + await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); + } + if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase)) { item.ViewType = viewType; diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index 15648058e8..fe9e093186 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -65,22 +65,55 @@ namespace MediaBrowser.Server.Implementations.Library var list = new List(); - foreach (var folder in standaloneFolders) + if (_config.Configuration.EnableUserViews) { - var collectionFolder = folder as ICollectionFolder; - var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; - - if (plainFolderIds.Contains(folder.Id)) - { - list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, user, cancellationToken).ConfigureAwait(false)); - } - else if (!string.IsNullOrWhiteSpace(folderViewType)) + foreach (var folder in standaloneFolders) { - list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false)); + var collectionFolder = folder as ICollectionFolder; + var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; + + if (UserView.IsUserSpecific(folder)) + { + list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false)); + } + else if (plainFolderIds.Contains(folder.Id)) + { + list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, cancellationToken).ConfigureAwait(false)); + } + else if (!string.IsNullOrWhiteSpace(folderViewType)) + { + list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false)); + } + else + { + list.Add(folder); + } } - else + } + else + { + // TODO: Deprecate this whole block + foreach (var folder in standaloneFolders) { - list.Add(folder); + var collectionFolder = folder as ICollectionFolder; + var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; + + if (UserView.IsUserSpecific(folder)) + { + list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false)); + } + else if (plainFolderIds.Contains(folder.Id)) + { + list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, user, cancellationToken).ConfigureAwait(false)); + } + else if (!string.IsNullOrWhiteSpace(folderViewType)) + { + list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false)); + } + else + { + list.Add(folder); + } } } @@ -113,26 +146,7 @@ namespace MediaBrowser.Server.Implementations.Library if (parents.Count > 0) { - var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.Games); - list.Add(await _libraryManager.GetNamedView(name, CollectionType.Games, string.Empty, cancellationToken).ConfigureAwait(false)); - } - - parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) - .ToList(); - - if (parents.Count > 0) - { - var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.BoxSets); - list.Add(await _libraryManager.GetNamedView(name, CollectionType.BoxSets, string.Empty, cancellationToken).ConfigureAwait(false)); - } - - parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) - .ToList(); - - if (parents.Count > 0) - { - var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.Playlists); - list.Add(await _libraryManager.GetNamedView(name, CollectionType.Playlists, string.Empty, cancellationToken).ConfigureAwait(false)); + list.Add(await GetUserView(parents, list, CollectionType.Games, string.Empty, user, cancellationToken).ConfigureAwait(false)); } if (user.Configuration.DisplayFoldersView) @@ -200,9 +214,9 @@ namespace MediaBrowser.Server.Implementations.Library public async Task GetUserView(List parents, List currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken) { var name = _localizationManager.GetLocalizedString("ViewType" + viewType); - var enableUserSpecificViews = _config.Configuration.EnableUserSpecificUserViews; + var enableUserViews = _config.Configuration.EnableUserViews; - if (parents.Count == 1 && parents.All(i => string.Equals((enableUserSpecificViews ? i.CollectionType : i.GetViewType(user)), viewType, StringComparison.OrdinalIgnoreCase))) + if (parents.Count == 1 && parents.All(i => string.Equals((enableUserViews ? i.GetViewType(user) : i.CollectionType), viewType, StringComparison.OrdinalIgnoreCase))) { if (!string.IsNullOrWhiteSpace(parents[0].Name)) { @@ -218,7 +232,7 @@ namespace MediaBrowser.Server.Implementations.Library return await GetUserView(parentId, name, viewType, enableRichView, sortName, user, cancellationToken).ConfigureAwait(false); } - if (enableUserSpecificViews) + if (!enableUserViews) { var view = await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false); @@ -240,6 +254,12 @@ namespace MediaBrowser.Server.Implementations.Library return _libraryManager.GetNamedView(user, name, parentId.ToString("N"), viewType, sortName, null, cancellationToken); } + public Task GetUserView(Guid parentId, string name, string viewType, bool enableRichView, string sortName, CancellationToken cancellationToken) + { + viewType = enableRichView ? viewType : null; + return _libraryManager.GetNamedView(name, parentId.ToString("N"), viewType, sortName, null, cancellationToken); + } + public List>> GetLatestItems(LatestItemsQuery request) { var user = _userManager.GetUserById(request.UserId); diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 8321ab9521..2f5702983b 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -66,14 +66,14 @@ namespace MediaBrowser.Server.Implementations.UserViews } var isUsingCollectionStrip = IsUsingCollectionStrip(view); - var recursive = isUsingCollectionStrip && !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.ViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase); + var recursive = isUsingCollectionStrip && !new[] { CollectionType.Channels, CollectionType.BoxSets, CollectionType.Playlists }.Contains(view.ViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase); var result = await view.GetItems(new InternalItemsQuery { User = (view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null), CollapseBoxSetItems = false, Recursive = recursive, - ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" } + ExcludeItemTypes = new[] { "UserView", "CollectionFolder" } }).ConfigureAwait(false); @@ -147,7 +147,14 @@ namespace MediaBrowser.Server.Implementations.UserViews { CollectionType.Movies, CollectionType.TvShows, - CollectionType.Music + CollectionType.Music, + CollectionType.Games, + CollectionType.Books, + CollectionType.MusicVideos, + CollectionType.HomeVideos, + CollectionType.BoxSets, + CollectionType.Playlists, + CollectionType.Photos }; return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty); -- cgit v1.2.3 From a2c371ec60f8da649887f72d9ee38a8f3a85365a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Sep 2015 23:55:26 -0400 Subject: rework collection editor --- MediaBrowser.Api/Dlna/DlnaServerService.cs | 1 - .../Serialization/JsonSerializer.cs | 4 +- .../Channels/IChannelFactory.cs | 14 - .../Channels/IChannelManager.cs | 2 +- .../MediaBrowser.Controller.csproj | 1 - MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs | 642 ++++++++++----------- MediaBrowser.Dlna/Main/DlnaEntryPoint.cs | 2 - MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 3 - .../Configuration/ServerConfiguration.cs | 4 - MediaBrowser.Model/Dlna/ConditionProcessor.cs | 1 - MediaBrowser.Providers/Omdb/OmdbImageProvider.cs | 3 +- .../Channels/ChannelManager.cs | 21 +- .../HttpServer/Security/AuthorizationContext.cs | 41 -- .../Sync/SyncManager.cs | 2 - .../ApplicationHost.cs | 2 +- .../MediaBrowser.WebDashboard.csproj | 3 - 16 files changed, 329 insertions(+), 417 deletions(-) delete mode 100644 MediaBrowser.Controller/Channels/IChannelFactory.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/Dlna/DlnaServerService.cs b/MediaBrowser.Api/Dlna/DlnaServerService.cs index 4f5e2ab259..4e7b1a7d58 100644 --- a/MediaBrowser.Api/Dlna/DlnaServerService.cs +++ b/MediaBrowser.Api/Dlna/DlnaServerService.cs @@ -108,7 +108,6 @@ namespace MediaBrowser.Api.Dlna private readonly IConnectionManager _connectionManager; private readonly IMediaReceiverRegistrar _mediaReceiverRegistrar; - // TODO: Add utf-8 private const string XMLContentType = "text/xml; charset=UTF-8"; public DlnaServerService(IDlnaManager dlnaManager, IContentDirectory contentDirectory, IConnectionManager connectionManager, IMediaReceiverRegistrar mediaReceiverRegistrar) diff --git a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs index 2c93f05497..a758a0c1e1 100644 --- a/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs +++ b/MediaBrowser.Common.Implementations/Serialization/JsonSerializer.cs @@ -1,7 +1,7 @@ -using MediaBrowser.Model.Serialization; +using MediaBrowser.Common.IO; +using MediaBrowser.Model.Serialization; using System; using System.IO; -using MediaBrowser.Common.IO; namespace MediaBrowser.Common.Implementations.Serialization { diff --git a/MediaBrowser.Controller/Channels/IChannelFactory.cs b/MediaBrowser.Controller/Channels/IChannelFactory.cs deleted file mode 100644 index c7ed925866..0000000000 --- a/MediaBrowser.Controller/Channels/IChannelFactory.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; - -namespace MediaBrowser.Controller.Channels -{ - public interface IChannelFactory - { - IEnumerable GetChannels(); - } - - public interface IFactoryChannel - { - - } -} \ No newline at end of file diff --git a/MediaBrowser.Controller/Channels/IChannelManager.cs b/MediaBrowser.Controller/Channels/IChannelManager.cs index 8d3e0f5962..fec550df8b 100644 --- a/MediaBrowser.Controller/Channels/IChannelManager.cs +++ b/MediaBrowser.Controller/Channels/IChannelManager.cs @@ -16,7 +16,7 @@ namespace MediaBrowser.Controller.Channels /// /// The channels. /// The factories. - void AddParts(IEnumerable channels, IEnumerable factories); + void AddParts(IEnumerable channels); /// /// Gets the channel download path. diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index dffb29f935..ea6e98ea62 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -77,7 +77,6 @@ - diff --git a/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs b/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs index f26ceff905..315313c041 100644 --- a/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs +++ b/MediaBrowser.Dlna/Channels/DlnaChannelFactory.cs @@ -18,325 +18,325 @@ using System.Threading.Tasks; namespace MediaBrowser.Dlna.Channels { - public class DlnaChannelFactory : IChannelFactory, IDisposable - { - private readonly IServerConfigurationManager _config; - private readonly ILogger _logger; - private readonly IHttpClient _httpClient; - - private readonly IDeviceDiscovery _deviceDiscovery; - - private readonly SemaphoreSlim _syncLock = new SemaphoreSlim(1, 1); - private List _servers = new List(); - - public static DlnaChannelFactory Instance; - - private Func> _localServersLookup; - - public DlnaChannelFactory(IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IDeviceDiscovery deviceDiscovery) - { - _config = config; - _httpClient = httpClient; - _logger = logger; - _deviceDiscovery = deviceDiscovery; - Instance = this; - } - - internal void Start(Func> localServersLookup) - { - _localServersLookup = localServersLookup; - - //deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered; - _deviceDiscovery.DeviceLeft += deviceDiscovery_DeviceLeft; - } - - async void deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e) - { - string usn; - if (!e.Headers.TryGetValue("USN", out usn)) usn = string.Empty; - - string nt; - if (!e.Headers.TryGetValue("NT", out nt)) nt = string.Empty; - - string location; - if (!e.Headers.TryGetValue("Location", out location)) location = string.Empty; - - if (!IsValid(nt, usn)) - { - return; - } - - if (_localServersLookup != null) - { - if (_localServersLookup().Any(i => usn.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1)) - { - // Don't add the local Dlna server to this - return; - } - } - - if (GetExistingServers(usn).Any()) - { - return; - } - - await _syncLock.WaitAsync().ConfigureAwait(false); - - try - { - if (GetExistingServers(usn).Any()) - { - return; - } - - var device = await Device.CreateuPnpDeviceAsync(new Uri(location), _httpClient, _config, _logger) - .ConfigureAwait(false); - - if (!_servers.Any(i => string.Equals(i.Properties.UUID, device.Properties.UUID, StringComparison.OrdinalIgnoreCase))) - { - _servers.Add(device); - } - } - catch (Exception ex) - { - - } - finally - { - _syncLock.Release(); - } - } - - async void deviceDiscovery_DeviceLeft(object sender, SsdpMessageEventArgs e) - { - string usn; - if (!e.Headers.TryGetValue("USN", out usn)) usn = String.Empty; - - string nt; - if (!e.Headers.TryGetValue("NT", out nt)) nt = String.Empty; - - if (!IsValid(nt, usn)) - { - return; - } - - if (!GetExistingServers(usn).Any()) - { - return; - } - - await _syncLock.WaitAsync().ConfigureAwait(false); - - try - { - var list = _servers.ToList(); - - foreach (var device in GetExistingServers(usn).ToList()) - { - list.Remove(device); - } - - _servers = list; - } - finally - { - _syncLock.Release(); - } - } - - private bool IsValid(string nt, string usn) - { - // It has to report that it's a media renderer - if (usn.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 && - nt.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 && - usn.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1 && - nt.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1) - { - return false; - } - - return true; - } - - private IEnumerable GetExistingServers(string usn) - { - return _servers - .Where(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1); - } - - public IEnumerable GetChannels() - { - //if (_servers.Count > 0) - //{ - // var service = _servers[0].Properties.Services - // .FirstOrDefault(i => string.Equals(i.ServiceType, "urn:schemas-upnp-org:service:ContentDirectory:1", StringComparison.OrdinalIgnoreCase)); - - // var controlUrl = service == null ? null : (_servers[0].Properties.BaseUrl.TrimEnd('/') + "/" + service.ControlUrl.TrimStart('/')); - - // if (!string.IsNullOrEmpty(controlUrl)) - // { - // return new List - // { - // new ServerChannel(_servers.ToList(), _httpClient, _logger, controlUrl) - // }; - // } - //} - - return new List(); - } - - public void Dispose() - { - if (_deviceDiscovery != null) - { - _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered; - _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft; - } - } - } - - public class ServerChannel : IChannel, IFactoryChannel - { - private readonly IHttpClient _httpClient; - private readonly ILogger _logger; - public string ControlUrl { get; set; } - public List Servers { get; set; } - - public ServerChannel(IHttpClient httpClient, ILogger logger) - { - _httpClient = httpClient; - _logger = logger; - Servers = new List(); - } - - public string Name - { - get { return "Devices"; } - } - - public string Description - { - get { return string.Empty; } - } - - public string DataVersion - { - get { return DateTime.UtcNow.Ticks.ToString(); } - } - - public string HomePageUrl - { - get { return string.Empty; } - } - - public ChannelParentalRating ParentalRating - { - get { return ChannelParentalRating.GeneralAudience; } - } - - public InternalChannelFeatures GetChannelFeatures() - { - return new InternalChannelFeatures - { - ContentTypes = new List - { - ChannelMediaContentType.Song, - ChannelMediaContentType.Clip - }, - - MediaTypes = new List - { - ChannelMediaType.Audio, - ChannelMediaType.Video, - ChannelMediaType.Photo - } - }; - } - - public bool IsEnabledFor(string userId) - { - return true; - } - - public async Task GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken) - { - IEnumerable items; - - if (string.IsNullOrWhiteSpace(query.FolderId)) - { - items = Servers.Select(i => new ChannelItemInfo - { - FolderType = ChannelFolderType.Container, - Id = GetServerId(i), - Name = i.Properties.Name, - Overview = i.Properties.ModelDescription, - Type = ChannelItemType.Folder - }); - } - else - { - var idParts = query.FolderId.Split('|'); - var folderId = idParts.Length == 2 ? idParts[1] : null; - - var result = await new ContentDirectoryBrowser(_httpClient, _logger).Browse(new ContentDirectoryBrowseRequest - { - Limit = query.Limit, - StartIndex = query.StartIndex, - ParentId = folderId, - ContentDirectoryUrl = ControlUrl - - }, cancellationToken).ConfigureAwait(false); - - items = result.Items.ToList(); - } - - var list = items.ToList(); - var count = list.Count; - - list = ApplyPaging(list, query).ToList(); - - return new ChannelItemResult - { - Items = list, - TotalRecordCount = count - }; - } - - private string GetServerId(Device device) - { - return device.Properties.UUID.GetMD5().ToString("N"); - } - - private IEnumerable ApplyPaging(IEnumerable items, InternalChannelItemQuery query) - { - if (query.StartIndex.HasValue) - { - items = items.Skip(query.StartIndex.Value); - } - - if (query.Limit.HasValue) - { - items = items.Take(query.Limit.Value); - } - - return items; - } - - public Task GetChannelImage(ImageType type, CancellationToken cancellationToken) - { - // TODO: Implement - return Task.FromResult(new DynamicImageResponse - { - HasImage = false - }); - } - - public IEnumerable GetSupportedChannelImages() - { - return new List - { - ImageType.Primary - }; - } - } + //public class DlnaChannelFactory : IChannelFactory, IDisposable + //{ + // private readonly IServerConfigurationManager _config; + // private readonly ILogger _logger; + // private readonly IHttpClient _httpClient; + + // private readonly IDeviceDiscovery _deviceDiscovery; + + // private readonly SemaphoreSlim _syncLock = new SemaphoreSlim(1, 1); + // private List _servers = new List(); + + // public static DlnaChannelFactory Instance; + + // private Func> _localServersLookup; + + // public DlnaChannelFactory(IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IDeviceDiscovery deviceDiscovery) + // { + // _config = config; + // _httpClient = httpClient; + // _logger = logger; + // _deviceDiscovery = deviceDiscovery; + // Instance = this; + // } + + // internal void Start(Func> localServersLookup) + // { + // _localServersLookup = localServersLookup; + + // //deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered; + // _deviceDiscovery.DeviceLeft += deviceDiscovery_DeviceLeft; + // } + + // async void deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e) + // { + // string usn; + // if (!e.Headers.TryGetValue("USN", out usn)) usn = string.Empty; + + // string nt; + // if (!e.Headers.TryGetValue("NT", out nt)) nt = string.Empty; + + // string location; + // if (!e.Headers.TryGetValue("Location", out location)) location = string.Empty; + + // if (!IsValid(nt, usn)) + // { + // return; + // } + + // if (_localServersLookup != null) + // { + // if (_localServersLookup().Any(i => usn.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1)) + // { + // // Don't add the local Dlna server to this + // return; + // } + // } + + // if (GetExistingServers(usn).Any()) + // { + // return; + // } + + // await _syncLock.WaitAsync().ConfigureAwait(false); + + // try + // { + // if (GetExistingServers(usn).Any()) + // { + // return; + // } + + // var device = await Device.CreateuPnpDeviceAsync(new Uri(location), _httpClient, _config, _logger) + // .ConfigureAwait(false); + + // if (!_servers.Any(i => string.Equals(i.Properties.UUID, device.Properties.UUID, StringComparison.OrdinalIgnoreCase))) + // { + // _servers.Add(device); + // } + // } + // catch (Exception ex) + // { + + // } + // finally + // { + // _syncLock.Release(); + // } + // } + + // async void deviceDiscovery_DeviceLeft(object sender, SsdpMessageEventArgs e) + // { + // string usn; + // if (!e.Headers.TryGetValue("USN", out usn)) usn = String.Empty; + + // string nt; + // if (!e.Headers.TryGetValue("NT", out nt)) nt = String.Empty; + + // if (!IsValid(nt, usn)) + // { + // return; + // } + + // if (!GetExistingServers(usn).Any()) + // { + // return; + // } + + // await _syncLock.WaitAsync().ConfigureAwait(false); + + // try + // { + // var list = _servers.ToList(); + + // foreach (var device in GetExistingServers(usn).ToList()) + // { + // list.Remove(device); + // } + + // _servers = list; + // } + // finally + // { + // _syncLock.Release(); + // } + // } + + // private bool IsValid(string nt, string usn) + // { + // // It has to report that it's a media renderer + // if (usn.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 && + // nt.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 && + // usn.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1 && + // nt.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1) + // { + // return false; + // } + + // return true; + // } + + // private IEnumerable GetExistingServers(string usn) + // { + // return _servers + // .Where(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1); + // } + + // public IEnumerable GetChannels() + // { + // //if (_servers.Count > 0) + // //{ + // // var service = _servers[0].Properties.Services + // // .FirstOrDefault(i => string.Equals(i.ServiceType, "urn:schemas-upnp-org:service:ContentDirectory:1", StringComparison.OrdinalIgnoreCase)); + + // // var controlUrl = service == null ? null : (_servers[0].Properties.BaseUrl.TrimEnd('/') + "/" + service.ControlUrl.TrimStart('/')); + + // // if (!string.IsNullOrEmpty(controlUrl)) + // // { + // // return new List + // // { + // // new ServerChannel(_servers.ToList(), _httpClient, _logger, controlUrl) + // // }; + // // } + // //} + + // return new List(); + // } + + // public void Dispose() + // { + // if (_deviceDiscovery != null) + // { + // _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered; + // _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft; + // } + // } + //} + + //public class ServerChannel : IChannel, IFactoryChannel + //{ + // private readonly IHttpClient _httpClient; + // private readonly ILogger _logger; + // public string ControlUrl { get; set; } + // public List Servers { get; set; } + + // public ServerChannel(IHttpClient httpClient, ILogger logger) + // { + // _httpClient = httpClient; + // _logger = logger; + // Servers = new List(); + // } + + // public string Name + // { + // get { return "Devices"; } + // } + + // public string Description + // { + // get { return string.Empty; } + // } + + // public string DataVersion + // { + // get { return DateTime.UtcNow.Ticks.ToString(); } + // } + + // public string HomePageUrl + // { + // get { return string.Empty; } + // } + + // public ChannelParentalRating ParentalRating + // { + // get { return ChannelParentalRating.GeneralAudience; } + // } + + // public InternalChannelFeatures GetChannelFeatures() + // { + // return new InternalChannelFeatures + // { + // ContentTypes = new List + // { + // ChannelMediaContentType.Song, + // ChannelMediaContentType.Clip + // }, + + // MediaTypes = new List + // { + // ChannelMediaType.Audio, + // ChannelMediaType.Video, + // ChannelMediaType.Photo + // } + // }; + // } + + // public bool IsEnabledFor(string userId) + // { + // return true; + // } + + // public async Task GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken) + // { + // IEnumerable items; + + // if (string.IsNullOrWhiteSpace(query.FolderId)) + // { + // items = Servers.Select(i => new ChannelItemInfo + // { + // FolderType = ChannelFolderType.Container, + // Id = GetServerId(i), + // Name = i.Properties.Name, + // Overview = i.Properties.ModelDescription, + // Type = ChannelItemType.Folder + // }); + // } + // else + // { + // var idParts = query.FolderId.Split('|'); + // var folderId = idParts.Length == 2 ? idParts[1] : null; + + // var result = await new ContentDirectoryBrowser(_httpClient, _logger).Browse(new ContentDirectoryBrowseRequest + // { + // Limit = query.Limit, + // StartIndex = query.StartIndex, + // ParentId = folderId, + // ContentDirectoryUrl = ControlUrl + + // }, cancellationToken).ConfigureAwait(false); + + // items = result.Items.ToList(); + // } + + // var list = items.ToList(); + // var count = list.Count; + + // list = ApplyPaging(list, query).ToList(); + + // return new ChannelItemResult + // { + // Items = list, + // TotalRecordCount = count + // }; + // } + + // private string GetServerId(Device device) + // { + // return device.Properties.UUID.GetMD5().ToString("N"); + // } + + // private IEnumerable ApplyPaging(IEnumerable items, InternalChannelItemQuery query) + // { + // if (query.StartIndex.HasValue) + // { + // items = items.Skip(query.StartIndex.Value); + // } + + // if (query.Limit.HasValue) + // { + // items = items.Take(query.Limit.Value); + // } + + // return items; + // } + + // public Task GetChannelImage(ImageType type, CancellationToken cancellationToken) + // { + // // TODO: Implement + // return Task.FromResult(new DynamicImageResponse + // { + // HasImage = false + // }); + // } + + // public IEnumerable GetSupportedChannelImages() + // { + // return new List + // { + // ImageType.Primary + // }; + // } + //} } diff --git a/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs b/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs index bdb778cab7..8c45757e76 100644 --- a/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs +++ b/MediaBrowser.Dlna/Main/DlnaEntryPoint.cs @@ -81,8 +81,6 @@ namespace MediaBrowser.Dlna.Main ReloadComponents(); _config.NamedConfigurationUpdated += _config_NamedConfigurationUpdated; - - DlnaChannelFactory.Instance.Start(() => _registeredServerIds); } void _config_NamedConfigurationUpdated(object sender, ConfigurationUpdateEventArgs e) diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index e2543c8419..01be4924ac 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -483,9 +483,6 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - // TODO: Output in webp for smaller sizes - // -f image2 -f webp - // Use ffmpeg to sample 100 (we can drop this if required using thumbnail=50 for 50 frames) frames and pick the best thumbnail. Have a fall back just in case. var args = useIFrame ? string.Format("-i {0} -threads 1 -v quiet -vframes 1 -vf \"{2},thumbnail=30\" -f image2 \"{1}\"", inputPath, "-", vf) : string.Format("-i {0} -threads 1 -v quiet -vframes 1 -vf \"{2}\" -f image2 \"{1}\"", inputPath, "-", vf); diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 1fcad8c950..b137a8502e 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -276,11 +276,7 @@ namespace MediaBrowser.Model.Configuration InsecureApps9 = new[] { - "Chromecast", - "iOS", "Unknown app", - "iPad", - "iPhone", "Windows Phone" }; diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index 793036f403..fd3df9c769 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -28,7 +28,6 @@ namespace MediaBrowser.Model.Dlna // TODO: Implement return true; case ProfileConditionValue.Has64BitOffsets: - // TODO: Implement return true; case ProfileConditionValue.IsAnamorphic: return IsConditionSatisfied(condition, isAnamorphic); diff --git a/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs b/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs index 7f804f9df4..3f25f0f930 100644 --- a/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbImageProvider.cs @@ -79,8 +79,7 @@ namespace MediaBrowser.Providers.Omdb public bool Supports(IHasImages item) { - // Save the http requests since we know it's not currently supported - // TODO: Check again periodically + // We'll hammer Omdb if we enable this if (item is Person) { return false; diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index 9edfc0c35a..d7209fbdf9 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -31,7 +31,6 @@ namespace MediaBrowser.Server.Implementations.Channels public class ChannelManager : IChannelManager, IDisposable { private IChannel[] _channels; - private IChannelFactory[] _factories; private readonly IUserManager _userManager; private readonly IUserDataManager _userDataManager; @@ -76,10 +75,9 @@ namespace MediaBrowser.Server.Implementations.Channels } } - public void AddParts(IEnumerable channels, IEnumerable factories) + public void AddParts(IEnumerable channels) { - _channels = channels.Where(i => !(i is IFactoryChannel)).ToArray(); - _factories = factories.ToArray(); + _channels = channels.ToArray(); } public string ChannelDownloadPath @@ -99,20 +97,7 @@ namespace MediaBrowser.Server.Implementations.Channels private IEnumerable GetAllChannels() { - return _factories - .SelectMany(i => - { - try - { - return i.GetChannels().ToList(); - } - catch (Exception ex) - { - _logger.ErrorException("Error getting channel list", ex); - return new List(); - } - }) - .Concat(_channels) + return _channels .OrderBy(i => i.Name); } diff --git a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs index 80892b96c2..ae5ce796ea 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/Security/AuthorizationContext.cs @@ -69,47 +69,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer.Security token = httpReq.QueryString["api_key"]; } - // Hack until iOS is updated - // TODO: Remove - if (string.IsNullOrWhiteSpace(client)) - { - var userAgent = httpReq.Headers["User-Agent"] ?? string.Empty; - - if (userAgent.IndexOf("mediabrowserios", StringComparison.OrdinalIgnoreCase) != -1 || - userAgent.IndexOf("iphone", StringComparison.OrdinalIgnoreCase) != -1 || - userAgent.IndexOf("ipad", StringComparison.OrdinalIgnoreCase) != -1) - { - client = "iOS"; - } - - else if (userAgent.IndexOf("crKey", StringComparison.OrdinalIgnoreCase) != -1) - { - client = "Chromecast"; - } - } - - // Hack until iOS is updated - // TODO: Remove - if (string.IsNullOrWhiteSpace(device)) - { - var userAgent = httpReq.Headers["User-Agent"] ?? string.Empty; - - if (userAgent.IndexOf("iPhone", StringComparison.OrdinalIgnoreCase) != -1) - { - device = "iPhone"; - } - - else if (userAgent.IndexOf("iPad", StringComparison.OrdinalIgnoreCase) != -1) - { - device = "iPad"; - } - - else if (userAgent.IndexOf("crKey", StringComparison.OrdinalIgnoreCase) != -1) - { - device = "Chromecast"; - } - } - var info = new AuthorizationInfo { Client = client, diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index 428ba5e204..15d1968777 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -962,8 +962,6 @@ namespace MediaBrowser.Server.Implementations.Sync return false; } - // TODO: Make sure it hasn't been deleted - return true; } diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index ad2cd96b64..b55e727d65 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -790,7 +790,7 @@ namespace MediaBrowser.Server.Startup.Common SessionManager.AddParts(GetExports()); - ChannelManager.AddParts(GetExports(), GetExports()); + ChannelManager.AddParts(GetExports()); MediaSourceManager.AddParts(GetExports()); diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index ccac9d8d87..36c21efdec 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -1005,9 +1005,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest -- cgit v1.2.3 From 5340bfe8da879ba2503cb675e6724ce33b754ae3 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 17 Sep 2015 23:08:45 -0400 Subject: added setting for intel qsv hardware decoding --- MediaBrowser.Api/Playback/BaseStreamingService.cs | 51 ++++++++++--- .../MediaEncoding/IMediaEncoder.cs | 7 ++ MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 16 ++++ .../Configuration/EncodingOptions.cs | 3 +- .../ApplicationHost.cs | 14 +++- .../FFMpeg/FFMpegDownloadInfo.cs | 20 ++--- .../FFMpeg/FFmpegValidator.cs | 86 +++++++++++----------- 7 files changed, 130 insertions(+), 67 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index a524490783..86f06213c4 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -290,13 +290,6 @@ namespace MediaBrowser.Api.Playback { get { - var lib = ApiEntryPoint.Instance.GetEncodingOptions().H264Encoder; - - if (!string.IsNullOrWhiteSpace(lib)) - { - return lib; - } - return "libx264"; } } @@ -809,6 +802,46 @@ namespace MediaBrowser.Api.Playback return "copy"; } + /// + /// Gets the name of the output video codec + /// + /// The state. + /// System.String. + protected string GetVideoDecoder(StreamState state) + { + if (string.Equals(ApiEntryPoint.Instance.GetEncodingOptions().HardwareVideoDecoder, "qsv", StringComparison.OrdinalIgnoreCase)) + { + if (state.VideoStream != null && !string.IsNullOrWhiteSpace(state.VideoStream.Codec)) + { + switch (state.MediaSource.VideoStream.Codec.ToLower()) + { + case "avc": + case "h264": + if (MediaEncoder.SupportsDecoder("h264_qsv")) + { + return "-c:v h264_qsv "; + } + break; + case "mpeg2video": + if (MediaEncoder.SupportsDecoder("mpeg2_qsv")) + { + return "-c:v mpeg2_qsv "; + } + break; + case "vc1": + if (MediaEncoder.SupportsDecoder("vc1_qsv")) + { + return "-c:v vc1_qsv "; + } + break; + } + } + } + + // leave blank so ffmpeg will decide + return string.Empty; + } + /// /// Gets the input argument. /// @@ -816,7 +849,7 @@ namespace MediaBrowser.Api.Playback /// System.String. protected string GetInputArgument(StreamState state) { - var arg = "-i " + GetInputPathArgument(state); + var arg = string.Format("{1}-i {0}", GetInputPathArgument(state), GetVideoDecoder(state)); if (state.SubtitleStream != null) { @@ -826,7 +859,7 @@ namespace MediaBrowser.Api.Playback } } - return arg; + return arg.Trim(); } private string GetInputPathArgument(StreamState state) diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index 23285b612a..427af6f6d7 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -24,6 +24,13 @@ namespace MediaBrowser.Controller.MediaEncoding /// The version. string Version { get; } + /// + /// Supportses the decoder. + /// + /// The decoder. + /// true if XXXX, false otherwise. + bool SupportsDecoder(string decoder); + /// /// Extracts the audio image. /// diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 01be4924ac..d317acc594 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -97,6 +97,22 @@ namespace MediaBrowser.MediaEncoding.Encoder FFMpegPath = ffMpegPath; } + public void SetAvailableEncoders(List list) + { + + } + + private List _decoders = new List(); + public void SetAvailableDecoders(List list) + { + _decoders = list.ToList(); + } + + public bool SupportsDecoder(string decoder) + { + return _decoders.Contains(decoder, StringComparer.OrdinalIgnoreCase); + } + /// /// Gets the encoder path. /// diff --git a/MediaBrowser.Model/Configuration/EncodingOptions.cs b/MediaBrowser.Model/Configuration/EncodingOptions.cs index 6d3894f029..77b894eb8a 100644 --- a/MediaBrowser.Model/Configuration/EncodingOptions.cs +++ b/MediaBrowser.Model/Configuration/EncodingOptions.cs @@ -6,14 +6,13 @@ namespace MediaBrowser.Model.Configuration public int EncodingThreadCount { get; set; } public string TranscodingTempPath { get; set; } public double DownMixAudioBoost { get; set; } - public string H264Encoder { get; set; } public bool EnableDebugLogging { get; set; } public bool EnableThrottling { get; set; } public int ThrottleThresholdInSeconds { get; set; } + public string HardwareVideoDecoder { get; set; } public EncodingOptions() { - H264Encoder = "libx264"; DownMixAudioBoost = 2; EnableThrottling = true; ThrottleThresholdInSeconds = 120; diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index b55e727d65..c38c818664 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -595,9 +595,7 @@ namespace MediaBrowser.Server.Startup.Common var info = await new FFMpegDownloader(Logger, ApplicationPaths, HttpClient, ZipClient, FileSystemManager, NativeApp.Environment) .GetFFMpegInfo(NativeApp.Environment, _startupOptions, progress).ConfigureAwait(false); - new FFmpegValidator(Logger, ApplicationPaths, FileSystemManager).Validate(info); - - MediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), + var mediaEncoder = new MediaEncoder(LogManager.GetLogger("MediaEncoder"), JsonSerializer, info.EncoderPath, info.ProbePath, @@ -611,7 +609,17 @@ namespace MediaBrowser.Server.Startup.Common SessionManager, () => SubtitleEncoder, () => MediaSourceManager); + + MediaEncoder = mediaEncoder; RegisterSingleInstance(MediaEncoder); + + Task.Run(() => + { + var result = new FFmpegValidator(Logger, ApplicationPaths, FileSystemManager).Validate(info); + + mediaEncoder.SetAvailableDecoders(result.Item1); + mediaEncoder.SetAvailableEncoders(result.Item2); + }); } /// diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs index 2910479ef8..c4fe7e43b5 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFMpegDownloadInfo.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg case OperatingSystem.Linux: info.ArchiveType = "7z"; - info.Version = "20150717"; + info.Version = "20150917"; break; case OperatingSystem.Osx: @@ -42,7 +42,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg switch (environment.SystemArchitecture) { case Architecture.X86_X64: - info.Version = "20150827"; + info.Version = "20150917"; break; case Architecture.X86: info.Version = "20150110"; @@ -54,7 +54,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg info.FFMpegFilename = "ffmpeg.exe"; info.FFProbeFilename = "ffprobe.exe"; - info.Version = "20150717"; + info.Version = "20150916"; info.ArchiveType = "7z"; switch (environment.SystemArchitecture) @@ -83,14 +83,14 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg case Architecture.X86_X64: return new[] { - "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20150717-git-8250943-win64-static.7z", - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150901-git-b54e03c-win64-static.7z" + "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20150916-git-cbbd906-win64-static.7z", + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150916-git-cbbd906-win64-static.7z" }; case Architecture.X86: return new[] { - "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150717-git-8250943-win32-static.7z", - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150901-git-b54e03c-win32-static.7z" + "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20150916-git-cbbd906-win32-static.7z", + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/windows/ffmpeg-20150916-git-cbbd906-win32-static.7z" }; } break; @@ -102,7 +102,7 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg case Architecture.X86_X64: return new[] { - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/osx/ffmpeg-x64-2.7.2.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/osx/ffmpeg-x64-2.8.0.7z" }; case Architecture.X86: return new[] @@ -119,12 +119,12 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg case Architecture.X86_X64: return new[] { - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-2.7.1-64bit-static.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-2.8.0-64bit-static.7z" }; case Architecture.X86: return new[] { - "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-2.7.1-32bit-static.7z" + "https://github.com/MediaBrowser/Emby.Resources/raw/master/ffmpeg/linux/ffmpeg-2.8.0-32bit-static.7z" }; } break; diff --git a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs b/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs index 54cd1357a6..d3388f47e5 100644 --- a/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs +++ b/MediaBrowser.Server.Startup.Common/FFMpeg/FFmpegValidator.cs @@ -7,6 +7,7 @@ using System.Globalization; using System.IO; using System.Text; using MediaBrowser.Common.IO; +using System.Collections.Generic; namespace MediaBrowser.Server.Startup.Common.FFMpeg { @@ -23,71 +24,65 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg _fileSystem = fileSystem; } - public void Validate(FFMpegInfo info) + public Tuple,List> Validate(FFMpegInfo info) { _logger.Info("FFMpeg: {0}", info.EncoderPath); _logger.Info("FFProbe: {0}", info.ProbePath); - string cacheKey; + var decoders = GetDecoders(info.EncoderPath); + var encoders = GetEncoders(info.EncoderPath); - try - { - cacheKey = new FileInfo(info.EncoderPath).Length.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N"); - } - catch (IOException) - { - // This could happen if ffmpeg is coming from a Path variable and we don't have the full path - cacheKey = Guid.NewGuid().ToString("N"); - } - catch - { - cacheKey = Guid.NewGuid().ToString("N"); - } - - var cachePath = Path.Combine(_appPaths.CachePath, "1" + cacheKey); - - ValidateCodecs(info.EncoderPath, cachePath); + return new Tuple, List>(decoders, encoders); } - private void ValidateCodecs(string ffmpegPath, string cachePath) + private List GetDecoders(string ffmpegPath) { - string output = null; + string output = string.Empty; try { - output = _fileSystem.ReadAllText(cachePath, Encoding.UTF8); + output = GetFFMpegOutput(ffmpegPath, "-decoders"); } catch { - } - if (string.IsNullOrWhiteSpace(output)) + var found = new List(); + var required = new[] { - try - { - output = GetFFMpegOutput(ffmpegPath, "-encoders"); - } - catch - { - return; - } + "h264_qsv", + "mpeg2_qsv", + "vc1_qsv" + }; - try + foreach (var codec in required) + { + var srch = " " + codec + " "; + + if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1) { - _fileSystem.CreateDirectory(Path.GetDirectoryName(cachePath)); - _fileSystem.WriteAllText(cachePath, output, Encoding.UTF8); + _logger.Warn("ffmpeg is missing decoder " + codec); } - catch + else { - + found.Add(codec); } } - ValidateCodecsFromOutput(output); + return found; } - private void ValidateCodecsFromOutput(string output) + private List GetEncoders(string ffmpegPath) { + string output = null; + try + { + output = GetFFMpegOutput(ffmpegPath, "-encoders"); + } + catch + { + } + + var found = new List(); var required = new[] { "libx264", @@ -103,16 +98,21 @@ namespace MediaBrowser.Server.Startup.Common.FFMpeg "srt" }; - foreach (var encoder in required) + foreach (var codec in required) { - var srch = " " + encoder + " "; + var srch = " " + codec + " "; if (output.IndexOf(srch, StringComparison.OrdinalIgnoreCase) == -1) { - _logger.Error("ffmpeg is missing encoder " + encoder); - //throw new ArgumentException("ffmpeg is missing encoder " + encoder); + _logger.Warn("ffmpeg is missing encoder " + codec); + } + else + { + found.Add(codec); } } + + return found; } private string GetFFMpegOutput(string path, string arguments) -- cgit v1.2.3 From 6d3dcd826695973fd958c92a775416a2e7b65835 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Sep 2015 12:16:06 -0400 Subject: update client sync --- MediaBrowser.Model/Configuration/ServerConfiguration.cs | 2 -- .../EntryPoints/ExternalPortForwarding.cs | 3 ++- MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj | 9 --------- 3 files changed, 2 insertions(+), 12 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index b137a8502e..3785924431 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -272,8 +272,6 @@ namespace MediaBrowser.Model.Configuration PeopleMetadataOptions = new PeopleMetadataOptions(); - EnableVideoFrameByFrameAnalysis = false; - InsecureApps9 = new[] { "Unknown app", diff --git a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs index fa5841bb83..a2ffa9affb 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/ExternalPortForwarding.cs @@ -147,7 +147,8 @@ namespace MediaBrowser.Server.Implementations.EntryPoints // It also can fail with others like 727-ExternalPortOnlySupportsWildcard, 728-NoPortMapsAvailable // and those errors (upnp errors) could be useful for diagnosting. - _logger.ErrorException("Error creating port forwarding rules", ex); + // Commenting out because users are reporting problems out of our control + //_logger.ErrorException("Error creating port forwarding rules", ex); } } diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 1291f2f7e6..bd46bf96d8 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -598,9 +598,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -614,9 +611,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -1200,9 +1194,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest -- cgit v1.2.3 From e8010955dc10c4be9b73c9a10de84356744b1cca Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Sep 2015 13:22:34 -0400 Subject: fix merge conflicts --- Emby.Drawing/ImageProcessor.cs | 52 +++++++++++----------- MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 11 ++--- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 13 +++--- .../Entities/Audio/MusicAlbum.cs | 2 +- .../Configuration/ServerConfiguration.cs | 20 +++++---- .../Devices/DeviceManager.cs | 4 +- .../Library/MediaSourceManager.cs | 9 ++-- 7 files changed, 57 insertions(+), 54 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 4710378017..efc8087387 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using Emby.Drawing.Common; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.Drawing; @@ -16,7 +17,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Emby.Drawing.Common; namespace Emby.Drawing { @@ -215,12 +215,12 @@ namespace Emby.Drawing { CheckDisposed(); - if (!_fileSystem.FileExists(cacheFilePath)) + if (!File.Exists(cacheFilePath)) { var newWidth = Convert.ToInt32(newSize.Width); var newHeight = Convert.ToInt32(newSize.Height); - _fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); + Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); @@ -270,7 +270,7 @@ namespace Emby.Drawing await semaphore.WaitAsync().ConfigureAwait(false); // Check again in case of contention - if (_fileSystem.FileExists(croppedImagePath)) + if (File.Exists(croppedImagePath)) { semaphore.Release(); return GetResult(croppedImagePath); @@ -280,7 +280,7 @@ namespace Emby.Drawing try { - _fileSystem.CreateDirectory(Path.GetDirectoryName(croppedImagePath)); + Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath)); await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); imageProcessingLockTaken = true; @@ -366,7 +366,7 @@ namespace Emby.Drawing /// ImageSize. public ImageSize GetImageSize(string path) { - return GetImageSize(path, _fileSystem.GetLastWriteTimeUtc(path), false); + return GetImageSize(path, File.GetLastWriteTimeUtc(path), false); } public ImageSize GetImageSize(ItemImageInfo info) @@ -399,8 +399,6 @@ namespace Emby.Drawing { size = GetImageSizeInternal(path, allowSlowMethod); - StartSaveImageSizeTimer(); - _cachedImagedSizes.AddOrUpdate(cacheHash, size, (keyName, oldValue) => size); } @@ -415,26 +413,28 @@ namespace Emby.Drawing /// ImageSize. private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod) { + ImageSize size; + try { - using (var file = TagLib.File.Create(path)) - { - var image = file as TagLib.Image.File; - - var properties = image.Properties; - - return new ImageSize - { - Height = properties.PhotoHeight, - Width = properties.PhotoWidth - }; - } + size = ImageHeader.GetDimensions(path, _logger, _fileSystem); } catch { + if (!allowSlowMethod) + { + throw; + } + //_logger.Info("Failed to read image header for {0}. Doing it the slow way.", path); + + CheckDisposed(); + + size = _imageEncoder.GetImageSize(path); } - return ImageHeader.GetDimensions(path, _logger, _fileSystem); + StartSaveImageSizeTimer(); + + return size; } private readonly Timer _saveImageSizeTimer; @@ -452,7 +452,7 @@ namespace Emby.Drawing try { var path = ImageSizeFile; - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); _jsonSerializer.SerializeToFile(_cachedImagedSizes, path); } catch (Exception ex) @@ -624,7 +624,7 @@ namespace Emby.Drawing await semaphore.WaitAsync().ConfigureAwait(false); // Check again in case of contention - if (_fileSystem.FileExists(enhancedImagePath)) + if (File.Exists(enhancedImagePath)) { semaphore.Release(); return enhancedImagePath; @@ -634,7 +634,7 @@ namespace Emby.Drawing try { - _fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath)); + Directory.CreateDirectory(Path.GetDirectoryName(enhancedImagePath)); await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); @@ -819,4 +819,4 @@ namespace Emby.Drawing } } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index 036397b4f5..ca5cf51114 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -23,7 +23,8 @@ namespace MediaBrowser.Api.Playback.Hls /// public abstract class BaseHlsService : BaseStreamingService { - protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) + protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer) + : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) { } @@ -90,12 +91,12 @@ namespace MediaBrowser.Api.Playback.Hls TranscodingJob job = null; var playlist = state.OutputFilePath; - if (!FileSystem.FileExists(playlist)) + if (!File.Exists(playlist)) { await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); try { - if (!FileSystem.FileExists(playlist)) + if (!File.Exists(playlist)) { // If the playlist doesn't already exist, startup ffmpeg try @@ -150,7 +151,7 @@ namespace MediaBrowser.Api.Playback.Hls { ApiEntryPoint.Instance.OnTranscodeEndRequest(job); } - + return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } @@ -317,4 +318,4 @@ namespace MediaBrowser.Api.Playback.Hls return false; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 9359c65f26..120ec6c0e0 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Playback.Hls TranscodingJob job = null; - if (FileSystem.FileExists(segmentPath)) + if (File.Exists(segmentPath)) { job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false); @@ -174,7 +174,7 @@ namespace MediaBrowser.Api.Playback.Hls await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); try { - if (FileSystem.FileExists(segmentPath)) + if (File.Exists(segmentPath)) { job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false); @@ -386,7 +386,8 @@ namespace MediaBrowser.Api.Playback.Hls try { - return fileSystem.GetFiles(folder) + return new DirectoryInfo(folder) + .EnumerateFiles("*", SearchOption.TopDirectoryOnly) .Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase) && Path.GetFileNameWithoutExtension(i.Name).StartsWith(filePrefix, StringComparison.OrdinalIgnoreCase)) .OrderByDescending(fileSystem.GetLastWriteTimeUtc) .FirstOrDefault(); @@ -431,7 +432,7 @@ namespace MediaBrowser.Api.Playback.Hls CancellationToken cancellationToken) { // If all transcoding has completed, just return immediately - if (transcodingJob != null && transcodingJob.HasExited && FileSystem.FileExists(segmentPath)) + if (transcodingJob != null && transcodingJob.HasExited && File.Exists(segmentPath)) { return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob); } @@ -451,7 +452,7 @@ namespace MediaBrowser.Api.Playback.Hls // If it appears in the playlist, it's done if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1) { - if (FileSystem.FileExists(segmentPath)) + if (File.Exists(segmentPath)) { return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob); } @@ -988,4 +989,4 @@ namespace MediaBrowser.Api.Playback.Hls return base.CanStreamCopyVideo(request, videoStream); } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index 98d1eb4ce2..8cd0a8def8 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -140,4 +140,4 @@ namespace MediaBrowser.Controller.Entities.Audio return id; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 3785924431..551ca2305c 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -44,6 +44,12 @@ namespace MediaBrowser.Model.Configuration /// true if [use HTTPS]; otherwise, false. public bool EnableHttps { get; set; } + /// + /// Gets or sets a value indicating whether [enable user specific user views]. + /// + /// true if [enable user specific user views]; otherwise, false. + public bool EnableUserSpecificUserViews { get; set; } + /// /// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// @@ -98,12 +104,6 @@ namespace MediaBrowser.Model.Configuration /// true if [disable startup scan]; otherwise, false. public bool DisableStartupScan { get; set; } - /// - /// Gets or sets a value indicating whether [enable user views]. - /// - /// true if [enable user views]; otherwise, false. - public bool EnableUserViews { get; set; } - /// /// Gets or sets a value indicating whether [enable library metadata sub folder]. /// @@ -223,7 +223,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableWindowsShortcuts { get; set; } public bool EnableVideoFrameByFrameAnalysis { get; set; } - + /// /// Initializes a new instance of the class. /// @@ -274,7 +274,11 @@ namespace MediaBrowser.Model.Configuration InsecureApps9 = new[] { + "Chromecast", + "iOS", "Unknown app", + "iPad", + "iPhone", "Windows Phone" }; @@ -577,4 +581,4 @@ namespace MediaBrowser.Model.Configuration }; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index a6a8b3a7a1..0feacc9751 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -157,7 +157,7 @@ namespace MediaBrowser.Server.Implementations.Devices _libraryMonitor.ReportFileSystemChangeBeginning(path); - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + Directory.CreateDirectory(Path.GetDirectoryName(path)); try { @@ -290,4 +290,4 @@ namespace MediaBrowser.Server.Implementations.Devices return config.GetConfiguration("devices"); } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs index a348c728e4..3da7e20212 100644 --- a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs @@ -15,7 +15,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Library { @@ -25,19 +24,17 @@ namespace MediaBrowser.Server.Implementations.Library private readonly IUserManager _userManager; private readonly ILibraryManager _libraryManager; private readonly IJsonSerializer _jsonSerializer; - private readonly IFileSystem _fileSystem; private IMediaSourceProvider[] _providers; private readonly ILogger _logger; - public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem) + public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer) { _itemRepo = itemRepo; _userManager = userManager; _libraryManager = libraryManager; _logger = logger; _jsonSerializer = jsonSerializer; - _fileSystem = fileSystem; } public void AddParts(IEnumerable providers) @@ -173,7 +170,7 @@ namespace MediaBrowser.Server.Implementations.Library if (source.Protocol == MediaProtocol.File) { // TODO: Path substitution - if (!_fileSystem.FileExists(source.Path)) + if (!File.Exists(source.Path)) { source.SupportsDirectStream = false; } @@ -585,4 +582,4 @@ namespace MediaBrowser.Server.Implementations.Library public MediaSourceInfo MediaSource; } } -} +} \ No newline at end of file -- cgit v1.2.3 From 4492dcc5922f4ead968504617b729e102db26c54 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Sep 2015 13:34:05 -0400 Subject: update merge --- Emby.Drawing/ImageProcessor.cs | 2 +- MediaBrowser.Api/Devices/DeviceService.cs | 2 +- MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 7 +++---- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 2 +- MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs | 2 +- MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs | 2 +- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 2 +- MediaBrowser.Model/Configuration/ServerConfiguration.cs | 6 +++--- MediaBrowser.Model/Dlna/StreamBuilder.cs | 2 +- MediaBrowser.Model/Net/MimeTypes.cs | 2 +- 10 files changed, 14 insertions(+), 15 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index efc8087387..231bfa2b47 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -819,4 +819,4 @@ namespace Emby.Drawing } } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Api/Devices/DeviceService.cs b/MediaBrowser.Api/Devices/DeviceService.cs index 6b280011a6..759eea3537 100644 --- a/MediaBrowser.Api/Devices/DeviceService.cs +++ b/MediaBrowser.Api/Devices/DeviceService.cs @@ -158,4 +158,4 @@ namespace MediaBrowser.Api.Devices } } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index ca5cf51114..e4f00e2a08 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -23,8 +23,7 @@ namespace MediaBrowser.Api.Playback.Hls /// public abstract class BaseHlsService : BaseStreamingService { - protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer) - : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) + protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) { } @@ -151,7 +150,7 @@ namespace MediaBrowser.Api.Playback.Hls { ApiEntryPoint.Instance.OnTranscodeEndRequest(job); } - + return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } @@ -318,4 +317,4 @@ namespace MediaBrowser.Api.Playback.Hls return false; } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 120ec6c0e0..7b2844cd4b 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -989,4 +989,4 @@ namespace MediaBrowser.Api.Playback.Hls return base.CanStreamCopyVideo(request, videoStream); } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs index 5858bdc529..42871866df 100644 --- a/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs +++ b/MediaBrowser.Common/ScheduledTasks/IntervalTrigger.cs @@ -104,4 +104,4 @@ namespace MediaBrowser.Common.ScheduledTasks } } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs index 8cd0a8def8..98d1eb4ce2 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs @@ -140,4 +140,4 @@ namespace MediaBrowser.Controller.Entities.Audio return id; } } -} \ No newline at end of file +} diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 6d45022da5..4fcc71f975 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -879,4 +879,4 @@ namespace MediaBrowser.MediaEncoding.Encoder } } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 551ca2305c..87b5e4fd71 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -103,7 +103,7 @@ namespace MediaBrowser.Model.Configuration /// /// true if [disable startup scan]; otherwise, false. public bool DisableStartupScan { get; set; } - + /// /// Gets or sets a value indicating whether [enable library metadata sub folder]. /// @@ -223,7 +223,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableWindowsShortcuts { get; set; } public bool EnableVideoFrameByFrameAnalysis { get; set; } - + /// /// Initializes a new instance of the class. /// @@ -581,4 +581,4 @@ namespace MediaBrowser.Model.Configuration }; } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index db4f692973..0335c43f05 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -1042,4 +1042,4 @@ namespace MediaBrowser.Model.Dlna return true; } } -} \ No newline at end of file +} diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs index 419809160b..e905af58da 100644 --- a/MediaBrowser.Model/Net/MimeTypes.cs +++ b/MediaBrowser.Model/Net/MimeTypes.cs @@ -321,4 +321,4 @@ namespace MediaBrowser.Model.Net return null; } } -} \ No newline at end of file +} -- cgit v1.2.3 From 959ac9d7275241f797a7c921b2cbf943a41a2f0c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Sep 2015 13:56:26 -0400 Subject: restore changes --- Emby.Drawing/ImageProcessor.cs | 52 +++++++++++----------- MediaBrowser.Api/Playback/Hls/BaseHlsService.cs | 11 ++--- MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs | 13 +++--- MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 27 ++++++++--- .../Configuration/ServerConfiguration.cs | 22 ++++----- .../Devices/DeviceManager.cs | 4 +- .../Library/MediaSourceManager.cs | 9 ++-- 7 files changed, 75 insertions(+), 63 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/Emby.Drawing/ImageProcessor.cs b/Emby.Drawing/ImageProcessor.cs index 231bfa2b47..3e5dca9b7f 100644 --- a/Emby.Drawing/ImageProcessor.cs +++ b/Emby.Drawing/ImageProcessor.cs @@ -1,5 +1,4 @@ -using Emby.Drawing.Common; -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Controller; using MediaBrowser.Controller.Drawing; @@ -17,6 +16,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Emby.Drawing.Common; namespace Emby.Drawing { @@ -215,12 +215,12 @@ namespace Emby.Drawing { CheckDisposed(); - if (!File.Exists(cacheFilePath)) + if (!_fileSystem.FileExists(cacheFilePath)) { var newWidth = Convert.ToInt32(newSize.Width); var newHeight = Convert.ToInt32(newSize.Height); - Directory.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(cacheFilePath)); await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); @@ -270,7 +270,7 @@ namespace Emby.Drawing await semaphore.WaitAsync().ConfigureAwait(false); // Check again in case of contention - if (File.Exists(croppedImagePath)) + if (_fileSystem.FileExists(croppedImagePath)) { semaphore.Release(); return GetResult(croppedImagePath); @@ -280,7 +280,7 @@ namespace Emby.Drawing try { - Directory.CreateDirectory(Path.GetDirectoryName(croppedImagePath)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(croppedImagePath)); await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); imageProcessingLockTaken = true; @@ -366,7 +366,7 @@ namespace Emby.Drawing /// ImageSize. public ImageSize GetImageSize(string path) { - return GetImageSize(path, File.GetLastWriteTimeUtc(path), false); + return GetImageSize(path, _fileSystem.GetLastWriteTimeUtc(path), false); } public ImageSize GetImageSize(ItemImageInfo info) @@ -399,6 +399,8 @@ namespace Emby.Drawing { size = GetImageSizeInternal(path, allowSlowMethod); + StartSaveImageSizeTimer(); + _cachedImagedSizes.AddOrUpdate(cacheHash, size, (keyName, oldValue) => size); } @@ -413,28 +415,26 @@ namespace Emby.Drawing /// ImageSize. private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod) { - ImageSize size; - try { - size = ImageHeader.GetDimensions(path, _logger, _fileSystem); - } - catch - { - if (!allowSlowMethod) + using (var file = TagLib.File.Create(path)) { - throw; - } - //_logger.Info("Failed to read image header for {0}. Doing it the slow way.", path); + var image = file as TagLib.Image.File; - CheckDisposed(); + var properties = image.Properties; - size = _imageEncoder.GetImageSize(path); + return new ImageSize + { + Height = properties.PhotoHeight, + Width = properties.PhotoWidth + }; + } + } + catch + { } - StartSaveImageSizeTimer(); - - return size; + return ImageHeader.GetDimensions(path, _logger, _fileSystem); } private readonly Timer _saveImageSizeTimer; @@ -452,7 +452,7 @@ namespace Emby.Drawing try { var path = ImageSizeFile; - Directory.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); _jsonSerializer.SerializeToFile(_cachedImagedSizes, path); } catch (Exception ex) @@ -624,7 +624,7 @@ namespace Emby.Drawing await semaphore.WaitAsync().ConfigureAwait(false); // Check again in case of contention - if (File.Exists(enhancedImagePath)) + if (_fileSystem.FileExists(enhancedImagePath)) { semaphore.Release(); return enhancedImagePath; @@ -634,7 +634,7 @@ namespace Emby.Drawing try { - Directory.CreateDirectory(Path.GetDirectoryName(enhancedImagePath)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(enhancedImagePath)); await _imageProcessingSemaphore.WaitAsync().ConfigureAwait(false); @@ -819,4 +819,4 @@ namespace Emby.Drawing } } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs index e4f00e2a08..a9a9610a97 100644 --- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs @@ -23,7 +23,8 @@ namespace MediaBrowser.Api.Playback.Hls /// public abstract class BaseHlsService : BaseStreamingService { - protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer) : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) + protected BaseHlsService(IServerConfigurationManager serverConfig, IUserManager userManager, ILibraryManager libraryManager, IIsoManager isoManager, IMediaEncoder mediaEncoder, IFileSystem fileSystem, IDlnaManager dlnaManager, ISubtitleEncoder subtitleEncoder, IDeviceManager deviceManager, IMediaSourceManager mediaSourceManager, IZipClient zipClient, IJsonSerializer jsonSerializer) + : base(serverConfig, userManager, libraryManager, isoManager, mediaEncoder, fileSystem, dlnaManager, subtitleEncoder, deviceManager, mediaSourceManager, zipClient, jsonSerializer) { } @@ -90,12 +91,12 @@ namespace MediaBrowser.Api.Playback.Hls TranscodingJob job = null; var playlist = state.OutputFilePath; - if (!File.Exists(playlist)) + if (!FileSystem.FileExists(playlist)) { await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); try { - if (!File.Exists(playlist)) + if (!FileSystem.FileExists(playlist)) { // If the playlist doesn't already exist, startup ffmpeg try @@ -150,7 +151,7 @@ namespace MediaBrowser.Api.Playback.Hls { ApiEntryPoint.Instance.OnTranscodeEndRequest(job); } - + return ResultFactory.GetResult(playlistText, MimeTypes.GetMimeType("playlist.m3u8"), new Dictionary()); } @@ -317,4 +318,4 @@ namespace MediaBrowser.Api.Playback.Hls return false; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs index 7b2844cd4b..cb49e65c7e 100644 --- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs +++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs @@ -165,7 +165,7 @@ namespace MediaBrowser.Api.Playback.Hls TranscodingJob job = null; - if (File.Exists(segmentPath)) + if (FileSystem.FileExists(segmentPath)) { job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false); @@ -174,7 +174,7 @@ namespace MediaBrowser.Api.Playback.Hls await ApiEntryPoint.Instance.TranscodingStartLock.WaitAsync(cancellationTokenSource.Token).ConfigureAwait(false); try { - if (File.Exists(segmentPath)) + if (FileSystem.FileExists(segmentPath)) { job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType); return await GetSegmentResult(state, playlistPath, segmentPath, requestedIndex, job, cancellationToken).ConfigureAwait(false); @@ -386,8 +386,7 @@ namespace MediaBrowser.Api.Playback.Hls try { - return new DirectoryInfo(folder) - .EnumerateFiles("*", SearchOption.TopDirectoryOnly) + return fileSystem.GetFiles(folder) .Where(i => string.Equals(i.Extension, segmentExtension, StringComparison.OrdinalIgnoreCase) && Path.GetFileNameWithoutExtension(i.Name).StartsWith(filePrefix, StringComparison.OrdinalIgnoreCase)) .OrderByDescending(fileSystem.GetLastWriteTimeUtc) .FirstOrDefault(); @@ -432,7 +431,7 @@ namespace MediaBrowser.Api.Playback.Hls CancellationToken cancellationToken) { // If all transcoding has completed, just return immediately - if (transcodingJob != null && transcodingJob.HasExited && File.Exists(segmentPath)) + if (transcodingJob != null && transcodingJob.HasExited && FileSystem.FileExists(segmentPath)) { return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob); } @@ -452,7 +451,7 @@ namespace MediaBrowser.Api.Playback.Hls // If it appears in the playlist, it's done if (text.IndexOf(segmentFilename, StringComparison.OrdinalIgnoreCase) != -1) { - if (File.Exists(segmentPath)) + if (FileSystem.FileExists(segmentPath)) { return GetSegmentResult(state, segmentPath, segmentIndex, transcodingJob); } @@ -989,4 +988,4 @@ namespace MediaBrowser.Api.Playback.Hls return base.CanStreamCopyVideo(request, videoStream); } } -} +} \ No newline at end of file diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs index 4fcc71f975..6f25d4b6e6 100644 --- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs @@ -97,6 +97,22 @@ namespace MediaBrowser.MediaEncoding.Encoder FFMpegPath = ffMpegPath; } + public void SetAvailableEncoders(List list) + { + + } + + private List _decoders = new List(); + public void SetAvailableDecoders(List list) + { + _decoders = list.ToList(); + } + + public bool SupportsDecoder(string decoder) + { + return _decoders.Contains(decoder, StringComparer.OrdinalIgnoreCase); + } + /// /// Gets the encoder path. /// @@ -330,7 +346,7 @@ namespace MediaBrowser.MediaEncoding.Encoder EnableRaisingEvents = true }; - _logger.Debug("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); + _logger.Info("{0} {1}", process.StartInfo.FileName, process.StartInfo.Arguments); using (process) { @@ -356,7 +372,7 @@ namespace MediaBrowser.MediaEncoding.Encoder process.WaitForExit(); - _logger.Debug("Keyframe extraction took {0} seconds", (DateTime.UtcNow - start).TotalSeconds); + _logger.Info("Keyframe extraction took {0} seconds", (DateTime.UtcNow - start).TotalSeconds); //_logger.Debug("Found keyframes {0}", string.Join(",", lines.ToArray())); return lines; } @@ -483,9 +499,6 @@ namespace MediaBrowser.MediaEncoding.Encoder } } - // TODO: Output in webp for smaller sizes - // -f image2 -f webp - // Use ffmpeg to sample 100 (we can drop this if required using thumbnail=50 for 50 frames) frames and pick the best thumbnail. Have a fall back just in case. var args = useIFrame ? string.Format("-i {0} -threads 1 -v quiet -vframes 1 -vf \"{2},thumbnail=30\" -f image2 \"{1}\"", inputPath, "-", vf) : string.Format("-i {0} -threads 1 -v quiet -vframes 1 -vf \"{2}\" -f image2 \"{1}\"", inputPath, "-", vf); @@ -605,7 +618,7 @@ namespace MediaBrowser.MediaEncoding.Encoder vf += string.Format(",scale=min(iw\\,{0}):trunc(ow/dar/2)*2", maxWidthParam); } - Directory.CreateDirectory(targetDirectory); + FileSystem.CreateDirectory(targetDirectory); var outputPath = Path.Combine(targetDirectory, filenamePrefix + "%05d.jpg"); var args = string.Format("-i {0} -threads 1 -v quiet -vf \"{2}\" -f image2 \"{1}\"", inputArgument, outputPath, vf); @@ -879,4 +892,4 @@ namespace MediaBrowser.MediaEncoding.Encoder } } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 87b5e4fd71..4ec6886117 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -44,12 +44,6 @@ namespace MediaBrowser.Model.Configuration /// true if [use HTTPS]; otherwise, false. public bool EnableHttps { get; set; } - /// - /// Gets or sets a value indicating whether [enable user specific user views]. - /// - /// true if [enable user specific user views]; otherwise, false. - public bool EnableUserSpecificUserViews { get; set; } - /// /// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// @@ -103,7 +97,13 @@ namespace MediaBrowser.Model.Configuration /// /// true if [disable startup scan]; otherwise, false. public bool DisableStartupScan { get; set; } - + + /// + /// Gets or sets a value indicating whether [enable user views]. + /// + /// true if [enable user views]; otherwise, false. + public bool EnableUserViews { get; set; } + /// /// Gets or sets a value indicating whether [enable library metadata sub folder]. /// @@ -223,7 +223,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableWindowsShortcuts { get; set; } public bool EnableVideoFrameByFrameAnalysis { get; set; } - + /// /// Initializes a new instance of the class. /// @@ -274,11 +274,7 @@ namespace MediaBrowser.Model.Configuration InsecureApps9 = new[] { - "Chromecast", - "iOS", "Unknown app", - "iPad", - "iPhone", "Windows Phone" }; @@ -581,4 +577,4 @@ namespace MediaBrowser.Model.Configuration }; } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs index 0173f27847..548a2222a9 100644 --- a/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs +++ b/MediaBrowser.Server.Implementations/Devices/DeviceManager.cs @@ -157,7 +157,7 @@ namespace MediaBrowser.Server.Implementations.Devices _libraryMonitor.ReportFileSystemChangeBeginning(path); - Directory.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); try { @@ -290,4 +290,4 @@ namespace MediaBrowser.Server.Implementations.Devices return config.GetConfiguration("devices"); } } -} +} \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs index 63067bf5a5..8ef7e94c20 100644 --- a/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs +++ b/MediaBrowser.Server.Implementations/Library/MediaSourceManager.cs @@ -15,6 +15,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.IO; namespace MediaBrowser.Server.Implementations.Library { @@ -24,17 +25,19 @@ namespace MediaBrowser.Server.Implementations.Library private readonly IUserManager _userManager; private readonly ILibraryManager _libraryManager; private readonly IJsonSerializer _jsonSerializer; + private readonly IFileSystem _fileSystem; private IMediaSourceProvider[] _providers; private readonly ILogger _logger; - public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer) + public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem) { _itemRepo = itemRepo; _userManager = userManager; _libraryManager = libraryManager; _logger = logger; _jsonSerializer = jsonSerializer; + _fileSystem = fileSystem; } public void AddParts(IEnumerable providers) @@ -170,7 +173,7 @@ namespace MediaBrowser.Server.Implementations.Library if (source.Protocol == MediaProtocol.File) { // TODO: Path substitution - if (!File.Exists(source.Path)) + if (!_fileSystem.FileExists(source.Path)) { source.SupportsDirectStream = false; } @@ -582,4 +585,4 @@ namespace MediaBrowser.Server.Implementations.Library public MediaSourceInfo MediaSource; } } -} +} \ No newline at end of file -- cgit v1.2.3 From ebc95ffb9af1d8fabe94c2686af8e816018e34ef Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 25 Sep 2015 22:31:13 -0400 Subject: update access denied exceptions --- MediaBrowser.Api/EnvironmentService.cs | 12 +----- MediaBrowser.Api/Library/LibraryService.cs | 2 +- MediaBrowser.Api/LiveTv/LiveTvService.cs | 4 +- .../Configuration/ServerConfiguration.cs | 1 - MediaBrowser.Providers/Manager/ImageSaver.cs | 5 --- MediaBrowser.Providers/Manager/ProviderManager.cs | 6 +++ .../Subtitles/OpenSubtitleDownloader.cs | 2 +- .../HttpServer/HttpListenerHost.cs | 2 +- .../LiveTv/EmbyTV/EmbyTV.cs | 47 ++++++++++++++-------- .../Session/SessionManager.cs | 5 ++- MediaBrowser.WebDashboard/Api/PackageCreator.cs | 3 +- 11 files changed, 47 insertions(+), 42 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/EnvironmentService.cs b/MediaBrowser.Api/EnvironmentService.cs index 11a0eec231..81b326da8f 100644 --- a/MediaBrowser.Api/EnvironmentService.cs +++ b/MediaBrowser.Api/EnvironmentService.cs @@ -120,8 +120,6 @@ namespace MediaBrowser.Api /// /// The request. /// System.Object. - /// Path - /// public object Get(GetDirectoryContents request) { var path = request.Path; @@ -138,15 +136,7 @@ namespace MediaBrowser.Api return ToOptimizedSerializedResultUsingCache(GetNetworkShares(path).OrderBy(i => i.Path).ToList()); } - try - { - return ToOptimizedSerializedResultUsingCache(GetFileSystemEntries(request).OrderBy(i => i.Path).ToList()); - } - catch (UnauthorizedAccessException) - { - // Don't throw the original UnauthorizedAccessException because it will cause a 401 response - throw new ApplicationException("Access to the path " + request.Path + " is denied."); - } + return ToOptimizedSerializedResultUsingCache(GetFileSystemEntries(request).OrderBy(i => i.Path).ToList()); } public object Get(GetNetworkShares request) diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs index eb1cd6084b..20fd1ef40a 100644 --- a/MediaBrowser.Api/Library/LibraryService.cs +++ b/MediaBrowser.Api/Library/LibraryService.cs @@ -722,7 +722,7 @@ namespace MediaBrowser.Api.Library if (!item.CanDelete(user)) { - throw new UnauthorizedAccessException(); + throw new SecurityException("Unauthorized access"); } if (item is ILiveTvRecording) diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs index 07e64c98d4..344d6ab3d3 100644 --- a/MediaBrowser.Api/LiveTv/LiveTvService.cs +++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs @@ -521,12 +521,12 @@ namespace MediaBrowser.Api.LiveTv if (user == null) { - throw new UnauthorizedAccessException("Anonymous live tv management is not allowed."); + throw new SecurityException("Anonymous live tv management is not allowed."); } if (!user.Policy.EnableLiveTvManagement) { - throw new UnauthorizedAccessException("The current user does not have permission to manage live tv."); + throw new SecurityException("The current user does not have permission to manage live tv."); } } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 4ec6886117..5121fcd6f5 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -274,7 +274,6 @@ namespace MediaBrowser.Model.Configuration InsecureApps9 = new[] { - "Unknown app", "Windows Phone" }; diff --git a/MediaBrowser.Providers/Manager/ImageSaver.cs b/MediaBrowser.Providers/Manager/ImageSaver.cs index 624736779e..dec6886350 100644 --- a/MediaBrowser.Providers/Manager/ImageSaver.cs +++ b/MediaBrowser.Providers/Manager/ImageSaver.cs @@ -236,11 +236,6 @@ namespace MediaBrowser.Providers.Manager file.Attributes |= FileAttributes.Hidden; } } - catch (UnauthorizedAccessException ex) - { - _logger.Error("Error saving image to {0}", ex, path); - throw new Exception(string.Format("Error saving image to {0}", path), ex); - } finally { _libraryMonitor.ReportFileSystemChangeComplete(path, false); diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs index 596a76327b..b2a51377c6 100644 --- a/MediaBrowser.Providers/Manager/ProviderManager.cs +++ b/MediaBrowser.Providers/Manager/ProviderManager.cs @@ -879,6 +879,11 @@ namespace MediaBrowser.Providers.Manager private void StartRefreshTimer() { + if (_disposed) + { + return; + } + lock (_refreshTimerLock) { if (_refreshTimer == null) @@ -1013,6 +1018,7 @@ namespace MediaBrowser.Providers.Manager public void Dispose() { _disposed = true; + StopRefreshTimer(); } } } \ No newline at end of file diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs index 54db0d5faa..5e48b79e35 100644 --- a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -196,7 +196,7 @@ namespace MediaBrowser.Providers.Subtitles if (!(loginResponse is MethodResponseLogIn)) { - throw new UnauthorizedAccessException("Authentication to OpenSubtitles failed."); + throw new Exception("Authentication to OpenSubtitles failed."); } _lastLogin = DateTime.UtcNow; diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 1885afc61e..e8bb40ba11 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer {typeof (FileNotFoundException), 404}, {typeof (DirectoryNotFoundException), 404}, {typeof (SecurityException), 401}, - {typeof (UnauthorizedAccessException), 401} + {typeof (UnauthorizedAccessException), 500} }; HostConfig.Instance.DebugMode = true; diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2b55945e62..ca3da4aa2a 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -611,11 +611,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV try { + var recordingEndDate = timer.EndDate.AddSeconds(timer.PostPaddingSeconds); + + if (recordingEndDate <= DateTime.UtcNow) + { + _logger.Warn("Recording timer fired for timer {0}, Id: {1}, but the program has already ended.", timer.Name, timer.Id); + return; + } + var cancellationTokenSource = new CancellationTokenSource(); if (_activeRecordings.TryAdd(timer.Id, cancellationTokenSource)) { - await RecordStream(timer, cancellationTokenSource.Token).ConfigureAwait(false); + await RecordStream(timer, recordingEndDate, cancellationTokenSource.Token).ConfigureAwait(false); } } catch (OperationCanceledException) @@ -628,22 +636,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } } - private async Task RecordStream(TimerInfo timer, CancellationToken cancellationToken) + private async Task RecordStream(TimerInfo timer, DateTime recordingEndDate, CancellationToken cancellationToken) { if (timer == null) { throw new ArgumentNullException("timer"); } - var mediaStreamInfo = await GetChannelStream(timer.ChannelId, null, CancellationToken.None); - var duration = (timer.EndDate - DateTime.UtcNow).Add(TimeSpan.FromSeconds(timer.PostPaddingSeconds)); - - HttpRequestOptions httpRequestOptions = new HttpRequestOptions() - { - Url = mediaStreamInfo.Path - }; - var info = GetProgramInfoFromCache(timer.ChannelId, timer.ProgramId); + var recordPath = RecordingPath; if (info.IsMovie) @@ -708,15 +709,27 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV _recordingProvider.Add(recording); } - recording.Path = recordPath; - recording.Status = RecordingStatus.InProgress; - recording.DateLastUpdated = DateTime.UtcNow; - _recordingProvider.Update(recording); - - _logger.Info("Beginning recording."); - try { + var mediaStreamInfo = await GetChannelStream(timer.ChannelId, null, CancellationToken.None); + + // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg + await Task.Delay(3000, cancellationToken).ConfigureAwait(false); + + var duration = recordingEndDate - DateTime.UtcNow; + + HttpRequestOptions httpRequestOptions = new HttpRequestOptions() + { + Url = mediaStreamInfo.Path + }; + + recording.Path = recordPath; + recording.Status = RecordingStatus.InProgress; + recording.DateLastUpdated = DateTime.UtcNow; + _recordingProvider.Update(recording); + + _logger.Info("Beginning recording."); + httpRequestOptions.BufferContent = false; var durationToken = new CancellationTokenSource(duration); var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, durationToken.Token).Token; diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index d9c3ed7a6d..d164874dc9 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -29,6 +29,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Controller.Net; namespace MediaBrowser.Server.Implementations.Session { @@ -1276,7 +1277,7 @@ namespace MediaBrowser.Server.Implementations.Session { if (!_deviceManager.CanAccessDevice(user.Id.ToString("N"), request.DeviceId)) { - throw new UnauthorizedAccessException("User is not allowed access from this device."); + throw new SecurityException("User is not allowed access from this device."); } } @@ -1286,7 +1287,7 @@ namespace MediaBrowser.Server.Implementations.Session { EventHelper.FireEventIfNotNull(AuthenticationFailed, this, new GenericEventArgs(request), _logger); - throw new UnauthorizedAccessException("Invalid user or password entered."); + throw new SecurityException("Invalid user or password entered."); } var token = await GetAuthorizationToken(user.Id.ToString("N"), request.DeviceId, request.App, request.AppVersion, request.DeviceName).ConfigureAwait(false); diff --git a/MediaBrowser.WebDashboard/Api/PackageCreator.cs b/MediaBrowser.WebDashboard/Api/PackageCreator.cs index 7aaf9c27a9..9e9c1f1b9d 100644 --- a/MediaBrowser.WebDashboard/Api/PackageCreator.cs +++ b/MediaBrowser.WebDashboard/Api/PackageCreator.cs @@ -9,6 +9,7 @@ using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using MediaBrowser.Controller.Net; using WebMarkupMin.Core; using WebMarkupMin.Core.Minifiers; using WebMarkupMin.Core.Settings; @@ -136,7 +137,7 @@ namespace MediaBrowser.WebDashboard.Api // Don't allow file system access outside of the source folder if (!_fileSystem.ContainsSubPath(rootPath, fullPath)) { - throw new UnauthorizedAccessException(); + throw new SecurityException("Access denied"); } return fullPath; -- cgit v1.2.3 From 1f7e1f5c4a9051c7fa13a09b4d895cf58ee1b3bf Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 14 Oct 2015 01:02:30 -0400 Subject: boxset image fixes --- MediaBrowser.Api/StartupWizardService.cs | 1 + MediaBrowser.Controller/Entities/BaseItem.cs | 3 ++ MediaBrowser.Controller/Entities/IHasMetadata.cs | 6 ++++ .../Providers/ImageRefreshMode.cs | 8 ++--- .../Configuration/ServerConfiguration.cs | 2 ++ MediaBrowser.Providers/Manager/MetadataService.cs | 36 +++++++++++++++++++--- .../Collections/CollectionImageProvider.cs | 11 +++++++ .../Collections/CollectionManager.cs | 15 ++++++--- .../Library/LibraryManager.cs | 6 ++-- .../LiveTv/LiveTvManager.cs | 2 +- .../Persistence/SqliteItemRepository.cs | 21 +++++++++++-- .../Photos/BaseDynamicImageProvider.cs | 2 +- .../UserViews/CollectionFolderImageProvider.cs | 2 +- .../UserViews/DynamicImageProvider.cs | 2 +- 14 files changed, 95 insertions(+), 22 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 962334cdc3..399c81ae88 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -73,6 +73,7 @@ namespace MediaBrowser.Api _config.Configuration.DisableXmlSavers = true; _config.Configuration.DisableStartupScan = true; _config.Configuration.EnableUserViews = true; + _config.Configuration.EnableDateLastRefresh = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 59d2a4bc70..22ca607ba0 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -342,6 +342,9 @@ namespace MediaBrowser.Controller.Entities public DateTime DateLastSaved { get; set; } + [IgnoreDataMember] + public DateTime DateLastRefreshed { get; set; } + /// /// The logger /// diff --git a/MediaBrowser.Controller/Entities/IHasMetadata.cs b/MediaBrowser.Controller/Entities/IHasMetadata.cs index b8c3e2823c..4eb25718e3 100644 --- a/MediaBrowser.Controller/Entities/IHasMetadata.cs +++ b/MediaBrowser.Controller/Entities/IHasMetadata.cs @@ -30,6 +30,12 @@ namespace MediaBrowser.Controller.Entities /// The date last saved. DateTime DateLastSaved { get; set; } + /// + /// Gets or sets the date last refreshed. + /// + /// The date last refreshed. + DateTime DateLastRefreshed { get; set; } + /// /// Updates to repository. /// diff --git a/MediaBrowser.Controller/Providers/ImageRefreshMode.cs b/MediaBrowser.Controller/Providers/ImageRefreshMode.cs index df10c91f6a..73ef4b8cda 100644 --- a/MediaBrowser.Controller/Providers/ImageRefreshMode.cs +++ b/MediaBrowser.Controller/Providers/ImageRefreshMode.cs @@ -8,14 +8,14 @@ namespace MediaBrowser.Controller.Providers None = 0, /// - /// The default + /// Existing images will be validated /// - Default = 1, + ValidationOnly = 1, /// - /// Existing images will be validated + /// The default /// - ValidationOnly = 2, + Default = 2, /// /// All providers will be executed to search for new metadata diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 5121fcd6f5..06a35ac0d1 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -224,6 +224,8 @@ namespace MediaBrowser.Model.Configuration public bool EnableVideoFrameByFrameAnalysis { get; set; } + public bool EnableDateLastRefresh { get; set; } + /// /// Initializes a new instance of the class. /// diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index f40f175880..316809fa8b 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Entities.Movies; namespace MediaBrowser.Providers.Manager { @@ -82,7 +83,7 @@ namespace MediaBrowser.Providers.Manager /// ProviderResult. protected MetadataStatus GetLastResult(IHasMetadata item) { - if (item.DateLastSaved == default(DateTime)) + if (GetLastRefreshDate(item) == default(DateTime)) { return new MetadataStatus { ItemId = item.Id }; } @@ -181,11 +182,13 @@ namespace MediaBrowser.Providers.Manager } } - var beforeSaveResult = await BeforeSave(itemOfType, item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata || refreshOptions.MetadataRefreshMode == MetadataRefreshMode.FullRefresh, updateType).ConfigureAwait(false); + var isFirstRefresh = GetLastRefreshDate(item) == default(DateTime); + + var beforeSaveResult = await BeforeSave(itemOfType, isFirstRefresh || refreshOptions.ReplaceAllMetadata || refreshOptions.MetadataRefreshMode == MetadataRefreshMode.FullRefresh, updateType).ConfigureAwait(false); updateType = updateType | beforeSaveResult; // Save if changes were made, or it's never been saved before - if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || item.DateLastSaved == default(DateTime) || refreshOptions.ReplaceAllMetadata) + if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || isFirstRefresh || refreshOptions.ReplaceAllMetadata) { // If any of these properties are set then make sure the updateType is not None, just to force everything to save if (refreshOptions.ForceSave || refreshOptions.ReplaceAllMetadata) @@ -193,6 +196,11 @@ namespace MediaBrowser.Providers.Manager updateType = updateType | ItemUpdateType.MetadataDownload; } + if (refreshOptions.MetadataRefreshMode >= MetadataRefreshMode.Default && refreshOptions.ImageRefreshMode >= ImageRefreshMode.Default) + { + item.DateLastRefreshed = DateTime.UtcNow; + } + // Save to database await SaveItem(metadataResult, updateType, cancellationToken).ConfigureAwait(false); } @@ -207,6 +215,26 @@ namespace MediaBrowser.Providers.Manager return updateType; } + private DateTime GetLastRefreshDate(IHasMetadata item) + { + if (item.DateLastRefreshed != default(DateTime)) + { + return item.DateLastRefreshed; + } + + if (ServerConfigurationManager.Configuration.EnableDateLastRefresh) + { + return item.DateLastRefreshed; + } + + if (item is BoxSet) + { + return item.DateLastRefreshed; + } + + return item.DateLastSaved; + } + protected async Task SaveItem(MetadataResult result, ItemUpdateType reason, CancellationToken cancellationToken) { if (result.Item.SupportsPeople && result.People != null) @@ -222,7 +250,7 @@ namespace MediaBrowser.Providers.Manager item.AfterMetadataRefresh(); return _cachedTask; } - + private readonly Task _cachedResult = Task.FromResult(ItemUpdateType.None); /// /// Befores the save. diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs b/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs index b88e459809..5ff1828441 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionImageProvider.cs @@ -22,6 +22,17 @@ namespace MediaBrowser.Server.Implementations.Collections { } + protected override bool Supports(IHasImages item) + { + // Right now this is the only way to prevent this image from getting created ahead of internet image providers + if (!item.IsLocked) + { + return false; + } + + return base.Supports(item); + } + protected override Task> GetItemsWithImages(IHasImages item) { var playlist = (BoxSet)item; diff --git a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs index 8a19ee4316..5c98e401f4 100644 --- a/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs +++ b/MediaBrowser.Server.Implementations/Collections/CollectionManager.cs @@ -73,7 +73,7 @@ namespace MediaBrowser.Server.Implementations.Collections try { - _fileSystem.CreateDirectory(path); + _fileSystem.CreateDirectory(path); var collection = new BoxSet { @@ -93,7 +93,12 @@ namespace MediaBrowser.Server.Implementations.Collections if (options.ItemIdList.Count > 0) { - await AddToCollection(collection.Id, options.ItemIdList, false); + await AddToCollection(collection.Id, options.ItemIdList, false, new MetadataRefreshOptions(_fileSystem) + { + // The initial adding of items is going to create a local metadata file + // This will cause internet metadata to be skipped as a result + MetadataRefreshMode = MetadataRefreshMode.FullRefresh + }); } else { @@ -145,10 +150,10 @@ namespace MediaBrowser.Server.Implementations.Collections public Task AddToCollection(Guid collectionId, IEnumerable ids) { - return AddToCollection(collectionId, ids, true); + return AddToCollection(collectionId, ids, true, new MetadataRefreshOptions(_fileSystem)); } - private async Task AddToCollection(Guid collectionId, IEnumerable ids, bool fireEvent) + private async Task AddToCollection(Guid collectionId, IEnumerable ids, bool fireEvent, MetadataRefreshOptions refreshOptions) { var collection = _libraryManager.GetItemById(collectionId) as BoxSet; @@ -186,7 +191,7 @@ namespace MediaBrowser.Server.Implementations.Collections await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); - _providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(_fileSystem)); + _providerManager.QueueRefresh(collection.Id, refreshOptions); if (fireEvent) { diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 93e660fd36..06b9ecabe8 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1699,7 +1699,7 @@ namespace MediaBrowser.Server.Implementations.Library if (!refresh) { - refresh = (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + refresh = (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval; } if (refresh) @@ -1796,7 +1796,7 @@ namespace MediaBrowser.Server.Implementations.Library await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); } - var refresh = isNew || (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval; if (refresh) { @@ -1866,7 +1866,7 @@ namespace MediaBrowser.Server.Implementations.Library await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false); } - var refresh = isNew || (DateTime.UtcNow - item.DateLastSaved) >= _viewRefreshInterval; + var refresh = isNew || (DateTime.UtcNow - item.DateLastRefreshed) >= _viewRefreshInterval; if (refresh) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 40e837ed7c..65125da66b 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -706,7 +706,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv isNew = true; } - + item.ChannelId = _tvDtoService.GetInternalChannelId(serviceName, info.ChannelId).ToString("N"); item.CommunityRating = info.CommunityRating; item.OfficialRating = info.OfficialRating; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 4b83885828..cede9350e8 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -197,6 +197,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(_logger, "TypedBaseItems", "IsHD", "BIT"); _connection.AddColumn(_logger, "TypedBaseItems", "ExternalEtag", "Text"); _connection.AddColumn(_logger, "TypedBaseItems", "ExternalImagePath", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "DateLastRefreshed", "DATETIME"); PrepareStatements(); @@ -291,7 +292,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "PreferredMetadataCountryCode", "IsHD", "ExternalEtag", - "ExternalImagePath" + "ExternalImagePath", + "DateLastRefreshed" }; private readonly string[] _mediaStreamSaveColumns = @@ -378,7 +380,8 @@ namespace MediaBrowser.Server.Implementations.Persistence "PreferredMetadataCountryCode", "IsHD", "ExternalEtag", - "ExternalImagePath" + "ExternalImagePath", + "DateLastRefreshed" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -599,6 +602,15 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.ExternalEtag; _saveItemCommand.GetParameter(index++).Value = item.ExternalImagePath; + if (item.DateLastRefreshed == default(DateTime)) + { + _saveItemCommand.GetParameter(index++).Value = null; + } + else + { + _saveItemCommand.GetParameter(index++).Value = item.DateLastRefreshed; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -820,6 +832,11 @@ namespace MediaBrowser.Server.Implementations.Persistence item.ExternalImagePath = reader.GetString(23); } + if (!reader.IsDBNull(24)) + { + item.DateLastRefreshed = reader.GetDateTime(24).ToUniversalTime(); + } + return item; } diff --git a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs index cc0140d689..47ec47f8f6 100644 --- a/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/Photos/BaseDynamicImageProvider.cs @@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Photos ImageProcessor = imageProcessor; } - public virtual bool Supports(IHasImages item) + protected virtual bool Supports(IHasImages item) { return true; } diff --git a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs index a699bfabfc..9247edadb6 100644 --- a/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/CollectionFolderImageProvider.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.UserViews return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary) || i.HasImage(ImageType.Thumb)).ToList(), 8); } - public override bool Supports(IHasImages item) + protected override bool Supports(IHasImages item) { return item is CollectionFolder; } diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 2b18218a8c..8dfbe38f1a 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -131,7 +131,7 @@ namespace MediaBrowser.Server.Implementations.UserViews return GetFinalItems(items.Where(i => i.HasImage(ImageType.Primary)).ToList()); } - public override bool Supports(IHasImages item) + protected override bool Supports(IHasImages item) { var view = item as UserView; if (view != null) -- cgit v1.2.3 From 5471cdce2f7cfee10b617640a99ace184e2571e9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 14 Oct 2015 22:58:31 -0400 Subject: disable movie folder feature for dlna by default --- MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs | 2 +- MediaBrowser.Model/Configuration/DlnaOptions.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs index 72040c8aee..a9ce5587d7 100644 --- a/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs +++ b/MediaBrowser.Dlna/ContentDirectory/ControlHandler.cs @@ -523,7 +523,7 @@ namespace MediaBrowser.Dlna.ContentDirectory if (context == null || context.IsFolder) { var movie = item as Movie; - if (movie != null && options.EnableEnhancedMovies) + if (movie != null && options.EnableMovieFolders) { if (movie.GetTrailerIds().Count > 0 || movie.SpecialFeatureIds.Count > 0) diff --git a/MediaBrowser.Model/Configuration/DlnaOptions.cs b/MediaBrowser.Model/Configuration/DlnaOptions.cs index 277102a501..c1974b8778 100644 --- a/MediaBrowser.Model/Configuration/DlnaOptions.cs +++ b/MediaBrowser.Model/Configuration/DlnaOptions.cs @@ -10,7 +10,7 @@ namespace MediaBrowser.Model.Configuration public int ClientDiscoveryIntervalSeconds { get; set; } public int BlastAliveMessageIntervalSeconds { get; set; } public string DefaultUserId { get; set; } - public bool EnableEnhancedMovies { get; set; } + public bool EnableMovieFolders { get; set; } public DlnaOptions() { @@ -19,7 +19,6 @@ namespace MediaBrowser.Model.Configuration BlastAliveMessages = true; ClientDiscoveryIntervalSeconds = 60; BlastAliveMessageIntervalSeconds = 30; - EnableEnhancedMovies = true; } } } -- cgit v1.2.3 From a0b1ddf0a7fbe285ce44a971a6f073895b8c2521 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 16 Oct 2015 14:11:11 -0400 Subject: add migrations for new release --- MediaBrowser.Controller/LiveTv/ITunerHost.cs | 5 +- .../Configuration/ServerConfiguration.cs | 4 + .../LiveTv/EmbyTV/EmbyTV.cs | 89 ++++++++++++++++------ .../LiveTv/RefreshChannelsScheduledTask.cs | 2 +- .../LiveTv/TunerHosts/BaseTunerHost.cs | 44 +++++++++-- .../Persistence/CleanDatabaseScheduledTask.cs | 5 +- .../ApplicationHost.cs | 13 ++-- .../MediaBrowser.Server.Startup.Common.csproj | 1 + .../Migrations/Release5767.cs | 47 ++++++++++++ 9 files changed, 169 insertions(+), 41 deletions(-) create mode 100644 MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs (limited to 'MediaBrowser.Model/Configuration') diff --git a/MediaBrowser.Controller/LiveTv/ITunerHost.cs b/MediaBrowser.Controller/LiveTv/ITunerHost.cs index bedbcffe32..2e3a71f703 100644 --- a/MediaBrowser.Controller/LiveTv/ITunerHost.cs +++ b/MediaBrowser.Controller/LiveTv/ITunerHost.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Model.Dto; +using System; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.LiveTv; using System.Collections.Generic; using System.Threading; @@ -37,7 +38,7 @@ namespace MediaBrowser.Controller.LiveTv /// The stream identifier. /// The cancellation token. /// Task<MediaSourceInfo>. - Task GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken); + Task> GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken); /// /// Gets the channel stream media sources. /// diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 06a35ac0d1..dfcafa32d8 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -226,11 +226,15 @@ namespace MediaBrowser.Model.Configuration public bool EnableDateLastRefresh { get; set; } + public string[] Migrations { get; set; } + /// /// Initializes a new instance of the class. /// public ServerConfiguration() { + Migrations = new string[] {}; + ImageSavingConvention = ImageSavingConvention.Compatible; PublicPort = 8096; PublicHttpsPort = 8920; diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 3ec64a017b..0d49607953 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -487,6 +487,29 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV { _logger.Info("Streaming Channel " + channelId); + foreach (var hostInstance in _liveTvManager.TunerHosts) + { + try + { + var result = await hostInstance.GetChannelStream(channelId, streamId, cancellationToken).ConfigureAwait(false); + + result.Item2.Release(); + + return result.Item1; + } + catch (Exception e) + { + _logger.ErrorException("Error getting channel stream", e); + } + } + + throw new ApplicationException("Tuner not found."); + } + + private async Task> GetChannelStreamInternal(string channelId, string streamId, CancellationToken cancellationToken) + { + _logger.Info("Streaming Channel " + channelId); + foreach (var hostInstance in _liveTvManager.TunerHosts) { try @@ -653,40 +676,56 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV try { - var mediaStreamInfo = await GetChannelStream(timer.ChannelId, null, CancellationToken.None); - - // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg - await Task.Delay(3000, cancellationToken).ConfigureAwait(false); + var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None); + var mediaStreamInfo = result.Item1; + var isResourceOpen = true; - var duration = recordingEndDate - DateTime.UtcNow; - - HttpRequestOptions httpRequestOptions = new HttpRequestOptions() + // Unfortunately due to the semaphore we have to have a nested try/finally + try { - Url = mediaStreamInfo.Path - }; + // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg + await Task.Delay(3000, cancellationToken).ConfigureAwait(false); + + var duration = recordingEndDate - DateTime.UtcNow; - recording.Path = recordPath; - recording.Status = RecordingStatus.InProgress; - recording.DateLastUpdated = DateTime.UtcNow; - _recordingProvider.Update(recording); + HttpRequestOptions httpRequestOptions = new HttpRequestOptions() + { + Url = mediaStreamInfo.Path + }; + + recording.Path = recordPath; + recording.Status = RecordingStatus.InProgress; + recording.DateLastUpdated = DateTime.UtcNow; + _recordingProvider.Update(recording); + + _logger.Info("Beginning recording."); + + httpRequestOptions.BufferContent = false; + var durationToken = new CancellationTokenSource(duration); + var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, durationToken.Token).Token; + httpRequestOptions.CancellationToken = linkedToken; + _logger.Info("Writing file to path: " + recordPath); + using (var response = await _httpClient.SendAsync(httpRequestOptions, "GET")) + { + using (var output = _fileSystem.GetFileStream(recordPath, FileMode.Create, FileAccess.Write, FileShare.Read)) + { + result.Item2.Release(); + isResourceOpen = false; - _logger.Info("Beginning recording."); + await response.Content.CopyToAsync(output, StreamDefaults.DefaultCopyToBufferSize, linkedToken); + } + } - httpRequestOptions.BufferContent = false; - var durationToken = new CancellationTokenSource(duration); - var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, durationToken.Token).Token; - httpRequestOptions.CancellationToken = linkedToken; - _logger.Info("Writing file to path: " + recordPath); - using (var response = await _httpClient.SendAsync(httpRequestOptions, "GET")) + recording.Status = RecordingStatus.Completed; + _logger.Info("Recording completed"); + } + finally { - using (var output = _fileSystem.GetFileStream(recordPath, FileMode.Create, FileAccess.Write, FileShare.Read)) + if (isResourceOpen) { - await response.Content.CopyToAsync(output, StreamDefaults.DefaultCopyToBufferSize, linkedToken); + result.Item2.Release(); } } - - recording.Status = RecordingStatus.Completed; - _logger.Info("Recording completed"); } catch (OperationCanceledException) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs b/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs index d8d91c2f97..3fb1d96614 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/RefreshChannelsScheduledTask.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace MediaBrowser.Server.Implementations.LiveTv { - class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask, IHasKey + public class RefreshChannelsScheduledTask : IScheduledTask, IConfigurableScheduledTask, IHasKey { private readonly ILiveTvManager _liveTvManager; private readonly IConfigurationManager _config; diff --git a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs index 616d01a327..d811152c26 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/TunerHosts/BaseTunerHost.cs @@ -141,7 +141,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts protected abstract Task GetChannelStream(TunerHostInfo tuner, string channelId, string streamId, CancellationToken cancellationToken); - public async Task GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken) + public async Task> GetChannelStream(string channelId, string streamId, CancellationToken cancellationToken) { if (IsValidChannelId(channelId)) { @@ -173,9 +173,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts try { var stream = await GetChannelStream(host, channelId, streamId, cancellationToken).ConfigureAwait(false); - - await AddMediaInfo(stream, false, cancellationToken).ConfigureAwait(false); - return stream; + var resourcePool = GetLock(host.Url); + + await AddMediaInfo(stream, false, resourcePool, cancellationToken).ConfigureAwait(false); + return new Tuple(stream, resourcePool); } catch (Exception ex) { @@ -187,7 +188,40 @@ namespace MediaBrowser.Server.Implementations.LiveTv.TunerHosts throw new LiveTvConflictException(); } - private async Task AddMediaInfo(MediaSourceInfo mediaSource, bool isAudio, CancellationToken cancellationToken) + /// + /// The _semaphoreLocks + /// + private readonly ConcurrentDictionary _semaphoreLocks = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); + /// + /// Gets the lock. + /// + /// The filename. + /// System.Object. + private SemaphoreSlim GetLock(string url) + { + return _semaphoreLocks.GetOrAdd(url, key => new SemaphoreSlim(1, 1)); + } + + private async Task AddMediaInfo(MediaSourceInfo mediaSource, bool isAudio, SemaphoreSlim resourcePool, CancellationToken cancellationToken) + { + await resourcePool.WaitAsync(cancellationToken).ConfigureAwait(false); + + try + { + await AddMediaInfoInternal(mediaSource, isAudio, cancellationToken).ConfigureAwait(false); + + // Leave the resource locked. it will be released upstream + } + catch (Exception) + { + // Release the resource if there's some kind of failure. + resourcePool.Release(); + + throw; + } + } + + private async Task AddMediaInfoInternal(MediaSourceInfo mediaSource, bool isAudio, CancellationToken cancellationToken) { var originalRuntime = mediaSource.RunTimeTicks; diff --git a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs index 6259c61af7..60b8c00bd2 100644 --- a/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs +++ b/MediaBrowser.Server.Implementations/Persistence/CleanDatabaseScheduledTask.cs @@ -1,5 +1,4 @@ -using MediaBrowser.Common.IO; -using MediaBrowser.Common.Progress; +using MediaBrowser.Common.Progress; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; @@ -17,7 +16,7 @@ using MediaBrowser.Controller.Entities.Audio; namespace MediaBrowser.Server.Implementations.Persistence { - class CleanDatabaseScheduledTask : IScheduledTask + public class CleanDatabaseScheduledTask : IScheduledTask { private readonly ILibraryManager _libraryManager; private readonly IItemRepository _itemRepo; diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index 840ccd8af0..bcb75d9a04 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -333,18 +333,18 @@ namespace MediaBrowser.Server.Startup.Common }); LogManager.RemoveConsoleOutput(); + + PerformPostInitMigrations(); } - public override async Task Init(IProgress progress) + public override Task Init(IProgress progress) { HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber; PerformPreInitMigrations(); - await base.Init(progress).ConfigureAwait(false); - - PerformPostInitMigrations(); + return base.Init(progress); } private void PerformPreInitMigrations() @@ -362,7 +362,10 @@ namespace MediaBrowser.Server.Startup.Common private void PerformPostInitMigrations() { - var migrations = new List(); + var migrations = new List + { + new Release5767(ServerConfigurationManager, TaskManager) + }; foreach (var task in migrations) { diff --git a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj index 9def89073b..13b782e406 100644 --- a/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj +++ b/MediaBrowser.Server.Startup.Common/MediaBrowser.Server.Startup.Common.csproj @@ -72,6 +72,7 @@ + diff --git a/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs b/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs new file mode 100644 index 0000000000..9a4580c127 --- /dev/null +++ b/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using MediaBrowser.Common.ScheduledTasks; +using MediaBrowser.Controller.Configuration; +using MediaBrowser.Server.Implementations.LiveTv; +using MediaBrowser.Server.Implementations.Persistence; +using MediaBrowser.Server.Implementations.ScheduledTasks; + +namespace MediaBrowser.Server.Startup.Common.Migrations +{ + public class Release5767 : IVersionMigration + { + private readonly IServerConfigurationManager _config; + private readonly ITaskManager _taskManager; + + public Release5767(IServerConfigurationManager config, ITaskManager taskManager) + { + _config = config; + _taskManager = taskManager; + } + + public void Run() + { + var name = "5767"; + + if (_config.Configuration.Migrations.Contains(name, StringComparer.OrdinalIgnoreCase)) + { + return; + } + + Task.Run(async () => + { + await Task.Delay(3000).ConfigureAwait(false); + + _taskManager.QueueScheduledTask(); + _taskManager.QueueScheduledTask(); + _taskManager.QueueScheduledTask(); + }); + + var list = _config.Configuration.Migrations.ToList(); + list.Add(name); + _config.Configuration.Migrations = list.ToArray(); + _config.SaveConfiguration(); + } + } +} -- cgit v1.2.3