* reduce unnecessary messages that may confuse users that have the libraries install via the mediainfo packages
This commit is contained in:
parent
b777a8ea54
commit
f88c7fcff7
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
package net.filebot.mediainfo;
|
package net.filebot.mediainfo;
|
||||||
|
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -12,16 +10,14 @@ import java.util.EnumMap;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import com.sun.jna.NativeLibrary;
|
import com.sun.jna.NativeLibrary;
|
||||||
import com.sun.jna.Platform;
|
import com.sun.jna.Platform;
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
import com.sun.jna.WString;
|
import com.sun.jna.WString;
|
||||||
|
|
||||||
|
|
||||||
public class MediaInfo implements Closeable {
|
public class MediaInfo implements Closeable {
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
// libmediainfo for linux depends on libzen
|
// libmediainfo for linux depends on libzen
|
||||||
|
@ -31,13 +27,12 @@ public class MediaInfo implements Closeable {
|
||||||
NativeLibrary.getInstance("zen");
|
NativeLibrary.getInstance("zen");
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
Logger.getLogger(MediaInfo.class.getName()).warning("Failed to preload libzen");
|
// Logger.getLogger(MediaInfo.class.getName()).warning("Failed to preload libzen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pointer handle;
|
private Pointer handle;
|
||||||
|
|
||||||
|
|
||||||
public MediaInfo() {
|
public MediaInfo() {
|
||||||
try {
|
try {
|
||||||
handle = MediaInfoLibrary.INSTANCE.New();
|
handle = MediaInfoLibrary.INSTANCE.New();
|
||||||
|
@ -45,12 +40,11 @@ public class MediaInfo implements Closeable {
|
||||||
throw new MediaInfoException(e);
|
throw new MediaInfoException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized boolean open(File file) {
|
public synchronized boolean open(File file) {
|
||||||
if (!file.isFile())
|
if (!file.isFile())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// MacOS filesystem may require NFD unicode decomposition (forcing NFD seems to work for System.out() but passing to libmediainfo is still not working)
|
// MacOS filesystem may require NFD unicode decomposition (forcing NFD seems to work for System.out() but passing to libmediainfo is still not working)
|
||||||
String path = file.getAbsolutePath();
|
String path = file.getAbsolutePath();
|
||||||
if (Platform.isMac()) {
|
if (Platform.isMac()) {
|
||||||
|
@ -58,191 +52,168 @@ public class MediaInfo implements Closeable {
|
||||||
}
|
}
|
||||||
return MediaInfoLibrary.INSTANCE.Open(handle, new WString(path)) > 0;
|
return MediaInfoLibrary.INSTANCE.Open(handle, new WString(path)) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String inform() {
|
public synchronized String inform() {
|
||||||
return MediaInfoLibrary.INSTANCE.Inform(handle).toString();
|
return MediaInfoLibrary.INSTANCE.Inform(handle).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String option(String option) {
|
public String option(String option) {
|
||||||
return option(option, "");
|
return option(option, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String option(String option, String value) {
|
public synchronized String option(String option, String value) {
|
||||||
return MediaInfoLibrary.INSTANCE.Option(handle, new WString(option), new WString(value)).toString();
|
return MediaInfoLibrary.INSTANCE.Option(handle, new WString(option), new WString(value)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(StreamKind streamKind, int streamNumber, String parameter) {
|
public String get(StreamKind streamKind, int streamNumber, String parameter) {
|
||||||
return get(streamKind, streamNumber, parameter, InfoKind.Text, InfoKind.Name);
|
return get(streamKind, streamNumber, parameter, InfoKind.Text, InfoKind.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind) {
|
public String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind) {
|
||||||
return get(streamKind, streamNumber, parameter, infoKind, InfoKind.Name);
|
return get(streamKind, streamNumber, parameter, infoKind, InfoKind.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind, InfoKind searchKind) {
|
public synchronized String get(StreamKind streamKind, int streamNumber, String parameter, InfoKind infoKind, InfoKind searchKind) {
|
||||||
return MediaInfoLibrary.INSTANCE.Get(handle, streamKind.ordinal(), streamNumber, new WString(parameter), infoKind.ordinal(), searchKind.ordinal()).toString();
|
return MediaInfoLibrary.INSTANCE.Get(handle, streamKind.ordinal(), streamNumber, new WString(parameter), infoKind.ordinal(), searchKind.ordinal()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String get(StreamKind streamKind, int streamNumber, int parameterIndex) {
|
public String get(StreamKind streamKind, int streamNumber, int parameterIndex) {
|
||||||
return get(streamKind, streamNumber, parameterIndex, InfoKind.Text);
|
return get(streamKind, streamNumber, parameterIndex, InfoKind.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized String get(StreamKind streamKind, int streamNumber, int parameterIndex, InfoKind infoKind) {
|
public synchronized String get(StreamKind streamKind, int streamNumber, int parameterIndex, InfoKind infoKind) {
|
||||||
return MediaInfoLibrary.INSTANCE.GetI(handle, streamKind.ordinal(), streamNumber, parameterIndex, infoKind.ordinal()).toString();
|
return MediaInfoLibrary.INSTANCE.GetI(handle, streamKind.ordinal(), streamNumber, parameterIndex, infoKind.ordinal()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized int streamCount(StreamKind streamKind) {
|
public synchronized int streamCount(StreamKind streamKind) {
|
||||||
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), -1);
|
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized int parameterCount(StreamKind streamKind, int streamNumber) {
|
public synchronized int parameterCount(StreamKind streamKind, int streamNumber) {
|
||||||
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), streamNumber);
|
return MediaInfoLibrary.INSTANCE.Count_Get(handle, streamKind.ordinal(), streamNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<StreamKind, List<Map<String, String>>> snapshot() {
|
public Map<StreamKind, List<Map<String, String>>> snapshot() {
|
||||||
Map<StreamKind, List<Map<String, String>>> mediaInfo = new EnumMap<StreamKind, List<Map<String, String>>>(StreamKind.class);
|
Map<StreamKind, List<Map<String, String>>> mediaInfo = new EnumMap<StreamKind, List<Map<String, String>>>(StreamKind.class);
|
||||||
|
|
||||||
for (StreamKind streamKind : StreamKind.values()) {
|
for (StreamKind streamKind : StreamKind.values()) {
|
||||||
int streamCount = streamCount(streamKind);
|
int streamCount = streamCount(streamKind);
|
||||||
|
|
||||||
if (streamCount > 0) {
|
if (streamCount > 0) {
|
||||||
List<Map<String, String>> streamInfoList = new ArrayList<Map<String, String>>(streamCount);
|
List<Map<String, String>> streamInfoList = new ArrayList<Map<String, String>>(streamCount);
|
||||||
|
|
||||||
for (int i = 0; i < streamCount; i++) {
|
for (int i = 0; i < streamCount; i++) {
|
||||||
streamInfoList.add(snapshot(streamKind, i));
|
streamInfoList.add(snapshot(streamKind, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaInfo.put(streamKind, streamInfoList);
|
mediaInfo.put(streamKind, streamInfoList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mediaInfo;
|
return mediaInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, String> snapshot(StreamKind streamKind, int streamNumber) {
|
public Map<String, String> snapshot(StreamKind streamKind, int streamNumber) {
|
||||||
Map<String, String> streamInfo = new LinkedHashMap<String, String>();
|
Map<String, String> streamInfo = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
for (int i = 0, count = parameterCount(streamKind, streamNumber); i < count; i++) {
|
for (int i = 0, count = parameterCount(streamKind, streamNumber); i < count; i++) {
|
||||||
String value = get(streamKind, streamNumber, i, InfoKind.Text);
|
String value = get(streamKind, streamNumber, i, InfoKind.Text);
|
||||||
|
|
||||||
if (value.length() > 0) {
|
if (value.length() > 0) {
|
||||||
streamInfo.put(get(streamKind, streamNumber, i, InfoKind.Name), value);
|
streamInfo.put(get(streamKind, streamNumber, i, InfoKind.Name), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return streamInfo;
|
return streamInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void close() {
|
public synchronized void close() {
|
||||||
MediaInfoLibrary.INSTANCE.Close(handle);
|
MediaInfoLibrary.INSTANCE.Close(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public synchronized void dispose() {
|
public synchronized void dispose() {
|
||||||
if (handle == null)
|
if (handle == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// delete handle
|
// delete handle
|
||||||
MediaInfoLibrary.INSTANCE.Delete(handle);
|
MediaInfoLibrary.INSTANCE.Delete(handle);
|
||||||
handle = null;
|
handle = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() {
|
protected void finalize() {
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public enum StreamKind {
|
public enum StreamKind {
|
||||||
General, Video, Audio, Text, Chapters, Image, Menu;
|
General, Video, Audio, Text, Chapters, Image, Menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public enum InfoKind {
|
public enum InfoKind {
|
||||||
/**
|
/**
|
||||||
* Unique name of parameter.
|
* Unique name of parameter.
|
||||||
*/
|
*/
|
||||||
Name,
|
Name,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Value of parameter.
|
* Value of parameter.
|
||||||
*/
|
*/
|
||||||
Text,
|
Text,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique name of measure unit of parameter.
|
* Unique name of measure unit of parameter.
|
||||||
*/
|
*/
|
||||||
Measure,
|
Measure,
|
||||||
|
|
||||||
Options,
|
Options,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translated name of parameter.
|
* Translated name of parameter.
|
||||||
*/
|
*/
|
||||||
Name_Text,
|
Name_Text,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translated name of measure unit.
|
* Translated name of measure unit.
|
||||||
*/
|
*/
|
||||||
Measure_Text,
|
Measure_Text,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* More information about the parameter.
|
* More information about the parameter.
|
||||||
*/
|
*/
|
||||||
Info,
|
Info,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How this parameter is supported, could be N (No), B (Beta), R (Read only), W (Read/Write).
|
* How this parameter is supported, could be N (No), B (Beta), R (Read only), W (Read/Write).
|
||||||
*/
|
*/
|
||||||
HowTo,
|
HowTo,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Domain of this piece of information.
|
* Domain of this piece of information.
|
||||||
*/
|
*/
|
||||||
Domain;
|
Domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String version() {
|
public static String version() {
|
||||||
return staticOption("Info_Version");
|
return staticOption("Info_Version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String parameters() {
|
public static String parameters() {
|
||||||
return staticOption("Info_Parameters");
|
return staticOption("Info_Parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String codecs() {
|
public static String codecs() {
|
||||||
return staticOption("Info_Codecs");
|
return staticOption("Info_Codecs");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String capacities() {
|
public static String capacities() {
|
||||||
return staticOption("Info_Capacities");
|
return staticOption("Info_Capacities");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String staticOption(String option) {
|
public static String staticOption(String option) {
|
||||||
return staticOption(option, "");
|
return staticOption(option, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String staticOption(String option, String value) {
|
public static String staticOption(String option, String value) {
|
||||||
try {
|
try {
|
||||||
return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString();
|
return MediaInfoLibrary.INSTANCE.Option(null, new WString(option), new WString(value)).toString();
|
||||||
|
@ -250,8 +221,7 @@ public class MediaInfo implements Closeable {
|
||||||
throw new MediaInfoException(e);
|
throw new MediaInfoException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for easy usage
|
* Helper for easy usage
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue