From b748d0784a6b2443ba841190a8ca9b6f0ae62828 Mon Sep 17 00:00:00 2001 From: softworkz Date: Tue, 20 Dec 2016 22:40:07 +0100 Subject: Enhanced sync events --- Emby.Server.Implementations/Sync/SyncManager.cs | 27 ++++++++++------------ .../Sync/SyncNotificationEntryPoint.cs | 12 ++++++++++ 2 files changed, 24 insertions(+), 15 deletions(-) (limited to 'Emby.Server.Implementations/Sync') diff --git a/Emby.Server.Implementations/Sync/SyncManager.cs b/Emby.Server.Implementations/Sync/SyncManager.cs index 13f60f5eea..061129e5f9 100644 --- a/Emby.Server.Implementations/Sync/SyncManager.cs +++ b/Emby.Server.Implementations/Sync/SyncManager.cs @@ -1042,10 +1042,7 @@ namespace Emby.Server.Implementations.Sync throw new ArgumentException("Operation is not valid for this job item"); } - if (jobItem.Status != SyncJobItemStatus.Synced) - { - jobItem.Status = SyncJobItemStatus.Cancelled; - } + jobItem.Status = SyncJobItemStatus.Cancelled; jobItem.Progress = 0; jobItem.IsMarkedForRemoval = true; @@ -1071,18 +1068,18 @@ namespace Emby.Server.Implementations.Sync _logger.ErrorException("Error deleting directory {0}", ex, path); } - //var jobItemsResult = GetJobItems(new SyncJobItemQuery - //{ - // AddMetadata = false, - // JobId = jobItem.JobId, - // Limit = 0, - // Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Failed, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring } - //}); + var jobItemsResult = GetJobItems(new SyncJobItemQuery + { + AddMetadata = false, + JobId = jobItem.JobId, + Limit = 0, + Statuses = new[] { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, SyncJobItemStatus.ReadyToTransfer, SyncJobItemStatus.Synced, SyncJobItemStatus.Transferring } + }); - //if (jobItemsResult.TotalRecordCount == 0) - //{ - // await CancelJob(jobItem.JobId).ConfigureAwait(false); - //} + if (jobItemsResult.TotalRecordCount == 0) + { + await CancelJob(jobItem.JobId).ConfigureAwait(false); + } } public Task MarkJobItemForRemoval(string id) diff --git a/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs b/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs index 46cdb28a4d..06e0e66a91 100644 --- a/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs +++ b/Emby.Server.Implementations/Sync/SyncNotificationEntryPoint.cs @@ -38,6 +38,18 @@ namespace Emby.Server.Implementations.Sync } } + + if (item.Status == SyncJobItemStatus.Cancelled) + { + try + { + await _sessionManager.SendMessageToUserDeviceSessions(item.TargetId, "SyncJobItemCancelled", item, CancellationToken.None).ConfigureAwait(false); + } + catch + { + + } + } } public void Dispose() -- cgit v1.2.3 From d350dc0edbff437cc2e5775e386da167dbd1224e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Dec 2016 12:09:50 -0500 Subject: resolve error saving sync jobs --- .../Data/SqliteExtensions.cs | 12 +++ Emby.Server.Implementations/Sync/SyncRepository.cs | 91 ++++++++++++++-------- .../TV/Omdb/OmdbEpisodeProvider.cs | 12 ++- 3 files changed, 80 insertions(+), 35 deletions(-) (limited to 'Emby.Server.Implementations/Sync') diff --git a/Emby.Server.Implementations/Data/SqliteExtensions.cs b/Emby.Server.Implementations/Data/SqliteExtensions.cs index d6ad0ba8ab..783258a138 100644 --- a/Emby.Server.Implementations/Data/SqliteExtensions.cs +++ b/Emby.Server.Implementations/Data/SqliteExtensions.cs @@ -346,6 +346,18 @@ namespace Emby.Server.Implementations.Data } } + public static void TryBind(this IStatement statement, string name, double? value) + { + if (value.HasValue) + { + TryBind(statement, name, value.Value); + } + else + { + TryBindNull(statement, name); + } + } + public static void TryBind(this IStatement statement, string name, int? value) { if (value.HasValue) diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index 885f8e64a6..6d4fce3997 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -221,48 +221,77 @@ namespace Emby.Server.Implementations.Sync using (var connection = CreateConnection()) { string commandText; - var paramList = new List(); if (insert) { - commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + commandText = "insert into SyncJobs (Id, TargetId, Name, Profile, Quality, Bitrate, Status, Progress, UserId, ItemIds, Category, ParentId, UnwatchedOnly, ItemLimit, SyncNewContent, DateCreated, DateLastModified, ItemCount) values (@Id, @TargetId, @Name, @Profile, @Quality, @Bitrate, @Status, @Progress, @UserId, @ItemIds, @Category, @ParentId, @UnwatchedOnly, @ItemLimit, @SyncNewContent, @DateCreated, @DateLastModified, @ItemCount)"; } else { - commandText = "update SyncJobs set TargetId=?,Name=?,Profile=?,Quality=?,Bitrate=?,Status=?,Progress=?,UserId=?,ItemIds=?,Category=?,ParentId=?,UnwatchedOnly=?,ItemLimit=?,SyncNewContent=?,DateCreated=?,DateLastModified=?,ItemCount=? where Id=?"; + commandText = "update SyncJobs set TargetId=@TargetId,Name=@Name,Profile=@Profile,Quality=@Quality,Bitrate=@Bitrate,Status=@Status,Progress=@Progress,UserId=@UserId,ItemIds=@ItemIds,Category=@Category,ParentId=@ParentId,UnwatchedOnly=@UnwatchedOnly,ItemLimit=@ItemLimit,SyncNewContent=@SyncNewContent,DateCreated=@DateCreated,DateLastModified=@DateLastModified,ItemCount=@ItemCount where Id=@Id"; } - paramList.Add(job.TargetId); - paramList.Add(job.Name); - paramList.Add(job.Profile); - paramList.Add(job.Quality); - paramList.Add(job.Bitrate); - paramList.Add(job.Status.ToString()); - paramList.Add(job.Progress); - paramList.Add(job.UserId); + connection.RunInTransaction(conn => + { + using (var statement = PrepareStatementSafe(connection, commandText)) + { + statement.TryBind("@TargetId", job.TargetId); + statement.TryBind("@Name", job.Name); + statement.TryBind("@Profile", job.Profile); + statement.TryBind("@Quality", job.Quality); + statement.TryBind("@Bitrate", job.Bitrate); + statement.TryBind("@Status", job.Status.ToString()); + statement.TryBind("@Progress", job.Progress); + statement.TryBind("@UserId", job.UserId); + + if (job.RequestedItemIds.Count > 0) + { + statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); + } + else + { + statement.TryBindNull("@ItemIds"); + } - paramList.Add(string.Join(",", job.RequestedItemIds.ToArray())); - paramList.Add(job.Category); - paramList.Add(job.ParentId); - paramList.Add(job.UnwatchedOnly); - paramList.Add(job.ItemLimit); - paramList.Add(job.SyncNewContent); - paramList.Add(job.DateCreated.ToDateTimeParamValue()); - paramList.Add(job.DateLastModified.ToDateTimeParamValue()); - paramList.Add(job.ItemCount); + if (job.Category.HasValue) + { + statement.TryBind("@Category", job.Category.Value.ToString()); + } + else + { + statement.TryBindNull("@Category"); + } - if (insert) - { - paramList.Insert(0, job.Id.ToGuidParamValue()); - } - else - { - paramList.Add(job.Id.ToGuidParamValue()); - } + if (!string.IsNullOrWhiteSpace(job.ParentId)) + { + statement.TryBind("@ParentId", job.ParentId); + } + else + { + statement.TryBindNull("@ParentId"); + } - connection.RunInTransaction(conn => - { - conn.Execute(commandText, paramList.ToArray()); + statement.TryBind("@UnwatchedOnly", job.UnwatchedOnly); + + if (job.ItemLimit.HasValue) + { + statement.TryBind("@ItemLimit", job.ItemLimit); + } + else + { + statement.TryBindNull("@ItemLimit"); + } + + statement.TryBind("@SyncNewContent", job.SyncNewContent); + + statement.TryBind("@DateCreated", job.DateCreated.ToDateTimeParamValue()); + statement.TryBind("@DateLastModified", job.DateLastModified.ToDateTimeParamValue()); + + statement.TryBind("@ItemCount", job.ItemCount); + statement.TryBind("@Id", job.Id.ToGuidParamValue()); + + statement.MoveNext(); + } }, TransactionMode); } } diff --git a/MediaBrowser.Providers/TV/Omdb/OmdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/Omdb/OmdbEpisodeProvider.cs index 21e327a8f2..56aa3967c5 100644 --- a/MediaBrowser.Providers/TV/Omdb/OmdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/Omdb/OmdbEpisodeProvider.cs @@ -55,11 +55,15 @@ namespace MediaBrowser.Providers.TV return result; } - if (OmdbProvider.IsValidSeries(info.SeriesProviderIds) && info.IndexNumber.HasValue && info.ParentIndexNumber.HasValue) + string seriesImdbId; + if (info.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out seriesImdbId) && !string.IsNullOrEmpty(seriesImdbId)) { - var seriesImdbId = info.GetProviderId(MetadataProviders.Imdb); - - result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false); + if (info.IndexNumber.HasValue && + info.ParentIndexNumber.HasValue) + { + result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager) + .FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false); + } } return result; -- cgit v1.2.3 From e1da7b80f4e8e64d6aec307e9f093062ca1a7f02 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 23 Dec 2016 12:57:47 -0500 Subject: update cloud sync profile --- Emby.Server.Implementations/Sync/CloudSyncProfile.cs | 16 +--------------- MediaBrowser.Model/Dlna/ConditionProcessor.cs | 13 +++++++------ MediaBrowser.Model/Dlna/StreamBuilder.cs | 7 ++----- 3 files changed, 10 insertions(+), 26 deletions(-) (limited to 'Emby.Server.Implementations/Sync') diff --git a/Emby.Server.Implementations/Sync/CloudSyncProfile.cs b/Emby.Server.Implementations/Sync/CloudSyncProfile.cs index 1a78c8ae66..c0675df817 100644 --- a/Emby.Server.Implementations/Sync/CloudSyncProfile.cs +++ b/Emby.Server.Implementations/Sync/CloudSyncProfile.cs @@ -68,7 +68,7 @@ namespace Emby.Server.Implementations.Sync }, new ProfileCondition { - Condition = ProfileConditionType.EqualsAny, + Condition = ProfileConditionType.Equals, Property = ProfileConditionValue.NumVideoStreams, Value = "1", IsRequired = false @@ -230,20 +230,6 @@ namespace Emby.Server.Implementations.Sync Codec = "aac,mp3", Conditions = new[] { - new ProfileCondition - { - Condition = ProfileConditionType.LessThanEqual, - Property = ProfileConditionValue.AudioChannels, - Value = "2", - IsRequired = true - }, - new ProfileCondition - { - Condition = ProfileConditionType.LessThanEqual, - Property = ProfileConditionValue.AudioBitrate, - Value = "320000", - IsRequired = true - }, new ProfileCondition { Condition = ProfileConditionType.Equals, diff --git a/MediaBrowser.Model/Dlna/ConditionProcessor.cs b/MediaBrowser.Model/Dlna/ConditionProcessor.cs index e9e76a993e..1c11e6a3ca 100644 --- a/MediaBrowser.Model/Dlna/ConditionProcessor.cs +++ b/MediaBrowser.Model/Dlna/ConditionProcessor.cs @@ -124,6 +124,7 @@ namespace MediaBrowser.Model.Dlna switch (condition.Condition) { case ProfileConditionType.Equals: + case ProfileConditionType.EqualsAny: return currentValue.Value.Equals(expected); case ProfileConditionType.GreaterThanEqual: return currentValue.Value >= expected; @@ -132,7 +133,7 @@ namespace MediaBrowser.Model.Dlna case ProfileConditionType.NotEquals: return !currentValue.Value.Equals(expected); default: - throw new InvalidOperationException("Unexpected ProfileConditionType"); + throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition); } } @@ -160,7 +161,7 @@ namespace MediaBrowser.Model.Dlna case ProfileConditionType.NotEquals: return !StringHelper.EqualsIgnoreCase(currentValue, expected); default: - throw new InvalidOperationException("Unexpected ProfileConditionType"); + throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition); } } @@ -182,7 +183,7 @@ namespace MediaBrowser.Model.Dlna case ProfileConditionType.NotEquals: return currentValue.Value != expected; default: - throw new InvalidOperationException("Unexpected ProfileConditionType"); + throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition); } } @@ -211,7 +212,7 @@ namespace MediaBrowser.Model.Dlna case ProfileConditionType.NotEquals: return !currentValue.Value.Equals(expected); default: - throw new InvalidOperationException("Unexpected ProfileConditionType"); + throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition); } } @@ -240,7 +241,7 @@ namespace MediaBrowser.Model.Dlna case ProfileConditionType.NotEquals: return !currentValue.Value.Equals(expected); default: - throw new InvalidOperationException("Unexpected ProfileConditionType"); + throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition); } } @@ -264,7 +265,7 @@ namespace MediaBrowser.Model.Dlna case ProfileConditionType.NotEquals: return timestamp != expected; default: - throw new InvalidOperationException("Unexpected ProfileConditionType"); + throw new InvalidOperationException("Unexpected ProfileConditionType: " + condition.Condition); } } } diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 6d68831ff7..cbbf434ff1 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -410,8 +410,6 @@ namespace MediaBrowser.Model.Dlna audioStreamIndex = audioStream.Index; } - var allMediaStreams = item.MediaStreams; - MediaStream videoStream = item.VideoStream; // TODO: This doesn't accout for situation of device being able to handle media bitrate, but wifi connection not fast enough @@ -427,7 +425,7 @@ namespace MediaBrowser.Model.Dlna if (isEligibleForDirectPlay || isEligibleForDirectStream) { // See if it can be direct played - PlayMethod? directPlay = GetVideoDirectPlayProfile(options, item, videoStream, audioStream, isEligibleForDirectPlay, isEligibleForDirectStream, allMediaStreams); + PlayMethod? directPlay = GetVideoDirectPlayProfile(options, item, videoStream, audioStream, isEligibleForDirectPlay, isEligibleForDirectStream); if (directPlay != null) { @@ -656,8 +654,7 @@ namespace MediaBrowser.Model.Dlna MediaStream videoStream, MediaStream audioStream, bool isEligibleForDirectPlay, - bool isEligibleForDirectStream, - List allMediaStreams) + bool isEligibleForDirectStream) { DeviceProfile profile = options.Profile; -- cgit v1.2.3 From a1acc0c1619bcb4d7e6720edb1e9d5775eb23713 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 27 Dec 2016 14:34:27 -0500 Subject: resolve sync failure --- Emby.Server.Implementations/Sync/SyncRepository.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'Emby.Server.Implementations/Sync') diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index 6d4fce3997..ad4222ba6a 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -244,14 +244,7 @@ namespace Emby.Server.Implementations.Sync statement.TryBind("@Progress", job.Progress); statement.TryBind("@UserId", job.UserId); - if (job.RequestedItemIds.Count > 0) - { - statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); - } - else - { - statement.TryBindNull("@ItemIds"); - } + statement.TryBind("@ItemIds", string.Join(",", job.RequestedItemIds.ToArray())); if (job.Category.HasValue) { -- cgit v1.2.3 From 28bbe32d1dc50ce7ad199f50acb5b2b4791b1b4c Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 28 Dec 2016 03:16:21 -0500 Subject: update sync cancellation --- Emby.Server.Implementations/Sync/SyncManager.cs | 12 ++++++++++++ Emby.Server.Implementations/Sync/SyncRepository.cs | 5 +++++ MediaBrowser.Model/Sync/SyncJobQuery.cs | 1 + 3 files changed, 18 insertions(+) (limited to 'Emby.Server.Implementations/Sync') diff --git a/Emby.Server.Implementations/Sync/SyncManager.cs b/Emby.Server.Implementations/Sync/SyncManager.cs index 061129e5f9..d3b6b33a27 100644 --- a/Emby.Server.Implementations/Sync/SyncManager.cs +++ b/Emby.Server.Implementations/Sync/SyncManager.cs @@ -1030,6 +1030,18 @@ namespace Emby.Server.Implementations.Sync { await CancelJobItem(jobItem.Id).ConfigureAwait(false); } + + var syncJobResult = await GetJobs(new SyncJobQuery + { + ItemId = item, + TargetId = targetId + + }).ConfigureAwait(false); + + foreach (var job in syncJobResult.Items) + { + await CancelJob(job.Id).ConfigureAwait(false); + } } } diff --git a/Emby.Server.Implementations/Sync/SyncRepository.cs b/Emby.Server.Implementations/Sync/SyncRepository.cs index ad4222ba6a..aafce3500f 100644 --- a/Emby.Server.Implementations/Sync/SyncRepository.cs +++ b/Emby.Server.Implementations/Sync/SyncRepository.cs @@ -360,6 +360,11 @@ namespace Emby.Server.Implementations.Sync whereClauses.Add("UserId=?"); paramList.Add(query.UserId); } + if (!string.IsNullOrWhiteSpace(query.ItemId)) + { + whereClauses.Add("ItemIds like ?"); + paramList.Add("%" + query.ItemId + "%"); + } if (query.SyncNewContent.HasValue) { whereClauses.Add("SyncNewContent=?"); diff --git a/MediaBrowser.Model/Sync/SyncJobQuery.cs b/MediaBrowser.Model/Sync/SyncJobQuery.cs index bb99b5d5f3..ed9e5ae605 100644 --- a/MediaBrowser.Model/Sync/SyncJobQuery.cs +++ b/MediaBrowser.Model/Sync/SyncJobQuery.cs @@ -24,6 +24,7 @@ namespace MediaBrowser.Model.Sync /// The user identifier. public string UserId { get; set; } public string ExcludeTargetIds { get; set; } + public string ItemId { get; set; } /// /// Gets or sets the status. /// -- cgit v1.2.3 From 5e4bf3c36f31bc60a547937b107d0bb61968b9d6 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 28 Dec 2016 14:56:16 -0500 Subject: add sync error handling --- Emby.Server.Implementations/Sync/SyncJobProcessor.cs | 10 +++++++++- Emby.Server.Implementations/Sync/SyncManager.cs | 5 ----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'Emby.Server.Implementations/Sync') diff --git a/Emby.Server.Implementations/Sync/SyncJobProcessor.cs b/Emby.Server.Implementations/Sync/SyncJobProcessor.cs index 415757609d..b1adc64df6 100644 --- a/Emby.Server.Implementations/Sync/SyncJobProcessor.cs +++ b/Emby.Server.Implementations/Sync/SyncJobProcessor.cs @@ -515,8 +515,14 @@ namespace Emby.Server.Implementations.Sync jobItem.Progress = 0; - var syncOptions = _config.GetSyncOptions(); var job = _syncManager.GetJob(jobItem.JobId); + if (job == null) + { + _logger.Error("Job not found. Cannot complete the sync job."); + await _syncManager.CancelJobItem(jobItem.Id).ConfigureAwait(false); + return; + } + var user = _userManager.GetUserById(job.UserId); if (user == null) { @@ -552,6 +558,8 @@ namespace Emby.Server.Implementations.Sync } } + var syncOptions = _config.GetSyncOptions(); + var video = item as Video; if (video != null) { diff --git a/Emby.Server.Implementations/Sync/SyncManager.cs b/Emby.Server.Implementations/Sync/SyncManager.cs index d3b6b33a27..310b35afe3 100644 --- a/Emby.Server.Implementations/Sync/SyncManager.cs +++ b/Emby.Server.Implementations/Sync/SyncManager.cs @@ -1049,11 +1049,6 @@ namespace Emby.Server.Implementations.Sync { var jobItem = _repo.GetJobItem(id); - if (jobItem.Status != SyncJobItemStatus.Queued && jobItem.Status != SyncJobItemStatus.ReadyToTransfer && jobItem.Status != SyncJobItemStatus.Converting && jobItem.Status != SyncJobItemStatus.Failed && jobItem.Status != SyncJobItemStatus.Synced && jobItem.Status != SyncJobItemStatus.Transferring) - { - throw new ArgumentException("Operation is not valid for this job item"); - } - jobItem.Status = SyncJobItemStatus.Cancelled; jobItem.Progress = 0; -- cgit v1.2.3