1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-25 01:08:52 -05:00

Fix rare MediaInfo issues on Mac OS X (the special characters issue... again... broken during refactoring)

@see https://www.filebot.net/forums/viewtopic.php?f=12&t=3988&p=22392#p22392
This commit is contained in:
Reinhard Pointner 2016-07-28 06:24:13 +08:00
parent 5a9169c5ed
commit 1da4b53942

View File

@ -1,10 +1,11 @@
package net.filebot.mediainfo; package net.filebot.mediainfo;
import static java.nio.charset.StandardCharsets.*;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -35,21 +36,21 @@ public class MediaInfo implements Closeable {
String path = file.getCanonicalPath(); String path = file.getCanonicalPath();
// on Mac files that contain accents cannot be opened via JNA WString file paths due to encoding differences so we use the buffer interface instead for these files // on Mac files that contain accents cannot be opened via JNA WString file paths due to encoding differences so we use the buffer interface instead for these files
if (Platform.isMac() && !StandardCharsets.US_ASCII.newEncoder().canEncode(path)) { if (Platform.isMac() && !US_ASCII.newEncoder().canEncode(path)) {
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
if (openViaBuffer(raf)) { if (openViaBuffer(raf)) {
return this;
}
throw new IOException("Failed to initialize media info buffer: " + path); throw new IOException("Failed to initialize media info buffer: " + path);
} }
} }
}
if (0 == MediaInfoLibrary.INSTANCE.Open(handle, new WString(path))) {
// failed to open file
throw new IOException("Failed to open media file: " + path);
}
// open via file path
if (0 != MediaInfoLibrary.INSTANCE.Open(handle, new WString(path))) {
return this; return this;
} }
throw new IOException("Failed to open media file: " + path);
}
private boolean openViaBuffer(RandomAccessFile f) throws IOException { private boolean openViaBuffer(RandomAccessFile f) throws IOException {
byte[] buffer = new byte[4 * 1024 * 1024]; // use large buffer to reduce JNA calls byte[] buffer = new byte[4 * 1024 * 1024]; // use large buffer to reduce JNA calls