wild mime

This commit is contained in:
Thibault Deckers 2021-12-10 12:34:48 +09:00
parent 2a5aefa7af
commit 9736747c7c
3 changed files with 12 additions and 5 deletions

View file

@ -1,5 +1,6 @@
package deckers.thibault.aves.channel.calls
import android.annotation.SuppressLint
import android.content.ContentUris
import android.content.Context
import android.database.Cursor
@ -95,6 +96,7 @@ class MetadataFetchHandler(private val context: Context) : MethodCallHandler {
}
}
@SuppressLint("ObsoleteSdkInt")
private fun getAllMetadata(call: MethodCall, result: MethodChannel.Result) {
val mimeType = call.argument<String>("mimeType")
val uri = call.argument<String>("uri")?.let { Uri.parse(it) }
@ -409,19 +411,19 @@ class MetadataFetchHandler(private val context: Context) : MethodCallHandler {
// File type
for (dir in metadata.getDirectoriesOfType(FileTypeDirectory::class.java)) {
// * `metadata-extractor` sometimes detects the wrong mime type (e.g. `pef` file as `tiff`)
// * `metadata-extractor` sometimes detects the wrong mime type (e.g. `pef` file as `tiff`, `mpeg` as `dvd`)
// * the content resolver / media store sometimes reports the wrong mime type (e.g. `png` file as `jpeg`, `tiff` as `srw`)
// * `context.getContentResolver().getType()` sometimes returns an incorrect value
// * `MediaMetadataRetriever.setDataSource()` sometimes fails with `status = 0x80000000`
// * file extension is unreliable
// In the end, `metadata-extractor` is the most reliable, except for `tiff` (false positives, false negatives),
// In the end, `metadata-extractor` is the most reliable, except for `tiff`/`dvd` (false positives, false negatives),
// in which case we trust the file extension
// cf https://github.com/drewnoakes/metadata-extractor/issues/296
if (path?.matches(TIFF_EXTENSION_PATTERN) == true) {
metadataMap[KEY_MIME_TYPE] = MimeTypes.TIFF
} else {
dir.getSafeString(FileTypeDirectory.TAG_DETECTED_FILE_MIME_TYPE) {
if (it != MimeTypes.TIFF) {
if (it != MimeTypes.TIFF && it != MimeTypes.DVD) {
metadataMap[KEY_MIME_TYPE] = it
}
}
@ -575,6 +577,7 @@ class MetadataFetchHandler(private val context: Context) : MethodCallHandler {
metadataMap[KEY_FLAGS] = flags
}
@SuppressLint("ObsoleteSdkInt")
private fun getMultimediaCatalogMetadataByMediaMetadataRetriever(
uri: Uri,
mimeType: String,

View file

@ -49,6 +49,7 @@ object MimeTypes {
private const val AVI = "video/avi"
private const val AVI_VND = "video/vnd.avi"
const val DVD = "video/dvd"
private const val MKV = "video/x-matroska"
private const val MOV = "video/quicktime"
private const val MP2T = "video/mp2t"

View file

@ -14,6 +14,7 @@ class MimeTypes {
static const art = 'image/x-jg';
static const djvu = 'image/vnd.djvu';
static const jxl = 'image/jxl';
static const psdVnd = 'image/vnd.adobe.photoshop';
static const psdX = 'image/x-photoshop';
@ -47,6 +48,7 @@ class MimeTypes {
static const mp2t = 'video/mp2t'; // .m2ts, .ts
static const mp2ts = 'video/mp2ts'; // .ts (prefer `mp2t` when possible)
static const mp4 = 'video/mp4';
static const mpeg = 'video/mpeg';
static const ogv = 'video/ogg';
static const webm = 'video/webm';
@ -55,6 +57,7 @@ class MimeTypes {
// JB2, JPC, JPX?
static const octetStream = 'application/octet-stream';
static const zip = 'application/zip';
// groups
@ -64,11 +67,11 @@ class MimeTypes {
static const Set<String> rawImages = {arw, cr2, crw, dcr, dng, erf, k25, kdc, mrw, nef, nrw, orf, pef, raf, raw, rw2, sr2, srf, srw, x3f};
// TODO TLAD [codec] make it dynamic if it depends on OS/lib versions
static const Set<String> undecodableImages = {art, crw, djvu, psdVnd, psdX, octetStream};
static const Set<String> undecodableImages = {art, crw, djvu, jxl, psdVnd, psdX, octetStream, zip};
static const Set<String> _knownOpaqueImages = {heic, heif, jpeg};
static const Set<String> _knownVideos = {avi, aviVnd, mkv, mov, mp2t, mp2ts, mp4, ogv, webm};
static const Set<String> _knownVideos = {avi, aviVnd, mkv, mov, mp2t, mp2ts, mp4, mpeg, ogv, webm};
static final Set<String> knownMediaTypes = {..._knownOpaqueImages, ...alphaImages, ...rawImages, ...undecodableImages, ..._knownVideos};