Guess image file type and ignore when not an image

Apparently, some publishers explicitly specify the audio file as an
image.
This commit is contained in:
ByteHamster 2021-07-31 20:43:42 +02:00
parent 63c00a12a8
commit d848ec3b98
2 changed files with 6 additions and 5 deletions

View File

@ -17,7 +17,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -103,7 +102,7 @@ public class ResizingOkHttpStreamFetcher extends OkHttpStreamFetcher {
callback.onDataReady(stream);
Log.d(TAG, "Compressed image from " + tempIn.length() / 1024
+ " to " + tempOut.length() / 1024 + " kB (quality: " + quality + "%)");
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
try {

View File

@ -47,8 +47,8 @@ public class NSMedia extends Namespace {
String medium = attributes.getValue(MEDIUM);
boolean validTypeMedia = false;
boolean validTypeImage = false;
boolean isDefault = "true".equals(defaultStr);
String guessedType = SyndTypeUtils.getMimeTypeFromUrl(url);
if (MEDIUM_AUDIO.equals(medium)) {
validTypeMedia = true;
@ -56,12 +56,14 @@ public class NSMedia extends Namespace {
} else if (MEDIUM_VIDEO.equals(medium)) {
validTypeMedia = true;
type = "video/*";
} else if (MEDIUM_IMAGE.equals(medium)) {
} else if (MEDIUM_IMAGE.equals(medium) && (guessedType == null
|| (!guessedType.startsWith("audio/") && !guessedType.startsWith("video/")))) {
// Apparently, some publishers explicitly specify the audio file as an image
validTypeImage = true;
type = "image/*";
} else {
if (type == null) {
type = SyndTypeUtils.getMimeTypeFromUrl(url);
type = guessedType;
}
if (SyndTypeUtils.enclosureTypeValid(type)) {