diff --git a/CHANGELOG.md b/CHANGELOG.md index e71aaab09..fd69ced18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix bug where multiple Plex servers would mix their episodes - Fix incorrect media item counts after removing paths from local libraries - Fix song playback in playback troubleshooting +- Fix seeking into extracted text subtitles ### Changed - Allow multiple watermarks in playback troubleshooting @@ -2719,4 +2720,4 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). [0.0.5-prealpha]: https://github.com/ErsatzTV/ErsatzTV/compare/v0.0.4-prealpha...v0.0.5-prealpha [0.0.4-prealpha]: https://github.com/ErsatzTV/ErsatzTV/compare/v0.0.3-prealpha...v0.0.4-prealpha [0.0.3-prealpha]: https://github.com/ErsatzTV/ErsatzTV/compare/v0.0.1-prealpha...v0.0.3-prealpha -[0.0.1-prealpha]: https://github.com/ErsatzTV/ErsatzTV/releases/tag/v0.0.1-prealpha \ No newline at end of file +[0.0.1-prealpha]: https://github.com/ErsatzTV/ErsatzTV/releases/tag/v0.0.1-prealpha diff --git a/ErsatzTV.Application/Subtitles/Queries/GetSubtitlePathByIdHandler.cs b/ErsatzTV.Application/Subtitles/Queries/GetSubtitlePathByIdHandler.cs index a1e5ed526..0a3cad011 100644 --- a/ErsatzTV.Application/Subtitles/Queries/GetSubtitlePathByIdHandler.cs +++ b/ErsatzTV.Application/Subtitles/Queries/GetSubtitlePathByIdHandler.cs @@ -8,43 +8,48 @@ using Microsoft.EntityFrameworkCore; namespace ErsatzTV.Application.Subtitles.Queries; -public class GetSubtitlePathByIdHandler : IRequestHandler> +public class GetSubtitlePathByIdHandler(IDbContextFactory dbContextFactory) + : IRequestHandler> { - private readonly IDbContextFactory _dbContextFactory; - - public GetSubtitlePathByIdHandler(IDbContextFactory dbContextFactory) => - _dbContextFactory = dbContextFactory; - public async Task> Handle( GetSubtitlePathById request, CancellationToken cancellationToken) { - await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); Option maybeSubtitle = await dbContext.Subtitles + .AsNoTracking() .SelectOneAsync(s => s.Id, s => s.Id == request.Id); - foreach (string plexUrl in await GetPlexUrl(request, dbContext, maybeSubtitle)) + foreach (var subtitle in maybeSubtitle) { - return plexUrl; - } + if (subtitle is { SubtitleKind: SubtitleKind.Embedded, IsExtracted: true }) + { + return Path.Combine(FileSystemLayout.SubtitleCacheFolder, subtitle.Path); + } - foreach (string jellyfinUrl in await GetJellyfinUrl(request, dbContext, maybeSubtitle)) - { - return jellyfinUrl; - } + foreach (string plexUrl in await GetPlexUrl(request.Id, dbContext, maybeSubtitle)) + { + return plexUrl; + } - foreach (string embyUrl in await GetEmbyUrl(request, dbContext, maybeSubtitle)) - { - return embyUrl; + foreach (string jellyfinUrl in await GetJellyfinUrl(request.Id, dbContext, maybeSubtitle)) + { + return jellyfinUrl; + } + + foreach (string embyUrl in await GetEmbyUrl(request.Id, dbContext, maybeSubtitle)) + { + return embyUrl; + } + + return subtitle.Path; } - return maybeSubtitle - .Map(s => s.Path) - .ToEither(BaseError.New($"Unable to locate subtitle with id {request.Id}")); + return BaseError.New($"Unable to locate subtitle with id {request.Id}"); } - private static async Task> GetPlexUrl( - GetSubtitlePathById request, + protected static async Task> GetPlexUrl( + int subtitleId, TvContext dbContext, Option maybeSubtitle) { @@ -57,7 +62,7 @@ public class GetSubtitlePathByIdHandler : IRequestHandler.None; } - private static async Task> GetJellyfinUrl( - GetSubtitlePathById request, + protected static async Task> GetJellyfinUrl( + int subtitleId, TvContext dbContext, Option maybeSubtitle) { @@ -97,7 +102,7 @@ public class GetSubtitlePathByIdHandler : IRequestHandler.None; } - private static async Task> GetEmbyUrl( - GetSubtitlePathById request, + protected static async Task> GetEmbyUrl( + int subtitleId, TvContext dbContext, Option maybeSubtitle) { @@ -138,7 +143,7 @@ public class GetSubtitlePathByIdHandler : IRequestHandler videoPath, - false when subtitle.SubtitleKind == SubtitleKind.Sidecar => subtitle.Path, - _ => Path.Combine(FileSystemLayout.SubtitleCacheFolder, subtitle.Path) - }; + string path = subtitle.IsImage ? videoPath : subtitle.Path; SubtitleMethod method = SubtitleMethod.Burn; if (channel.StreamingMode == StreamingMode.HttpLiveStreamingDirect)