mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-15 20:20:25 +01:00
Merge pull request #17074 from jellyfin/renovate/sharpcompress-0.x
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
Format / format-check (push) Waiting to run
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
OpenAPI Publish / OpenAPI - Publish Artifact (push) Waiting to run
OpenAPI Publish / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI Publish / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / main (push) Waiting to run
Some checks are pending
CodeQL / Analyze (csharp) (push) Waiting to run
Format / format-check (push) Waiting to run
Tests / run-tests (macos-latest) (push) Waiting to run
Tests / run-tests (ubuntu-latest) (push) Waiting to run
Tests / run-tests (windows-latest) (push) Waiting to run
OpenAPI Publish / OpenAPI - Publish Artifact (push) Waiting to run
OpenAPI Publish / OpenAPI - Publish Unstable Spec (push) Blocked by required conditions
OpenAPI Publish / OpenAPI - Publish Stable Spec (push) Blocked by required conditions
Project Automation / Project board (push) Waiting to run
Merge Conflict Labeler / main (push) Waiting to run
Update dependency SharpCompress to 0.49.1
This commit is contained in:
@@ -67,7 +67,7 @@
|
||||
<PackageVersion Include="Serilog.Sinks.File" Version="7.0.0" />
|
||||
<PackageVersion Include="Serilog.Sinks.Graylog" Version="3.1.1" />
|
||||
<PackageVersion Include="SerilogAnalyzer" Version="0.15.0" />
|
||||
<PackageVersion Include="SharpCompress" Version="0.38.0" />
|
||||
<PackageVersion Include="SharpCompress" Version="0.49.1" />
|
||||
<PackageVersion Include="SharpFuzz" Version="2.2.0" />
|
||||
<PackageVersion Include="SkiaSharp" Version="3.119.4" />
|
||||
<PackageVersion Include="SkiaSharp.HarfBuzz" Version="3.119.4" />
|
||||
|
||||
@@ -49,24 +49,26 @@ public class ComicBookInfoProvider : IComicProvider
|
||||
try
|
||||
{
|
||||
Stream stream = AsyncFile.OpenRead(path);
|
||||
|
||||
await using (stream.ConfigureAwait(false))
|
||||
await using (var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Read, false, null, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (archive.Comment is null)
|
||||
var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Read, false, null, cancellationToken).ConfigureAwait(false);
|
||||
await using (archive.ConfigureAwait(false))
|
||||
{
|
||||
_logger.LogInformation("missing ComicBookInfo in archive comment: {Path}", info.Path);
|
||||
return new MetadataResult<Book> { HasMetadata = false };
|
||||
}
|
||||
if (archive.Comment is null)
|
||||
{
|
||||
_logger.LogInformation("missing ComicBookInfo in archive comment: {Path}", info.Path);
|
||||
return new MetadataResult<Book> { HasMetadata = false };
|
||||
}
|
||||
|
||||
var comicBookMetadata = JsonSerializer.Deserialize<ComicBookInfoFormat>(archive.Comment, JsonDefaults.Options);
|
||||
if (comicBookMetadata is null)
|
||||
{
|
||||
_logger.LogError("ComicBookInfo deserialization failure: {Path}", info.Path);
|
||||
return new MetadataResult<Book> { HasMetadata = false };
|
||||
}
|
||||
var comicBookMetadata = JsonSerializer.Deserialize<ComicBookInfoFormat>(archive.Comment, JsonDefaults.Options);
|
||||
if (comicBookMetadata is null)
|
||||
{
|
||||
_logger.LogError("ComicBookInfo deserialization failure: {Path}", info.Path);
|
||||
return new MetadataResult<Book> { HasMetadata = false };
|
||||
}
|
||||
|
||||
return SaveMetadata(comicBookMetadata);
|
||||
return SaveMetadata(comicBookMetadata);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -9,6 +9,7 @@ using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Drawing;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharpCompress.Archives;
|
||||
|
||||
@@ -38,16 +39,16 @@ public class ComicImageProvider : IDynamicImageProvider
|
||||
public string Name => "Comic Book Archive Cover Extractor";
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<DynamicImageResponse> GetImage(BaseItem item, ImageType type, CancellationToken cancellationToken)
|
||||
public async Task<DynamicImageResponse> GetImage(BaseItem item, ImageType type, CancellationToken cancellationToken)
|
||||
{
|
||||
var extension = Path.GetExtension(item.Path);
|
||||
|
||||
if (_comicBookExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return LoadCover(item);
|
||||
return await LoadCoverAsync(item, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
return Task.FromResult(new DynamicImageResponse { HasImage = false });
|
||||
return new DynamicImageResponse { HasImage = false };
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -67,7 +68,8 @@ public class ComicImageProvider : IDynamicImageProvider
|
||||
/// with no image if nothing is found.
|
||||
/// </summary>
|
||||
/// <param name="item">Item to check for covers.</param>
|
||||
private async Task<DynamicImageResponse> LoadCover(BaseItem item)
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
private async Task<DynamicImageResponse> LoadCoverAsync(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
var memoryStream = new MemoryStream();
|
||||
|
||||
@@ -75,14 +77,22 @@ public class ComicImageProvider : IDynamicImageProvider
|
||||
{
|
||||
ImageFormat imageFormat;
|
||||
|
||||
using (Stream stream = File.OpenRead(item.Path))
|
||||
using (var archive = ArchiveFactory.Open(stream))
|
||||
using (Stream stream = AsyncFile.OpenRead(item.Path))
|
||||
{
|
||||
// throw exception to log results if no cover is found
|
||||
(var cover, imageFormat) = FindCoverEntryInArchive(archive) ?? throw new InvalidOperationException("no supported cover found");
|
||||
var archive = await ArchiveFactory.OpenAsyncArchive(stream, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
await using (archive.ConfigureAwait(false))
|
||||
{
|
||||
// throw exception to log results if no cover is found
|
||||
(var cover, imageFormat) = await FindCoverEntryInArchiveAsync(archive).ConfigureAwait(false)
|
||||
?? throw new InvalidOperationException("no supported cover found");
|
||||
|
||||
// copy the cover to memory stream
|
||||
await cover.OpenEntryStream().CopyToAsync(memoryStream).ConfigureAwait(false);
|
||||
// copy the cover to memory stream
|
||||
var coverStream = await cover.OpenEntryStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
await using (coverStream.ConfigureAwait(false))
|
||||
{
|
||||
await coverStream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reset stream position after copying
|
||||
@@ -102,7 +112,7 @@ public class ComicImageProvider : IDynamicImageProvider
|
||||
/// </summary>
|
||||
/// <param name="archive">The archive to search.</param>
|
||||
/// <returns>The search result.</returns>
|
||||
private (IArchiveEntry CoverEntry, ImageFormat ImageFormat)? FindCoverEntryInArchive(IArchive archive)
|
||||
private async ValueTask<(IArchiveEntry CoverEntry, ImageFormat ImageFormat)?> FindCoverEntryInArchiveAsync(IAsyncArchive archive)
|
||||
{
|
||||
IArchiveEntry? cover;
|
||||
|
||||
@@ -110,7 +120,7 @@ public class ComicImageProvider : IDynamicImageProvider
|
||||
// in many cases the cover will simply be the first image in the archive
|
||||
foreach (var extension in _coverExtensions)
|
||||
{
|
||||
cover = archive.Entries.FirstOrDefault(e => e.Key == "cover" + extension);
|
||||
cover = await archive.EntriesAsync.FirstOrDefaultAsync(e => e.Key == "cover" + extension).ConfigureAwait(false);
|
||||
|
||||
if (cover is not null)
|
||||
{
|
||||
@@ -120,7 +130,9 @@ public class ComicImageProvider : IDynamicImageProvider
|
||||
}
|
||||
}
|
||||
|
||||
cover = archive.Entries.OrderBy(x => x.Key).FirstOrDefault(x => _coverExtensions.Contains(Path.GetExtension(x.Key), StringComparison.OrdinalIgnoreCase));
|
||||
cover = await archive.EntriesAsync.OrderBy(x => x.Key)
|
||||
.FirstOrDefaultAsync(x => _coverExtensions.Contains(Path.GetExtension(x.Key), StringComparison.OrdinalIgnoreCase))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
if (cover is not null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user