From 8397a0a56e40d3da10c77f472423c63019a2c781 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 17 Sep 2016 02:08:13 -0400 Subject: [PATCH 1/4] fix update level migration --- .../Migrations/UpdateLevelMigration.cs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs index 4afd5bd34..8483ca904 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/UpdateLevelMigration.cs @@ -6,6 +6,7 @@ using MediaBrowser.Common.Implementations.Updates; using MediaBrowser.Common.Net; using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; +using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Updates; @@ -18,17 +19,19 @@ namespace MediaBrowser.Server.Startup.Common.Migrations private readonly IHttpClient _httpClient; private readonly IJsonSerializer _jsonSerializer; private readonly string _releaseAssetFilename; + private readonly ILogger _logger; - public UpdateLevelMigration(IServerConfigurationManager config, IServerApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer, string releaseAssetFilename) + public UpdateLevelMigration(IServerConfigurationManager config, IServerApplicationHost appHost, IHttpClient httpClient, IJsonSerializer jsonSerializer, string releaseAssetFilename, ILogger logger) { _config = config; _appHost = appHost; _httpClient = httpClient; _jsonSerializer = jsonSerializer; _releaseAssetFilename = releaseAssetFilename; + _logger = logger; } - public async void Run() + public async Task Run() { var lastVersion = _config.Configuration.LastVersion; var currentVersion = _appHost.ApplicationVersion; @@ -44,9 +47,9 @@ namespace MediaBrowser.Server.Startup.Common.Migrations await CheckVersion(currentVersion, updateLevel, CancellationToken.None).ConfigureAwait(false); } - catch + catch (Exception ex) { - + _logger.ErrorException("Error in update migration", ex); } } @@ -109,10 +112,13 @@ namespace MediaBrowser.Server.Startup.Common.Migrations private Version ParseVersion(string versionString) { - var parts = versionString.Split('.'); - if (parts.Length == 3) + if (!string.IsNullOrWhiteSpace(versionString)) { - versionString += ".0"; + var parts = versionString.Split('.'); + if (parts.Length == 3) + { + versionString += ".0"; + } } Version version; From 7a67dba8efbd2d586b0576f18f128f76ff92efab Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 17 Sep 2016 02:08:38 -0400 Subject: [PATCH 2/4] add disposed check to FileRefresher --- MediaBrowser.Server.Implementations/IO/FileRefresher.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MediaBrowser.Server.Implementations/IO/FileRefresher.cs b/MediaBrowser.Server.Implementations/IO/FileRefresher.cs index 2f4605c5c..8e28aa2a0 100644 --- a/MediaBrowser.Server.Implementations/IO/FileRefresher.cs +++ b/MediaBrowser.Server.Implementations/IO/FileRefresher.cs @@ -68,6 +68,11 @@ namespace MediaBrowser.Server.Implementations.IO lock (_timerLock) { + if (_disposed) + { + return; + } + if (_timer == null) { _timer = new Timer(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1)); @@ -287,6 +292,7 @@ namespace MediaBrowser.Server.Implementations.IO if (_timer != null) { _timer.Dispose(); + _timer = null; } } } From 512740cfb24ab4c79bd20f32b75f778f38885b6e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 17 Sep 2016 02:09:02 -0400 Subject: [PATCH 3/4] exclude unrated from intros --- .../Intros/DefaultIntroProvider.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs index 4a43befed..9b23d5be4 100644 --- a/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs +++ b/MediaBrowser.Server.Implementations/Intros/DefaultIntroProvider.cs @@ -99,8 +99,9 @@ namespace MediaBrowser.Server.Implementations.Intros IncludeItemTypes = new[] { typeof(Trailer).Name }, TrailerTypes = trailerTypes.ToArray(), SimilarTo = item, - IsPlayed = config.EnableIntrosForWatchedContent ? (bool?) null : false, + IsPlayed = config.EnableIntrosForWatchedContent ? (bool?)null : false, MaxParentalRating = config.EnableIntrosParentalControl ? ratingLevel : null, + BlockUnratedItems = config.EnableIntrosParentalControl ? new[] { UnratedItem.Trailer } : new UnratedItem[] { }, Limit = config.TrailerLimit }); @@ -110,7 +111,7 @@ namespace MediaBrowser.Server.Implementations.Intros Type = i.SourceType == SourceType.Channel ? ItemWithTrailerType.ChannelTrailer : ItemWithTrailerType.ItemWithTrailer, LibraryManager = _libraryManager })); - } + } return GetResult(item, candidates, config); } @@ -197,7 +198,7 @@ namespace MediaBrowser.Server.Implementations.Intros } returnResult.AddRange(GetMediaInfoIntrosByTags(allIntros, item.Tags).Take(1)); - + return returnResult.DistinctBy(i => i.Path, StringComparer.OrdinalIgnoreCase); } catch (IOException) From 5cfae1ada1114cb03561565c0e8a9d354e89562e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 17 Sep 2016 02:09:29 -0400 Subject: [PATCH 4/4] update startup tasks --- MediaBrowser.Model/Dlna/StreamBuilder.cs | 4 ++-- .../LiveTv/LiveTvManager.cs | 2 +- MediaBrowser.Server.Startup.Common/ApplicationHost.cs | 10 +++++----- .../Migrations/DbMigration.cs | 2 +- .../Migrations/IVersionMigration.cs | 5 +++-- .../Migrations/MovieDbEpisodeProviderMigration.cs | 3 ++- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 13d559773..98bef334b 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -602,7 +602,7 @@ namespace MediaBrowser.Model.Dlna private int GetAudioBitrate(string subProtocol, int? maxTotalBitrate, int? targetAudioChannels, string targetAudioCodec, MediaStream audioStream) { - var defaultBitrate = audioStream == null ? 192000 : audioStream.BitRate ?? 192000; + int defaultBitrate = audioStream == null ? 192000 : audioStream.BitRate ?? 192000; // Reduce the bitrate if we're downmixing if (targetAudioChannels.HasValue && audioStream != null && audioStream.Channels.HasValue && targetAudioChannels.Value < audioStream.Channels.Value) { @@ -615,7 +615,7 @@ namespace MediaBrowser.Model.Dlna { if (StringHelper.EqualsIgnoreCase(targetAudioCodec, "ac3")) { - if (string.Equals(subProtocol, "hls", StringComparison.OrdinalIgnoreCase)) + if (StringHelper.EqualsIgnoreCase(subProtocol, "hls")) { defaultBitrate = Math.Max(384000, defaultBitrate); } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index b3ced55a5..65d023e88 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1011,7 +1011,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var factorChannelWatchCount = (query.IsAiring ?? false) || (query.IsKids ?? false) || (query.IsSports ?? false) || (query.IsMovie ?? false); - programs = programList.OrderBy(i => i.HasImage(ImageType.Primary) ? 0 : 1) + programs = programList.OrderBy(i => i.StartDate.Date) .ThenByDescending(i => GetRecommendationScore(i, user.Id, factorChannelWatchCount)) .ThenBy(i => i.StartDate); diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index f5419e5cf..d8d3614e6 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -315,6 +315,8 @@ namespace MediaBrowser.Server.Startup.Common /// public override async Task RunStartupTasks() { + await PerformPreInitMigrations().ConfigureAwait(false); + if (ServerConfigurationManager.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion && ServerConfigurationManager.Configuration.IsStartupWizardCompleted) { @@ -366,23 +368,21 @@ namespace MediaBrowser.Server.Startup.Common HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber; - PerformPreInitMigrations(); - return base.Init(progress); } - private void PerformPreInitMigrations() + private async Task PerformPreInitMigrations() { var migrations = new List { - new UpdateLevelMigration(ServerConfigurationManager, this, HttpClient, JsonSerializer, _releaseAssetFilename) + new UpdateLevelMigration(ServerConfigurationManager, this, HttpClient, JsonSerializer, _releaseAssetFilename, Logger) }; foreach (var task in migrations) { try { - task.Run(); + await task.Run().ConfigureAwait(false); } catch (Exception ex) { diff --git a/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs index f0cb9e84e..6bcdcca87 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/DbMigration.cs @@ -16,7 +16,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations _taskManager = taskManager; } - public void Run() + public async Task Run() { // If a forced migration is required, do that now if (_config.Configuration.MigrationVersion < CleanDatabaseScheduledTask.MigrationVersion) diff --git a/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs index a6a8c1a35..6ef08fae9 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/IVersionMigration.cs @@ -1,8 +1,9 @@ - +using System.Threading.Tasks; + namespace MediaBrowser.Server.Startup.Common.Migrations { public interface IVersionMigration { - void Run(); + Task Run(); } } diff --git a/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs b/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs index 3ad5f577f..cd2122e57 100644 --- a/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs +++ b/MediaBrowser.Server.Startup.Common/Migrations/MovieDbEpisodeProviderMigration.cs @@ -1,5 +1,6 @@ using MediaBrowser.Controller.Configuration; using System.Linq; +using System.Threading.Tasks; namespace MediaBrowser.Server.Startup.Common.Migrations { @@ -13,7 +14,7 @@ namespace MediaBrowser.Server.Startup.Common.Migrations _config = config; } - public void Run() + public async Task Run() { var migrationKey = this.GetType().FullName; var migrationKeyList = _config.Configuration.Migrations.ToList();