AudioBook playback now working as desired.

pull/11517/head
Samson50 3 weeks ago
parent 3ae08b4f06
commit bfff862ed2

@ -729,7 +729,9 @@ namespace Emby.Naming.Common
// Sometimes named as 0001_005 (chapter_part)
"(?<chapter>[0-9]+)_(?<part>[0-9]+)",
// Some audiobooks are ripped from cd's, and will be named by disk number.
@"dis(?:c|k)[\s_-]?(?<chapter>[0-9]+)"
@"dis(?:c|k)[\s_-]?(?<chapter>[0-9]+)",
// Use number at end of file name before extension
"[0-9]+$"
};
AudioBookNamesExpressions = new[]

@ -407,6 +407,7 @@ namespace Emby.Server.Implementations.Dto
}
else
{
// TODO: Why is this here? Seems redundant
if (options.EnableUserData)
{
dto.UserData = _userDataRepository.GetUserDataDto(item, user);

@ -289,15 +289,11 @@ namespace Emby.Server.Implementations.Library
}
else if (positionTicks > 0 && hasRuntime && item is AudioBookFile)
{
var playbackPositionInMinutes = TimeSpan.FromTicks(positionTicks).TotalMinutes;
var remainingTimeInMinutes = TimeSpan.FromTicks(runtimeTicks - positionTicks).TotalMinutes;
data.Played = playedToCompletion = false;
if (playbackPositionInMinutes < _config.Configuration.MinAudiobookResume)
{
// ignore progress during the beginning
positionTicks = 0;
}
else if (remainingTimeInMinutes < _config.Configuration.MaxAudiobookResume || positionTicks >= runtimeTicks)
// TODO: Use percentage of total runtime ticks for completion comparison
if (remainingTimeInMinutes < _config.Configuration.MaxAudiobookResume || positionTicks >= runtimeTicks)
{
// mark as completed close to the end
positionTicks = 0;

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using Jellyfin.Api.Extensions;
@ -9,6 +10,7 @@ using Jellyfin.Extensions;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.AudioBooks;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dto;
@ -516,10 +518,25 @@ public class ItemsController : BaseJellyfinApiController
result = new QueryResult<BaseItem>(itemsArray);
}
return new QueryResult<BaseItemDto>(
var queryResult = new QueryResult<BaseItemDto>(
startIndex,
result.TotalRecordCount,
_dtoService.GetBaseItemDtos(result.Items, dtoOptions, user));
// TODO: Sort return items by chapter for audio book
if (item is AudioBook)
{
for (int i = 0; i < queryResult.Items.Count; i++)
{
if (!queryResult.Items[i].UserData.Played)
{
queryResult.StartIndex = i;
break;
}
}
}
return queryResult;
}
/// <summary>

@ -160,17 +160,7 @@ namespace MediaBrowser.Controller.Entities.AudioBooks
protected override IEnumerable<(BaseItem Item, MediaSourceType MediaSourceType)> GetAllItemsForMediaSources()
{
var chapters = AudioBookEntity.Chapters;
var nextChapters = new List<(BaseItem Item, MediaSourceType MediaSourceType)>();
foreach (var chapter in chapters)
{
if (chapter.Chapter >= this.Chapter)
{
nextChapters.Add((chapter, MediaSourceType.Default));
}
}
return nextChapters;
return [(this, MediaSourceType.Default)];
}
}
}

@ -150,13 +150,13 @@ public class ServerConfiguration : BaseApplicationConfiguration
/// Gets or sets the minimum minutes of a book that must be played in order for playstate to be updated.
/// </summary>
/// <value>The min resume in minutes.</value>
public int MinAudiobookResume { get; set; } = 5;
public int MinAudiobookResume { get; set; } = 0;
/// <summary>
/// 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.
/// </summary>
/// <value>The remaining time in minutes.</value>
public int MaxAudiobookResume { get; set; } = 5;
public int MaxAudiobookResume { get; set; } = 1;
/// <summary>
/// Gets or sets the threshold in minutes after a inactive session gets closed automatically.

Loading…
Cancel
Save