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

Improved auto-detection

This commit is contained in:
Reinhard Pointner 2016-04-14 09:31:57 +00:00
parent 0a5327691e
commit 8ae4bed832
2 changed files with 37 additions and 14 deletions

View File

@ -10,6 +10,7 @@ import static net.filebot.Settings.*;
import static net.filebot.WebServices.*;
import static net.filebot.format.ExpressionFormatMethods.*;
import static net.filebot.media.MediaDetection.*;
import static net.filebot.media.XattrMetaInfo.*;
import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
@ -38,6 +39,7 @@ import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind;
import net.filebot.similarity.NameSimilarityMetric;
import net.filebot.util.FastFile;
import net.filebot.web.Episode;
import net.filebot.web.Movie;
public class AutoDetection {
@ -85,19 +87,29 @@ public class AutoDetection {
}
public boolean isEpisode(File f) {
return MediaDetection.isEpisode(f.getName(), false) && (anyMatch(f.getParentFile(), SERIES_PATTERN) || find(f.getName(), SERIES_EPISODE_PATTERN) || MediaDetection.isEpisode(f, true));
if (MediaDetection.isEpisode(f.getName(), false) && (anyMatch(f.getParentFile(), SERIES_PATTERN) || find(f.getName(), SERIES_EPISODE_PATTERN))) {
return true;
}
if (MediaDetection.isEpisode(f.getPath(), true)) {
return true;
}
Object metaInfo = xattr.getMetaInfo(f);
return metaInfo instanceof Episode && !AniDB.getIdentifier().equals(((Episode) metaInfo).getSeriesInfo().getDatabase());
}
public boolean isAnime(File f) {
if (MediaDetection.parseEpisodeNumber(f.getName(), false) == null) {
return false;
}
if (anyMatch(f.getParentFile(), ANIME_PATTERN) || find(f.getName(), ANIME_EPISODE_PATTERN) || find(f.getName(), EMBEDDED_CHECKSUM)) {
return true;
}
// check for Japanese audio or characteristic subtitles
if (VIDEO_FILES.accept(f)) {
// check for Japanese audio or characteristic subtitles
try (MediaInfo mi = new MediaInfo().open(f)) {
long minutes = Duration.ofMillis(Long.parseLong(mi.get(StreamKind.General, 0, "Duration"))).toMinutes();
return minutes < 60 || mi.get(StreamKind.General, 0, "AudioLanguageList").contains("Japanese") && mi.get(StreamKind.General, 0, "TextCodecList").contains("ASS");
@ -105,7 +117,9 @@ public class AutoDetection {
debug.warning("Failed to read audio language: " + e.getMessage());
}
}
return false;
Object metaInfo = xattr.getMetaInfo(f);
return metaInfo instanceof Episode && AniDB.getIdentifier().equals(((Episode) metaInfo).getSeriesInfo().getDatabase());
}
public boolean anyMatch(File file, Pattern pattern) {

View File

@ -120,21 +120,27 @@ public class MediaDetection {
}
public static boolean isEpisode(File file, boolean strict) {
if (xattr.getMetaInfo(file) instanceof Episode)
return true;
Object metaInfo = xattr.getMetaInfo(file);
if (metaInfo != null) {
return metaInfo instanceof Episode;
}
return MediaDetection.isEpisode(String.join("/", file.getParent(), file.getName()), strict);
}
public static boolean isMovie(File file, boolean strict) {
if (xattr.getMetaInfo(file) instanceof Movie)
return true;
Object metaInfo = xattr.getMetaInfo(file);
if (metaInfo != null) {
return metaInfo instanceof Movie;
}
if (isEpisode(file, strict))
if (isEpisode(file, strict)) {
return false;
}
if (matchMovieName(asList(file.getName(), file.getParent()), strict, 0).size() > 0)
if (matchMovieName(asList(file.getName(), file.getParent()), strict, 0).size() > 0) {
return true;
}
// check for valid imdb id patterns
return grepImdbId(file.getPath()).stream().map(Movie::new).filter(m -> {
@ -1003,18 +1009,21 @@ public class MediaDetection {
return null;
}
public static File getStructurePathTail(File file) throws Exception {
public static List<String> listStructurePathTail(File file) throws Exception {
LinkedList<String> relativePath = new LinkedList<String>();
// iterate path in reverse
for (File it : listPathTail(file, Integer.MAX_VALUE, true)) {
for (File it : listPathTail(file, FILE_WALK_MAX_DEPTH, true)) {
if (isStructureRoot(it))
break;
// iterate path in reverse
relativePath.addFirst(it.getName());
}
return relativePath;
}
return relativePath.isEmpty() ? null : new File(join(relativePath, File.separator));
public static File getStructurePathTail(File file) throws Exception {
List<String> relativePath = listStructurePathTail(file);
return relativePath.isEmpty() ? null : new File(String.join(File.separator, relativePath));
}
public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) {