[
https://issues.apache.org/jira/browse/TIKA-5041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18139193#comment-18139193
]
ASF GitHub Bot commented on TIKA-5041:
--------------------------------------
dschmidt opened a new pull request, #3553:
URL: https://github.com/apache/tika/pull/3553
[TIKA-5041](https://issues.apache.org/jira/browse/TIKA-5041)
#3530 gave `.cbz` its cover. This does the same for comic book archives in
RAR, 7z and tar: `application/vnd.comicbook-rar` (`.cbr`, IANA-registered,
alias `application/x-cbr`), `application/x-cb7` (`.cb7`) and
`application/x-cbt` (`.cbt`), new sub-types of their containers. `RarParser`,
`SevenZParser` and `PackageParser` keep the comic type and mark the first page
in name order as the `THUMBNAIL`; the choice is the one `ZipPreview` makes for
`.cbz`, now shared in `ComicBook`. For tar, the names come from `TarFile`
first, as a streamed tar gives them only one by one.
Detection needed a local workaround. A name or declared type replaces the
magic type only when it is a sub-type of it, and the magic of a RAR is
`application/x-rar-compressed; version=4` or `version=5`, that of a GNU tar
`application/x-gtar`; neither has the comic types below it, so a `.cbr` stayed
a RAR whatever its name or declared type said. `ComicBookDetector` returns the
comic type when the name ends in `.cbr`, `.cb7` or `.cbt`, or the declared type
is a comic type, and the content starts with the matching container's magic.
## To be decided: fix the hint rule instead?
The general fix would be in `MimeTypes.applyHint`: let a hint win when it
specializes the base of a parameterized magic type (`x-rar-compressed` for
`x-rar-compressed; version=5`), and treat GNU tar as a variant of tar. That
would make the detector unnecessary and help any other format sitting on a
versioned container, but it changes detection for every type with such
variants, PDF versions included. I went with the contained detector for now;
happy to switch if you prefer the general one.
Checked with two real `.cbr` (RAR4 and RAR5), two real `.cb7` and a POSIX
and a GNU `.cbt` built with tar, each for detection (with the name, with only
the declared type, with neither), parsing and `/unpack/preset/thumbnail`: all
give the comic type from a name or a declared type and their first page as the
thumbnail; without either they stay plain archives, as `.cbz` does. Tests cover
the detector, a RAR5, a 7z and a POSIX and GNU tar with pages stored out of
order.
> Comic book archives in RAR, 7z and tar (.cbr, .cb7, .cbt): detect them and
> emit the cover as THUMBNAIL
> ------------------------------------------------------------------------------------------------------
>
> Key: TIKA-5041
> URL: https://issues.apache.org/jira/browse/TIKA-5041
> Project: Tika
> Issue Type: Improvement
> Components: mime, parser
> Reporter: Dominik Schmidt
> Priority: Major
>
> TIKA-5032 handles comic book archives in a zip container ({{.cbz}},
> {{application/vnd.comicbook+zip}}): the first page in name order is the cover
> and is emitted as {{THUMBNAIL}}. The same convention exists for other
> containers, with no type in tika-mimetypes.xml today:
> * {{.cbr}}: RAR, IANA-registered as {{application/vnd.comicbook-rar}}
> (shared-mime-info: sub-class of {{application/vnd.rar}}, alias
> {{application/x-cbr}})
> * {{.cb7}}: 7z, {{application/x-cb7}} in shared-mime-info
> * {{.cbt}}: tar, {{application/x-cbt}} in shared-mime-info
> Registering them as sub-types of their container would let RarParser,
> SevenZParser and the tar path open them; picking the cover needs the full
> entry list, like the zip case. RAR support is limited (RAR5), so {{.cbr}} may
> only partly work.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)