Implement advanced multi-part movie detection (via group by mediainfo)
This commit is contained in:
parent
47d9513a70
commit
73e7443593
|
@ -463,6 +463,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
// collect all File/MoviePart matches
|
||||
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
|
||||
|
||||
// TODO: MediaDetection.groupByMediaCharacteristics()
|
||||
for (Entry<Movie, SortedSet<File>> byMovie : filesByMovie.entrySet()) {
|
||||
for (List<File> movieFileListByMediaFolder : mapByMediaFolder(byMovie.getValue()).values()) {
|
||||
for (List<File> fileSet : mapByExtension(movieFileListByMediaFolder).values()) {
|
||||
|
|
|
@ -751,13 +751,23 @@ public class MediaBindingBean {
|
|||
}
|
||||
|
||||
@Define("bitrate")
|
||||
public Long getBitRate() {
|
||||
public Long getOverallBitRate() {
|
||||
return new Double(getMediaInfo(StreamKind.General, 0, "OverallBitRate")).longValue();
|
||||
}
|
||||
|
||||
@Define("vbr")
|
||||
public Long getVideoBitRate() {
|
||||
return new Double(getMediaInfo(StreamKind.Video, 0, "BitRate")).longValue();
|
||||
}
|
||||
|
||||
@Define("abr")
|
||||
public Long getAudioBitRate() {
|
||||
return new Double(getMediaInfo(StreamKind.Audio, 0, "BitRate")).longValue();
|
||||
}
|
||||
|
||||
@Define("duration")
|
||||
public Long getDuration() {
|
||||
return (long) Double.parseDouble(getMediaInfo(StreamKind.General, 0, "Duration"));
|
||||
return new Double(getMediaInfo(StreamKind.General, 0, "Duration")).longValue();
|
||||
}
|
||||
|
||||
@Define("seconds")
|
||||
|
|
|
@ -1067,6 +1067,37 @@ public class MediaDetection {
|
|||
return map;
|
||||
}
|
||||
|
||||
public static List<List<File>> groupByMediaCharacteristics(Collection<File> files) {
|
||||
List<List<File>> groups = new ArrayList<List<File>>();
|
||||
|
||||
mapByExtension(files).forEach((extension, filesByExtension) -> {
|
||||
if (filesByExtension.size() < 2) {
|
||||
groups.add(filesByExtension);
|
||||
return;
|
||||
}
|
||||
|
||||
mapByMediaFolder(filesByExtension).forEach((mediaFolder, filesByMediaFolder) -> {
|
||||
if (filesByMediaFolder.size() < 2) {
|
||||
groups.add(filesByMediaFolder);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
filesByMediaFolder.stream().collect(groupingBy(new VideoQuality()::getVideoBitrate)).forEach((vbr, videos) -> {
|
||||
groups.add(videos);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
debug.warning(format("Failed to group by media characteristics: %s", e.getMessage()));
|
||||
|
||||
// if mediainfo fails and we can't further group by video bitrate then just keep the grouping we have
|
||||
groups.add(filesByMediaFolder);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
public static Map<String, List<File>> mapBySeriesName(Collection<File> files, boolean anime, Locale locale) throws Exception {
|
||||
Map<String, List<File>> result = new TreeMap<String, List<File>>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package net.filebot.media;
|
||||
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
import static java.util.Comparator.*;
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
@ -64,4 +64,16 @@ public class VideoQuality implements Comparator<File> {
|
|||
}).orElseGet(f::length);
|
||||
}
|
||||
|
||||
public long getVideoBitrate(File f) {
|
||||
return media(f).map(it -> {
|
||||
return it.getVideoBitRate();
|
||||
}).orElse(0L);
|
||||
}
|
||||
|
||||
public long getAudioBitrate(File f) {
|
||||
return media(f).map(it -> {
|
||||
return it.getAudioBitRate();
|
||||
}).orElse(0L);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -195,6 +195,7 @@ class MovieMatcher implements AutoCompleteMatcher {
|
|||
// collect all File/MoviePart matches
|
||||
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
|
||||
|
||||
// TODO: MediaDetection.groupByMediaCharacteristics()
|
||||
filesByMovie.forEach((movie, byMovie) -> {
|
||||
mapByMediaFolder(byMovie).forEach((mediaFolder, byFolder) -> {
|
||||
mapByExtension(byFolder).forEach((ext, moviePartFiles) -> {
|
||||
|
|
Loading…
Reference in New Issue