diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 97c856035..6dc97100d 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -416,6 +416,8 @@ namespace MediaBrowser.Common.Implementations /// protected virtual void FindParts() { + RegisterModules(); + ConfigurationManager.AddParts(GetExports()); Plugins = GetExports(); } @@ -481,7 +483,6 @@ namespace MediaBrowser.Common.Implementations IsoManager = new IsoManager(); RegisterSingleInstance(IsoManager); - RegisterModules(); return Task.FromResult (true); } @@ -524,6 +525,14 @@ namespace MediaBrowser.Common.Implementations } catch (ReflectionTypeLoadException ex) { + if (ex.LoaderExceptions != null) + { + foreach (var loaderException in ex.LoaderExceptions) + { + Logger.Error("LoaderException: " + loaderException.Message); + } + } + // If it fails we can still get a list of the Types it was able to resolve return ex.Types.Where(t => t != null); } diff --git a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs index 0bcc5c711..7bbc1abd7 100644 --- a/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs +++ b/MediaBrowser.Common.Implementations/Configuration/BaseConfigurationManager.cs @@ -10,6 +10,7 @@ using System.IO; using System.Linq; using System.Threading; using CommonIO; +using MediaBrowser.Common.Extensions; namespace MediaBrowser.Common.Implementations.Configuration { @@ -33,7 +34,7 @@ namespace MediaBrowser.Common.Implementations.Configuration /// Occurs when [configuration updating]. /// public event EventHandler NamedConfigurationUpdating; - + /// /// Occurs when [named configuration updated]. /// @@ -89,8 +90,8 @@ namespace MediaBrowser.Common.Implementations.Configuration } } - private ConfigurationStore[] _configurationStores = {}; - private IConfigurationFactory[] _configurationFactories = {}; + private ConfigurationStore[] _configurationStores = { }; + private IConfigurationFactory[] _configurationFactories = { }; /// /// Initializes a new instance of the class. @@ -228,9 +229,15 @@ namespace MediaBrowser.Common.Implementations.Configuration { var file = GetConfigurationFile(key); - var configurationType = _configurationStores - .First(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)) - .ConfigurationType; + var configurationInfo = _configurationStores + .FirstOrDefault(i => string.Equals(i.Key, key, StringComparison.OrdinalIgnoreCase)); + + if (configurationInfo == null) + { + throw new ResourceNotFoundException("Configuration with key " + key + " not found."); + } + + var configurationType = configurationInfo.ConfigurationType; lock (_configurationSyncLock) { @@ -285,7 +292,7 @@ namespace MediaBrowser.Common.Implementations.Configuration NewConfiguration = configuration }, Logger); - + _configurations.AddOrUpdate(key, configuration, (k, v) => configuration); var path = GetConfigurationFile(key); diff --git a/MediaBrowser.Providers/Manager/ItemImageProvider.cs b/MediaBrowser.Providers/Manager/ItemImageProvider.cs index cfa3e67f5..77902e668 100644 --- a/MediaBrowser.Providers/Manager/ItemImageProvider.cs +++ b/MediaBrowser.Providers/Manager/ItemImageProvider.cs @@ -465,6 +465,13 @@ namespace MediaBrowser.Providers.Manager var url = image.Url; + if (EnableImageStub(item, type)) + { + SaveImageStub(item, type, url); + result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; + return true; + } + try { var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false); @@ -488,6 +495,28 @@ namespace MediaBrowser.Providers.Manager return false; } + private bool EnableImageStub(IHasImages item, ImageType type) + { + if (item.LocationType == LocationType.Remote || item.LocationType == LocationType.Virtual) + { + return true; + } + + return true; + } + + private void SaveImageStub(IHasImages item, ImageType imageType, string url) + { + var newIndex = item.AllowsMultipleImages(imageType) ? item.GetImages(imageType).Count() : 0; + + item.SetImage(new ItemImageInfo + { + Path = url, + Type = imageType + + }, newIndex); + } + private async Task DownloadBackdrops(IHasImages item, ImageType imageType, int limit, IRemoteImageProvider provider, RefreshResult result, IEnumerable images, int minWidth, CancellationToken cancellationToken) { foreach (var image in images.Where(i => i.Type == imageType)) @@ -504,6 +533,13 @@ namespace MediaBrowser.Providers.Manager var url = image.Url; + if (EnableImageStub(item, imageType)) + { + SaveImageStub(item, imageType, url); + result.UpdateType = result.UpdateType | ItemUpdateType.ImageUpdate; + return; + } + try { var response = await provider.GetImageResponse(url, cancellationToken).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/Movies/FanartMovieImageProvider.cs b/MediaBrowser.Providers/Movies/FanartMovieImageProvider.cs index cb2e993a0..d2e9b160d 100644 --- a/MediaBrowser.Providers/Movies/FanartMovieImageProvider.cs +++ b/MediaBrowser.Providers/Movies/FanartMovieImageProvider.cs @@ -20,6 +20,9 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; +using MediaBrowser.Controller.Channels; +using MediaBrowser.Controller.LiveTv; +using MediaBrowser.Model.Channels; using MediaBrowser.Providers.TV; namespace MediaBrowser.Providers.Movies @@ -59,6 +62,30 @@ namespace MediaBrowser.Providers.Movies public bool Supports(IHasImages item) { + //var channelItem = item as IChannelMediaItem; + + //if (channelItem != null) + //{ + // if (channelItem.ContentType == ChannelMediaContentType.Movie) + // { + // return true; + // } + // if (channelItem.ContentType == ChannelMediaContentType.MovieExtra) + // { + // if (channelItem.ExtraType == ExtraType.Trailer) + // { + // return true; + // } + // } + //} + + // Supports images for tv movies + //var tvProgram = item as LiveTvProgram; + //if (tvProgram != null && tvProgram.IsMovie) + //{ + // return true; + //} + return item is Movie || item is BoxSet || item is MusicVideo; } diff --git a/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs b/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs index 6e0ff14b9..b6f93392b 100644 --- a/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs +++ b/MediaBrowser.Providers/Movies/MovieDbImageProvider.cs @@ -71,15 +71,6 @@ namespace MediaBrowser.Providers.Movies public IEnumerable GetSupportedImages(IHasImages item) { - if (item is ChannelVideoItem || item is LiveTvProgram) - { - // Too many channel items to allow backdrops here - return new List - { - ImageType.Primary - }; - } - return new List { ImageType.Primary, diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index eccce75d4..1bb8c21bf 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -42,6 +42,7 @@ namespace MediaBrowser.Server.Implementations.Channels private readonly IFileSystem _fileSystem; private readonly IJsonSerializer _jsonSerializer; private readonly IHttpClient _httpClient; + private readonly IProviderManager _providerManager; private readonly ILocalizationManager _localization; private readonly ConcurrentDictionary _refreshedItems = new ConcurrentDictionary(); @@ -51,7 +52,7 @@ namespace MediaBrowser.Server.Implementations.Channels private Timer _refreshTimer; private Timer _clearDownloadCountsTimer; - public ChannelManager(IUserManager userManager, IDtoService dtoService, ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem, IUserDataManager userDataManager, IJsonSerializer jsonSerializer, ILocalizationManager localization, IHttpClient httpClient) + public ChannelManager(IUserManager userManager, IDtoService dtoService, ILibraryManager libraryManager, ILogger logger, IServerConfigurationManager config, IFileSystem fileSystem, IUserDataManager userDataManager, IJsonSerializer jsonSerializer, ILocalizationManager localization, IHttpClient httpClient, IProviderManager providerManager) { _userManager = userManager; _dtoService = dtoService; @@ -63,6 +64,7 @@ namespace MediaBrowser.Server.Implementations.Channels _jsonSerializer = jsonSerializer; _localization = localization; _httpClient = httpClient; + _providerManager = providerManager; _refreshTimer = new Timer(s => _refreshedItems.Clear(), null, TimeSpan.FromHours(3), TimeSpan.FromHours(3)); _clearDownloadCountsTimer = new Timer(s => _downloadCounts.Clear(), null, TimeSpan.FromHours(24), TimeSpan.FromHours(24)); @@ -649,7 +651,7 @@ namespace MediaBrowser.Server.Implementations.Channels var internalItems = await Task.WhenAll(itemTasks).ConfigureAwait(false); internalItems = ApplyFilters(internalItems, query.Filters, user).ToArray(); - await RefreshIfNeeded(internalItems, new Progress(), cancellationToken).ConfigureAwait(false); + RefreshIfNeeded(internalItems); if (query.StartIndex.HasValue) { @@ -814,7 +816,7 @@ namespace MediaBrowser.Server.Implementations.Channels var internalResult = await GetAllMediaInternal(query, cancellationToken).ConfigureAwait(false); - await RefreshIfNeeded(internalResult.Items, new Progress(), cancellationToken).ConfigureAwait(false); + RefreshIfNeeded(internalResult.Items); var dtoOptions = new DtoOptions(); @@ -954,7 +956,7 @@ namespace MediaBrowser.Server.Implementations.Channels } } - return await GetReturnItems(internalItems, providerTotalRecordCount, user, query, progress, cancellationToken).ConfigureAwait(false); + return await GetReturnItems(internalItems, providerTotalRecordCount, user, query).ConfigureAwait(false); } public async Task> GetChannelItems(ChannelItemQuery query, CancellationToken cancellationToken) @@ -1123,9 +1125,7 @@ namespace MediaBrowser.Server.Implementations.Channels private async Task> GetReturnItems(IEnumerable items, int? totalCountFromProvider, User user, - ChannelItemQuery query, - IProgress progress, - CancellationToken cancellationToken) + ChannelItemQuery query) { items = ApplyFilters(items, query.Filters, user); @@ -1148,7 +1148,7 @@ namespace MediaBrowser.Server.Implementations.Channels } var returnItemArray = all.ToArray(); - await RefreshIfNeeded(returnItemArray, progress, cancellationToken).ConfigureAwait(false); + RefreshIfNeeded(returnItemArray); return new QueryResult { @@ -1272,32 +1272,22 @@ namespace MediaBrowser.Server.Implementations.Channels return item; } - private async Task RefreshIfNeeded(BaseItem[] programs, IProgress progress, CancellationToken cancellationToken) + private void RefreshIfNeeded(BaseItem[] programs) { - var numComplete = 0; - var numItems = programs.Length; - foreach (var program in programs) { - await RefreshIfNeeded(program, cancellationToken).ConfigureAwait(false); - - numComplete++; - double percent = numComplete; - percent /= numItems; - progress.Report(percent * 100); + RefreshIfNeeded(program); } } - private readonly Task _cachedTask = Task.FromResult(true); - private Task RefreshIfNeeded(BaseItem program, CancellationToken cancellationToken) + private void RefreshIfNeeded(BaseItem program) { if (!_refreshedItems.ContainsKey(program.Id)) { _refreshedItems.TryAdd(program.Id, true); - return program.RefreshMetadata(cancellationToken); + _providerManager.QueueRefresh(program.Id, new MetadataRefreshOptions(_fileSystem)); } - return _cachedTask; } internal IChannel GetChannelProvider(Channel channel) diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index cede9350e..49b1f1821 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -225,19 +225,18 @@ namespace MediaBrowser.Server.Implementations.Persistence var columns = string.Join(",", _mediaStreamSaveColumns); string[] queries = { - "INSERT INTO mediastreams("+columns+") SELECT "+columns+" FROM MediaInfoOld.mediastreams;" + "REPLACE INTO mediastreams("+columns+") SELECT "+columns+" FROM MediaInfoOld.mediastreams;" }; try { _connection.RunQueries(queries, _logger); + File.Delete(file); } catch (Exception ex) { - throw ex; + _logger.ErrorException("Error migrating media info database", ex); } - - File.Delete(file); } private void MigrateChapters(string file) @@ -247,19 +246,18 @@ namespace MediaBrowser.Server.Implementations.Persistence SqliteExtensions.Attach(_connection, backupFile, "ChaptersOld"); string[] queries = { - "INSERT INTO "+ChaptersTableName+"(ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath) SELECT ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath FROM ChaptersOld.Chapters;" + "REPLACE INTO "+ChaptersTableName+"(ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath) SELECT ItemId, ChapterIndex, StartPositionTicks, Name, ImagePath FROM ChaptersOld.Chapters;" }; try { _connection.RunQueries(queries, _logger); + File.Delete(file); } catch (Exception ex) { - throw ex; + _logger.ErrorException("Error migrating chapter database", ex); } - - File.Delete(file); } /// diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index bcb75d9a0..70e903114 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -8,7 +8,6 @@ using MediaBrowser.Common.Events; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Implementations; using MediaBrowser.Common.Implementations.ScheduledTasks; -using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; using MediaBrowser.Common.Progress; using MediaBrowser.Controller; @@ -477,7 +476,7 @@ namespace MediaBrowser.Server.Startup.Common progress.Report(15); - ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LogManager.GetLogger("ChannelManager"), ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager, HttpClient); + ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LogManager.GetLogger("ChannelManager"), ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager, HttpClient, ProviderManager); RegisterSingleInstance(ChannelManager); MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager); @@ -524,8 +523,7 @@ namespace MediaBrowser.Server.Startup.Common await RegisterMediaEncoder(innerProgress).ConfigureAwait(false); progress.Report(90); - EncodingManager = new EncodingManager(FileSystemManager, Logger, - MediaEncoder, ChapterManager); + EncodingManager = new EncodingManager(FileSystemManager, Logger, MediaEncoder, ChapterManager); RegisterSingleInstance(EncodingManager); var sharingRepo = new SharingRepository(LogManager, ApplicationPaths); diff --git a/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs b/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs index 9a4580c12..d1c085734 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/Release5767.cs @@ -20,9 +20,9 @@ namespace MediaBrowser.Server.Startup.Common.Migrations _taskManager = taskManager; } - public void Run() + public async void Run() { - var name = "5767"; + var name = "5767.1"; if (_config.Configuration.Migrations.Contains(name, StringComparer.OrdinalIgnoreCase)) { @@ -38,6 +38,9 @@ namespace MediaBrowser.Server.Startup.Common.Migrations _taskManager.QueueScheduledTask(); }); + // Wait a few minutes before marking this as done. Make sure the server doesn't get restarted. + await Task.Delay(300000).ConfigureAwait(false); + var list = _config.Configuration.Migrations.ToList(); list.Add(name); _config.Configuration.Migrations = list.ToArray(); diff --git a/SharedVersion.cs b/SharedVersion.cs index 8675cc16c..b2a874c1f 100644 --- a/SharedVersion.cs +++ b/SharedVersion.cs @@ -1,4 +1,4 @@ using System.Reflection; //[assembly: AssemblyVersion("3.0.*")] -[assembly: AssemblyVersion("3.0.5768.0")] +[assembly: AssemblyVersion("3.0.5768.1")]