From 99adbf04975dcb233b49ea9f3eead358dd4d39fa Mon Sep 17 00:00:00 2001 From: artiume Date: Wed, 30 Dec 2020 08:48:33 -0500 Subject: [PATCH 1/5] Split resume function for Audiobooks --- .../Library/UserDataManager.cs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs index f9e5e6bbc..df8c6adfa 100644 --- a/Emby.Server.Implementations/Library/UserDataManager.cs +++ b/Emby.Server.Implementations/Library/UserDataManager.cs @@ -14,6 +14,7 @@ using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using Book = MediaBrowser.Controller.Entities.Book; +using AudioBook = MediaBrowser.Controller.Entities.AudioBook; namespace Emby.Server.Implementations.Library { @@ -219,7 +220,7 @@ namespace Emby.Server.Implementations.Library var hasRuntime = runtimeTicks > 0; // If a position has been reported, and if we know the duration - if (positionTicks > 0 && hasRuntime) + if (positionTicks > 0 && hasRuntime && !(item is AudioBook)) { var pctIn = decimal.Divide(positionTicks, runtimeTicks) * 100; @@ -245,6 +246,24 @@ namespace Emby.Server.Implementations.Library } } } + else if (positionTicks > 0 && hasRuntime && (item is AudioBook)) + { + var minIn = TimeSpan.FromTicks(positionTicks).TotalSeconds / 60; + // 10,000 ticks per millisecond * 60,000 milliseconds per minute = 600,000,000 ticks per minute + var minOut = (runtimeTicks - positionTicks) / 600000000; + + if (minIn > _config.Configuration.MinAudiobookResume) + { + // ignore progress during the beginning + positionTicks = 0; + } + else if (minOut < _config.Configuration.MaxAudiobookResume || positionTicks >= runtimeTicks) + { + // mark as completed close to the end + positionTicks = 0; + data.Played = playedToCompletion = true; + } + } else if (!hasRuntime) { // If we don't know the runtime we'll just have to assume it was fully played From cd979e6b6291d426f3e180e36b5a8ba68c208cbd Mon Sep 17 00:00:00 2001 From: artiume Date: Wed, 30 Dec 2020 08:52:11 -0500 Subject: [PATCH 2/5] Add default of 5 minutes --- .../Configuration/ServerConfiguration.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 7013cb300..9fb978e9b 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -298,6 +298,18 @@ namespace MediaBrowser.Model.Configuration /// The min resume duration seconds. public int MinResumeDurationSeconds { get; set; } = 300; + /// + /// Gets or sets the minimum minutes of a book that must be played in order for playstate to be updated. + /// + /// The min resume in minutes. + public int MinAudiobookResume { get; set; } = 5; + + /// + /// Gets or sets the remaining minutes of a book that can be played while still saving playstate. If this percentage is crossed playstate will be reset to the beginning and the item will be marked watched. + /// + /// The remaining time in minutes. + public int MaxAudiobookResume { get; set; } = 5; + /// /// Gets or sets the delay in seconds that we will wait after a file system change to try and discover what has been added/removed /// Some delay is necessary with some items because their creation is not atomic. It involves the creation of several From 77b478c726df8012e8eb27ee59f3bd937848a661 Mon Sep 17 00:00:00 2001 From: artiume Date: Wed, 30 Dec 2020 09:12:13 -0500 Subject: [PATCH 3/5] Update Emby.Server.Implementations/Library/UserDataManager.cs Co-authored-by: Bond-009 --- Emby.Server.Implementations/Library/UserDataManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs index df8c6adfa..1b38f5e0e 100644 --- a/Emby.Server.Implementations/Library/UserDataManager.cs +++ b/Emby.Server.Implementations/Library/UserDataManager.cs @@ -248,7 +248,7 @@ namespace Emby.Server.Implementations.Library } else if (positionTicks > 0 && hasRuntime && (item is AudioBook)) { - var minIn = TimeSpan.FromTicks(positionTicks).TotalSeconds / 60; + var minIn = TimeSpan.FromTicks(positionTicks).TotalMinutes; // 10,000 ticks per millisecond * 60,000 milliseconds per minute = 600,000,000 ticks per minute var minOut = (runtimeTicks - positionTicks) / 600000000; From c7cb177260e80859d18e40615673dc2b7afeda9c Mon Sep 17 00:00:00 2001 From: artiume Date: Wed, 30 Dec 2020 09:12:36 -0500 Subject: [PATCH 4/5] Update Emby.Server.Implementations/Library/UserDataManager.cs Co-authored-by: Bond-009 --- Emby.Server.Implementations/Library/UserDataManager.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs index 1b38f5e0e..415e20710 100644 --- a/Emby.Server.Implementations/Library/UserDataManager.cs +++ b/Emby.Server.Implementations/Library/UserDataManager.cs @@ -249,8 +249,7 @@ namespace Emby.Server.Implementations.Library else if (positionTicks > 0 && hasRuntime && (item is AudioBook)) { var minIn = TimeSpan.FromTicks(positionTicks).TotalMinutes; - // 10,000 ticks per millisecond * 60,000 milliseconds per minute = 600,000,000 ticks per minute - var minOut = (runtimeTicks - positionTicks) / 600000000; + var minOut = TimeSpan.FromTicks(runtimeTicks - positionTicks).TotalMinutes; if (minIn > _config.Configuration.MinAudiobookResume) { From f411353c8ca27eb17db4258d400a38721041c9a2 Mon Sep 17 00:00:00 2001 From: artiume Date: Wed, 30 Dec 2020 09:30:02 -0500 Subject: [PATCH 5/5] Update Emby.Server.Implementations/Library/UserDataManager.cs Co-authored-by: Bond-009 --- Emby.Server.Implementations/Library/UserDataManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/Library/UserDataManager.cs b/Emby.Server.Implementations/Library/UserDataManager.cs index 415e20710..d16275b19 100644 --- a/Emby.Server.Implementations/Library/UserDataManager.cs +++ b/Emby.Server.Implementations/Library/UserDataManager.cs @@ -246,7 +246,7 @@ namespace Emby.Server.Implementations.Library } } } - else if (positionTicks > 0 && hasRuntime && (item is AudioBook)) + else if (positionTicks > 0 && hasRuntime && item is AudioBook) { var minIn = TimeSpan.FromTicks(positionTicks).TotalMinutes; var minOut = TimeSpan.FromTicks(runtimeTicks - positionTicks).TotalMinutes;