Merge pull request #13847 from Shadowghost/rework-chapter-management

Rework chapter management
This commit is contained in:
Tim Eisele
2025-04-26 14:01:12 +02:00
committed by GitHub
parent f35b8dd33d
commit df5671263f
15 changed files with 447 additions and 395 deletions

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Chapters;
/// <summary>
/// Interface IChapterManager.
/// </summary>
public interface IChapterManager
{
/// <summary>
/// Saves the chapters.
/// </summary>
/// <param name="video">The video.</param>
/// <param name="chapters">The set of chapters.</param>
void SaveChapters(Video video, IReadOnlyList<ChapterInfo> chapters);
/// <summary>
/// Gets a single chapter of a BaseItem on a specific index.
/// </summary>
/// <param name="baseItemId">The BaseItems id.</param>
/// <param name="index">The index of that chapter.</param>
/// <returns>A chapter instance.</returns>
ChapterInfo? GetChapter(Guid baseItemId, int index);
/// <summary>
/// Gets all chapters associated with the baseItem.
/// </summary>
/// <param name="baseItemId">The BaseItems id.</param>
/// <returns>A readonly list of chapter instances.</returns>
IReadOnlyList<ChapterInfo> GetChapters(Guid baseItemId);
/// <summary>
/// Refreshes the chapter images.
/// </summary>
/// <param name="video">Video to use.</param>
/// <param name="directoryService">Directory service to use.</param>
/// <param name="chapters">Set of chapters to refresh.</param>
/// <param name="extractImages">Option to extract images.</param>
/// <param name="saveChapters">Option to save chapters.</param>
/// <param name="cancellationToken">CancellationToken to use for operation.</param>
/// <returns><c>true</c> if successful, <c>false</c> if not.</returns>
Task<bool> RefreshChapterImages(Video video, IDirectoryService directoryService, IReadOnlyList<ChapterInfo> chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken);
/// <summary>
/// Deletes the chapter images.
/// </summary>
/// <param name="video">Video to use.</param>
void DeleteChapterImages(Video video);
}

View File

@@ -34,7 +34,6 @@ using MediaBrowser.Model.IO;
using MediaBrowser.Model.Library;
using MediaBrowser.Model.LiveTv;
using MediaBrowser.Model.MediaInfo;
using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Controller.Entities
@@ -484,7 +483,7 @@ namespace MediaBrowser.Controller.Entities
public static IItemRepository ItemRepository { get; set; }
public static IChapterRepository ChapterRepository { get; set; }
public static IChapterManager ChapterManager { get; set; }
public static IFileSystem FileSystem { get; set; }
@@ -2051,7 +2050,7 @@ namespace MediaBrowser.Controller.Entities
{
if (imageType == ImageType.Chapter)
{
var chapter = ChapterRepository.GetChapter(this.Id, imageIndex);
var chapter = ChapterManager.GetChapter(Id, imageIndex);
if (chapter is null)
{
@@ -2101,7 +2100,7 @@ namespace MediaBrowser.Controller.Entities
if (image.Type == ImageType.Chapter)
{
var chapters = ChapterRepository.GetChapters(this.Id);
var chapters = ChapterManager.GetChapters(Id);
for (var i = 0; i < chapters.Count; i++)
{
if (chapters[i].ImagePath == image.Path)

View File

@@ -1,5 +1,4 @@
using MediaBrowser.Controller.Entities;
using MediaBrowser.Model.Dto;
namespace MediaBrowser.Controller.IO;
@@ -46,4 +45,19 @@ public interface IPathManager
/// <param name="mediaSourceId">The media source id.</param>
/// <returns>The absolute path.</returns>
public string GetAttachmentFolderPath(string mediaSourceId);
/// <summary>
/// Gets the chapter images data path.
/// </summary>
/// <param name="item">The base item.</param>
/// <returns>The chapter images data path.</returns>
public string GetChapterImageFolderPath(BaseItem item);
/// <summary>
/// Gets the chapter images path.
/// </summary>
/// <param name="item">The base item.</param>
/// <param name="chapterPositionTicks">The chapter position.</param>
/// <returns>The chapter images data path.</returns>
public string GetChapterImagePath(BaseItem item, long chapterPositionTicks);
}

View File

@@ -1,28 +0,0 @@
#nullable disable
#pragma warning disable CS1591
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.MediaEncoding
{
public interface IEncodingManager
{
/// <summary>
/// Refreshes the chapter images.
/// </summary>
/// <param name="video">Video to use.</param>
/// <param name="directoryService">Directory service to use.</param>
/// <param name="chapters">Set of chapters to refresh.</param>
/// <param name="extractImages">Option to extract images.</param>
/// <param name="saveChapters">Option to save chapters.</param>
/// <param name="cancellationToken">CancellationToken to use for operation.</param>
/// <returns><c>true</c> if successful, <c>false</c> if not.</returns>
Task<bool> RefreshChapterImages(Video video, IDirectoryService directoryService, IReadOnlyList<ChapterInfo> chapters, bool extractImages, bool saveChapters, CancellationToken cancellationToken);
}
}

View File

@@ -1,15 +1,20 @@
using System;
using System.Collections.Generic;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.Chapters;
namespace MediaBrowser.Controller.Persistence;
/// <summary>
/// Interface IChapterManager.
/// Interface IChapterRepository.
/// </summary>
public interface IChapterRepository
{
/// <summary>
/// Deletes the chapters.
/// </summary>
/// <param name="itemId">The item.</param>
void DeleteChapters(Guid itemId);
/// <summary>
/// Saves the chapters.
/// </summary>
@@ -17,21 +22,6 @@ public interface IChapterRepository
/// <param name="chapters">The set of chapters.</param>
void SaveChapters(Guid itemId, IReadOnlyList<ChapterInfo> chapters);
/// <summary>
/// Gets all chapters associated with the baseItem.
/// </summary>
/// <param name="baseItem">The baseitem.</param>
/// <returns>A readonly list of chapter instances.</returns>
IReadOnlyList<ChapterInfo> GetChapters(BaseItemDto baseItem);
/// <summary>
/// Gets a single chapter of a BaseItem on a specific index.
/// </summary>
/// <param name="baseItem">The baseitem.</param>
/// <param name="index">The index of that chapter.</param>
/// <returns>A chapter instance.</returns>
ChapterInfo? GetChapter(BaseItemDto baseItem, int index);
/// <summary>
/// Gets all chapters associated with the baseItem.
/// </summary>