mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 05:51:31 -04:00
Extended MediaCharacteristics common interface
This commit is contained in:
parent
b2438ec6a1
commit
2093882034
@ -8,6 +8,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@ -103,10 +104,28 @@ public class FFProbe implements MediaCharacteristics {
|
||||
}).get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return getTag("title").orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant getCreationTime() {
|
||||
return getTag("creation_time").map(Instant::parse).orElse(null);
|
||||
}
|
||||
|
||||
public Map<String, Object> getFormat() {
|
||||
return (Map) json.get("format");
|
||||
}
|
||||
|
||||
public Map<String, Object> getTags() {
|
||||
return (Map<String, Object>) getFormat().get("tags");
|
||||
}
|
||||
|
||||
public Optional<String> getTag(String tag) {
|
||||
return Optional.ofNullable(getTags()).map(m -> (String) m.get(tag));
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getStreams() {
|
||||
return (List) asList((Object[]) json.get("streams"));
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.filebot.media;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
|
||||
public interface MediaCharacteristics extends AutoCloseable {
|
||||
|
||||
@ -20,4 +21,8 @@ public interface MediaCharacteristics extends AutoCloseable {
|
||||
|
||||
Float getFrameRate();
|
||||
|
||||
String getTitle();
|
||||
|
||||
Instant getCreationTime();
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.lang.ref.Cleaner;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -180,6 +183,21 @@ public class MediaInfo implements MediaCharacteristics {
|
||||
return Float.parseFloat(get(StreamKind.Video, 0, "FrameRate"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return get(StreamKind.General, 0, "Title");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instant getCreationTime() {
|
||||
String d = get(StreamKind.General, 0, "Encoded_Date");
|
||||
if (d.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
// e.g. UTC 2008-01-08 19:54:39
|
||||
return ZonedDateTime.parse(d, DateTimeFormatter.ofPattern("zzz uuuu-MM-dd HH:mm:ss")).toInstant();
|
||||
}
|
||||
|
||||
public Map<StreamKind, List<Map<String, String>>> snapshot() {
|
||||
Map<StreamKind, List<Map<String, String>>> mediaInfo = new EnumMap<StreamKind, List<Map<String, String>>>(StreamKind.class);
|
||||
|
||||
|
@ -28,8 +28,8 @@ import java.util.stream.Stream;
|
||||
|
||||
import com.ibm.icu.text.Transliterator;
|
||||
|
||||
import net.filebot.format.BindingException;
|
||||
import net.filebot.format.MediaBindingBean;
|
||||
import net.filebot.media.MediaCharacteristics;
|
||||
import net.filebot.media.MediaCharacteristicsParser;
|
||||
import net.filebot.media.SmartSeasonEpisodeMatcher;
|
||||
import net.filebot.similarity.SeasonEpisodeMatcher.SxE;
|
||||
import net.filebot.vfs.FileInfo;
|
||||
@ -538,10 +538,11 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||
|
||||
private long getTimeStamp(File file) {
|
||||
if (VIDEO_FILES.accept(file) && file.length() > ONE_MEGABYTE) {
|
||||
try {
|
||||
return new MediaBindingBean(file, file).getEncodedDate().getTimeStamp();
|
||||
} catch (BindingException e) {
|
||||
debug.finest(e::getMessage); // Binding "General[0][Encoded_Date]": undefined => normal if Encoded_Date is undefined => ignore
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(file)) {
|
||||
Instant t = mi.getCreationTime();
|
||||
if (t != null) {
|
||||
return t.toEpochMilli();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
debug.warning("Failed to read media encoding date: " + e.getMessage());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user