cleanup: remove broken mimetype check #1040
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR removes a broken attempt to handle extension mismatches.
Problem
The code currently tries to verify if a file's mimetype (as determined by Android's
ContentResolver) matches the mimetype inferred from the file's extension. If there is a mismatch, that might indicate that the file has the wrong extension, and the correct extension is appended.However,
MimeTypeMap.getFileExtensionFromUrl(fileName)will always returns null,since
getFileExtensionFromUrltakes URLs to always contain a/,but *nix forbids
/in filenames.As a result, this check incorrectly appends an extra extension to
every filename it encounters (e.g.
example.mp3.mp3).Why remove the check
While the code is easily fixed, I think the check is better left out altogether, since in its current form, it is probably a truism. The value of
mimeTypeis determined byapplicationContext.getContentResolver().getType(contentUri), which internally callsmimeTypeMap.getMimeTypeFromExtensionon the uri's extension.1 ThismimeTypevariable is then compared to the output of the exact same function (mimeTypeMap.getMimeTypeFromExtension). Hard for that to be wrong.Better leave handling misleading extensions to Kodi. In my tests, Kodi and standalone ffmeg are more than capable of handling files with incorrect extensions over http. I tested this by using Kore to play back a mpeg encoded file with an incorrect extension (
.flac).Footnotes
Tracing the calls of
getType(), I see that it ultimately just callsgetTypeForName()in ExternalStorageProvider.java, which then callsgetMimeTypeFromExtension. ↩