From 2bd85df383ec70251a8cdf9802963e29b52b60a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20L=C3=BCtzner?= Date: Thu, 15 Feb 2024 22:15:14 +0000 Subject: [PATCH] Add missing MIME types for comicbook formats (#11010) * Correct MIME types for comicbook file extensions cb7, cba, cbr, cbt and cbz all refer to different types of digital comicbooks. The last letter of the extension indicates the compression algorithm that was used: 7zip, arc, rar, tar or zip. All these filetypes used to have the `application/x-cbr` MIME type assigned to them. However, that has since been deprecated and was replaced with - `application/vnd.comicbook-rar` for rar compressed files and - `application/vnd.comicbook+zip` for rar compressed files. Only these two are officially listed by IANA https://www.iana.org/assignments/media-types/application/vnd.comicbook+zip . cbr and cbz are by far the most common file extensions for comicbooks. There's no official MIME type for cb7, cba or cbt files. However, with rar being a proprietary compression algorithm, FOSS applications will often refuse to handle files that identify themselves as `application/x-cbr`, so I decided to assign extension specific MIME types to them. I've seen these being used by other applications, specifically comic book readers. I've read through the docs on iana.org, but haven't figured out why they chose `-rar`, but `+zip`. * Add conversions from MIME type to file extensions for comicbook formats cb7, cba, cbr, cbt and cbz all refer to different types of digital comicbooks. The last letter of the extension indicates the compression algorithm that was used: 7zip, arc, rar, tar or zip. All these filetypes used to have the `application/x-cbr` MIME type assigned to them. However, that has since been deprecated and was replaced with - `application/vnd.comicbook-rar` for rar compressed files and - `application/vnd.comicbook+zip` for rar compressed files. Only these two are officially listed by IANA https://www.iana.org/assignments/media-types/application/vnd.comicbook+zip . cbr and cbz are by far the most common file extensions for comicbooks. There's no official MIME type for cb7, cba or cbt files. However, with rar being a proprietary compression algorithm, FOSS applications will often refuse to handle files that identify themselves as `application/x-cbr`, so I decided to assign extension specific MIME types to them. I've seen these being used by other applications, specifically comic book readers. * Update CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + MediaBrowser.Model/Net/MimeTypes.cs | 11 +++++++++++ tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index a8ee693ec4..55642e4e21 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -251,3 +251,4 @@ - [Utku Özdemir](https://github.com/utkuozdemir) - [JPUC1143](https://github.com/Jpuc1143/) - [0x25CBFC4F](https://github.com/0x25CBFC4F) + - [Robert Lützner](https://github.com/rluetzner) diff --git a/MediaBrowser.Model/Net/MimeTypes.cs b/MediaBrowser.Model/Net/MimeTypes.cs index 7b510a3379..90035f18f1 100644 --- a/MediaBrowser.Model/Net/MimeTypes.cs +++ b/MediaBrowser.Model/Net/MimeTypes.cs @@ -66,6 +66,11 @@ namespace MediaBrowser.Model.Net { // Type application { ".azw3", "application/vnd.amazon.ebook" }, + { ".cb7", "application/x-cb7" }, + { ".cba", "application/x-cba" }, + { ".cbr", "application/vnd.comicbook-rar" }, + { ".cbt", "application/x-cbt" }, + { ".cbz", "application/vnd.comicbook+zip" }, // Type image { ".tbn", "image/jpeg" }, @@ -98,6 +103,12 @@ namespace MediaBrowser.Model.Net private static readonly Dictionary _extensionLookup = new Dictionary(StringComparer.OrdinalIgnoreCase) { // Type application + { "application/vnd.comicbook-rar", ".cbr" }, + { "application/vnd.comicbook+zip", ".cbz" }, + { "application/x-cb7", ".cb7" }, + { "application/x-cba", ".cba" }, + { "application/x-cbr", ".cbr" }, + { "application/x-cbt", ".cbt" }, { "application/x-cbz", ".cbz" }, { "application/x-javascript", ".js" }, { "application/xml", ".xml" }, diff --git a/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs b/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs index ccdf017580..a18a85ec0f 100644 --- a/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs +++ b/tests/Jellyfin.Model.Tests/Net/MimeTypesTests.cs @@ -6,6 +6,11 @@ namespace Jellyfin.Model.Tests.Net public class MimeTypesTests { [Theory] + [InlineData(".cb7", "application/x-cb7")] + [InlineData(".cba", "application/x-cba")] + [InlineData(".cbr", "application/vnd.comicbook-rar")] + [InlineData(".cbt", "application/x-cbt")] + [InlineData(".cbz", "application/vnd.comicbook+zip")] [InlineData(".dll", "application/octet-stream")] [InlineData(".log", "text/plain")] [InlineData(".srt", "application/x-subrip")] @@ -94,10 +99,16 @@ namespace Jellyfin.Model.Tests.Net [InlineData("application/pdf", ".pdf")] [InlineData("application/ttml+xml", ".ttml")] [InlineData("application/vnd.amazon.ebook", ".azw")] + [InlineData("application/vnd.comicbook-rar", ".cbr")] + [InlineData("application/vnd.comicbook+zip", ".cbz")] [InlineData("application/vnd.ms-fontobject", ".eot")] [InlineData("application/vnd.rar", ".rar")] [InlineData("application/wasm", ".wasm")] [InlineData("application/x-7z-compressed", ".7z")] + [InlineData("application/x-cb7", ".cb7")] + [InlineData("application/x-cba", ".cba")] + [InlineData("application/x-cbr", ".cbr")] + [InlineData("application/x-cbt", ".cbt")] [InlineData("application/x-cbz", ".cbz")] [InlineData("application/x-javascript", ".js")] [InlineData("application/x-mobipocket-ebook", ".mobi")]