mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-16 04:30:24 +01:00
Replace usage of SharpCompress
ComicImageProvider is the last user of SharpCompress after this PR
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
@@ -12,7 +13,6 @@ using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.IO;
|
||||
using MediaBrowser.Providers.Books.ComicBookInfo.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharpCompress.Archives.Zip;
|
||||
|
||||
namespace MediaBrowser.Providers.Books.ComicBookInfo;
|
||||
|
||||
@@ -48,28 +48,18 @@ public class ComicBookInfoProvider : IComicProvider
|
||||
|
||||
try
|
||||
{
|
||||
Stream stream = File.OpenRead(path);
|
||||
Stream stream = AsyncFile.OpenRead(path);
|
||||
|
||||
// not yet async: https://github.com/adamhathcock/sharpcompress/pull/565
|
||||
await using (stream.ConfigureAwait(false))
|
||||
using (var archive = ZipArchive.Open(stream))
|
||||
await using (var archive = await ZipArchive.CreateAsync(stream, ZipArchiveMode.Read, false, null, cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
if (!archive.IsComplete)
|
||||
{
|
||||
_logger.LogError("incomplete comic archive: {Path}", info.Path);
|
||||
return new MetadataResult<Book> { HasMetadata = false };
|
||||
}
|
||||
|
||||
var volume = archive.Volumes.First();
|
||||
|
||||
if (volume.Comment is null)
|
||||
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>(volume.Comment, JsonDefaults.Options);
|
||||
|
||||
var comicBookMetadata = JsonSerializer.Deserialize<ComicBookInfoFormat>(archive.Comment, JsonDefaults.Options);
|
||||
if (comicBookMetadata is null)
|
||||
{
|
||||
_logger.LogError("ComicBookInfo deserialization failure: {Path}", info.Path);
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Xml.XPath;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using SharpCompress;
|
||||
|
||||
namespace MediaBrowser.Providers.Books.ComicInfo;
|
||||
|
||||
@@ -41,7 +40,13 @@ public static class ComicInfoReader
|
||||
hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/Summary", summary => book.Overview = summary);
|
||||
hasFoundMetadata |= ReadIntInto(xml, "ComicInfo/Year", year => book.ProductionYear = year);
|
||||
hasFoundMetadata |= ReadThreePartDateInto(xml, "ComicInfo/Year", "ComicInfo/Month", "ComicInfo/Day", dateTime => book.PremiereDate = dateTime);
|
||||
hasFoundMetadata |= ReadCommaSeparatedStringsInto(xml, "ComicInfo/Genre", genres => genres.ForEach(genre => book.AddGenre(genre)));
|
||||
hasFoundMetadata |= ReadCommaSeparatedStringsInto(xml, "ComicInfo/Genre", genres =>
|
||||
{
|
||||
foreach (var genre in genres)
|
||||
{
|
||||
book.AddGenre(genre);
|
||||
}
|
||||
});
|
||||
hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/Publisher", publisher => book.SetStudios([publisher]));
|
||||
|
||||
hasFoundMetadata |= ReadStringInto(xml, "ComicInfo/AlternateSeries", title =>
|
||||
@@ -71,32 +76,50 @@ public static class ComicInfoReader
|
||||
{
|
||||
ReadCommaSeparatedStringsInto(xml, "ComicInfo/Writer", authors =>
|
||||
{
|
||||
authors.ForEach(p => metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Author }));
|
||||
foreach (var p in authors)
|
||||
{
|
||||
metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Author });
|
||||
}
|
||||
});
|
||||
|
||||
ReadCommaSeparatedStringsInto(xml, "ComicInfo/Penciller", pencillers =>
|
||||
{
|
||||
pencillers.ForEach(p => metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Penciller }));
|
||||
foreach (var p in pencillers)
|
||||
{
|
||||
metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Penciller });
|
||||
}
|
||||
});
|
||||
|
||||
ReadCommaSeparatedStringsInto(xml, "ComicInfo/Inker", inkers =>
|
||||
{
|
||||
inkers.ForEach(p => metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Inker }));
|
||||
foreach (var p in inkers)
|
||||
{
|
||||
metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Inker });
|
||||
}
|
||||
});
|
||||
|
||||
ReadCommaSeparatedStringsInto(xml, "ComicInfo/Letterer", letterers =>
|
||||
{
|
||||
letterers.ForEach(p => metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Letterer }));
|
||||
foreach (var p in letterers)
|
||||
{
|
||||
metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Letterer });
|
||||
}
|
||||
});
|
||||
|
||||
ReadCommaSeparatedStringsInto(xml, "ComicInfo/CoverArtist", artists =>
|
||||
{
|
||||
artists.ForEach(p => metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.CoverArtist }));
|
||||
foreach (var p in artists)
|
||||
{
|
||||
metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.CoverArtist });
|
||||
}
|
||||
});
|
||||
|
||||
ReadCommaSeparatedStringsInto(xml, "ComicInfo/Colourist", colorists =>
|
||||
{
|
||||
colorists.ForEach(p => metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Colorist }));
|
||||
foreach (var p in colorists)
|
||||
{
|
||||
metadataResult.AddPerson(new PersonInfo { Name = p, Type = PersonKind.Colorist });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
Reference in New Issue
Block a user