mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-02 08:25:02 -04:00
Improved auto-detection
This commit is contained in:
parent
0a5327691e
commit
8ae4bed832
@ -10,6 +10,7 @@ import static net.filebot.Settings.*;
|
|||||||
import static net.filebot.WebServices.*;
|
import static net.filebot.WebServices.*;
|
||||||
import static net.filebot.format.ExpressionFormatMethods.*;
|
import static net.filebot.format.ExpressionFormatMethods.*;
|
||||||
import static net.filebot.media.MediaDetection.*;
|
import static net.filebot.media.MediaDetection.*;
|
||||||
|
import static net.filebot.media.XattrMetaInfo.*;
|
||||||
import static net.filebot.similarity.Normalization.*;
|
import static net.filebot.similarity.Normalization.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
import static net.filebot.util.StringUtilities.*;
|
import static net.filebot.util.StringUtilities.*;
|
||||||
@ -38,6 +39,7 @@ import net.filebot.mediainfo.MediaInfo;
|
|||||||
import net.filebot.mediainfo.MediaInfo.StreamKind;
|
import net.filebot.mediainfo.MediaInfo.StreamKind;
|
||||||
import net.filebot.similarity.NameSimilarityMetric;
|
import net.filebot.similarity.NameSimilarityMetric;
|
||||||
import net.filebot.util.FastFile;
|
import net.filebot.util.FastFile;
|
||||||
|
import net.filebot.web.Episode;
|
||||||
import net.filebot.web.Movie;
|
import net.filebot.web.Movie;
|
||||||
|
|
||||||
public class AutoDetection {
|
public class AutoDetection {
|
||||||
@ -85,19 +87,29 @@ public class AutoDetection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEpisode(File f) {
|
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) {
|
public boolean isAnime(File f) {
|
||||||
if (MediaDetection.parseEpisodeNumber(f.getName(), false) == null) {
|
if (MediaDetection.parseEpisodeNumber(f.getName(), false) == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (anyMatch(f.getParentFile(), ANIME_PATTERN) || find(f.getName(), ANIME_EPISODE_PATTERN) || find(f.getName(), EMBEDDED_CHECKSUM)) {
|
if (anyMatch(f.getParentFile(), ANIME_PATTERN) || find(f.getName(), ANIME_EPISODE_PATTERN) || find(f.getName(), EMBEDDED_CHECKSUM)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for Japanese audio or characteristic subtitles
|
|
||||||
if (VIDEO_FILES.accept(f)) {
|
if (VIDEO_FILES.accept(f)) {
|
||||||
|
// check for Japanese audio or characteristic subtitles
|
||||||
try (MediaInfo mi = new MediaInfo().open(f)) {
|
try (MediaInfo mi = new MediaInfo().open(f)) {
|
||||||
long minutes = Duration.ofMillis(Long.parseLong(mi.get(StreamKind.General, 0, "Duration"))).toMinutes();
|
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");
|
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());
|
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) {
|
public boolean anyMatch(File file, Pattern pattern) {
|
||||||
|
@ -120,21 +120,27 @@ public class MediaDetection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEpisode(File file, boolean strict) {
|
public static boolean isEpisode(File file, boolean strict) {
|
||||||
if (xattr.getMetaInfo(file) instanceof Episode)
|
Object metaInfo = xattr.getMetaInfo(file);
|
||||||
return true;
|
if (metaInfo != null) {
|
||||||
|
return metaInfo instanceof Episode;
|
||||||
|
}
|
||||||
|
|
||||||
return MediaDetection.isEpisode(String.join("/", file.getParent(), file.getName()), strict);
|
return MediaDetection.isEpisode(String.join("/", file.getParent(), file.getName()), strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isMovie(File file, boolean strict) {
|
public static boolean isMovie(File file, boolean strict) {
|
||||||
if (xattr.getMetaInfo(file) instanceof Movie)
|
Object metaInfo = xattr.getMetaInfo(file);
|
||||||
return true;
|
if (metaInfo != null) {
|
||||||
|
return metaInfo instanceof Movie;
|
||||||
|
}
|
||||||
|
|
||||||
if (isEpisode(file, strict))
|
if (isEpisode(file, strict)) {
|
||||||
return false;
|
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;
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// check for valid imdb id patterns
|
// check for valid imdb id patterns
|
||||||
return grepImdbId(file.getPath()).stream().map(Movie::new).filter(m -> {
|
return grepImdbId(file.getPath()).stream().map(Movie::new).filter(m -> {
|
||||||
@ -1003,18 +1009,21 @@ public class MediaDetection {
|
|||||||
return null;
|
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>();
|
LinkedList<String> relativePath = new LinkedList<String>();
|
||||||
|
for (File it : listPathTail(file, FILE_WALK_MAX_DEPTH, true)) {
|
||||||
// iterate path in reverse
|
|
||||||
for (File it : listPathTail(file, Integer.MAX_VALUE, true)) {
|
|
||||||
if (isStructureRoot(it))
|
if (isStructureRoot(it))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// iterate path in reverse
|
||||||
relativePath.addFirst(it.getName());
|
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) {
|
public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) {
|
||||||
|
Loading…
Reference in New Issue
Block a user