aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Server.Implementations/Item/ChapterManager.cs
diff options
context:
space:
mode:
authorJPVenson <JPVenson@users.noreply.github.com>2024-09-08 16:56:14 +0000
committerGitHub <noreply@github.com>2024-09-08 16:56:14 +0000
commitee1bdf4e222125ed7382165fd7e09599ca4bd4aa (patch)
tree78b1e180c2626ccfc483f8bff9ec861079a6d8e6 /Jellyfin.Server.Implementations/Item/ChapterManager.cs
parentd0b4b2ddb31a54f0705303ab8461be1125d66eab (diff)
WIP move baseitem to jellyfin.db
Diffstat (limited to 'Jellyfin.Server.Implementations/Item/ChapterManager.cs')
-rw-r--r--Jellyfin.Server.Implementations/Item/ChapterManager.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/Jellyfin.Server.Implementations/Item/ChapterManager.cs b/Jellyfin.Server.Implementations/Item/ChapterManager.cs
new file mode 100644
index 000000000..273cc96ba
--- /dev/null
+++ b/Jellyfin.Server.Implementations/Item/ChapterManager.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Jellyfin.Data.Entities;
+using MediaBrowser.Model.Entities;
+using Microsoft.EntityFrameworkCore;
+using BaseItemDto = MediaBrowser.Controller.Entities.BaseItem;
+
+namespace Jellyfin.Server.Implementations.Item;
+
+public class ChapterManager
+{
+ private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
+
+ public ChapterManager(IDbContextFactory<JellyfinDbContext> dbProvider)
+ {
+ _dbProvider = dbProvider;
+ }
+
+ public IReadOnlyList<ChapterInfo> GetChapters(BaseItemDto baseItemDto)
+ {
+ using var context = _dbProvider.CreateDbContext();
+ return context.Chapters.Where(e => e.ItemId.Equals(baseItemDto.Id)).Select(Map).ToList();
+ }
+
+ private Chapter Map(ChapterInfo chapterInfo, int index, Guid itemId)
+ {
+ return new Chapter()
+ {
+ ChapterIndex = index,
+ StartPositionTicks = chapterInfo.StartPositionTicks,
+ ImageDateModified = chapterInfo.ImageDateModified,
+ ImagePath = chapterInfo.ImagePath,
+ ItemId = itemId,
+ Name = chapterInfo.Name
+ };
+ }
+
+ private ChapterInfo Map(Chapter chapterInfo, BaseItemDto baseItem)
+ {
+ var info = new ChapterInfo()
+ {
+ StartPositionTicks = chapterInfo.StartPositionTicks,
+ ImageDateModified = chapterInfo.ImageDateModified.GetValueOrDefault(),
+ ImagePath = chapterInfo.ImagePath,
+ Name = chapterInfo.Name,
+ };
+ info.ImageTag = _imageProcessor.GetImageCacheTag(baseItem, info);
+ return info;
+ }
+}