浏览代码

Split resume function for Audiobooks

artiume 4 年之前
父节点
当前提交
99adbf0497
共有 1 个文件被更改,包括 20 次插入1 次删除
  1. 20 1
      Emby.Server.Implementations/Library/UserDataManager.cs

+ 20 - 1
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