From f56010bcd1775419c553e4e0fb8bb30d64cd1ca4 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 29 Jul 2012 12:42:05 +0000 Subject: [PATCH] * infer media info bindings from just any video file if necessary --- .../net/sourceforge/filebot/cli/CmdlineOperations.java | 2 +- .../sourceforge/filebot/format/MediaBindingBean.java | 10 ++++++++-- .../filebot/ui/rename/MovieHashMatcher.java | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/net/sourceforge/filebot/cli/CmdlineOperations.java b/source/net/sourceforge/filebot/cli/CmdlineOperations.java index dfc23128..b572e643 100644 --- a/source/net/sourceforge/filebot/cli/CmdlineOperations.java +++ b/source/net/sourceforge/filebot/cli/CmdlineOperations.java @@ -367,7 +367,7 @@ public class CmdlineOperations implements CmdlineInterface { String baseName = stripReleaseInfo(getName(nfo)).toLowerCase(); for (File movieFile : siblingMovieFiles) { - if (stripReleaseInfo(getName(movieFile)).toLowerCase().startsWith(baseName)) { + if (!baseName.isEmpty() && stripReleaseInfo(getName(movieFile)).toLowerCase().startsWith(baseName)) { movieByFile.put(movieFile, movie); } } diff --git a/source/net/sourceforge/filebot/format/MediaBindingBean.java b/source/net/sourceforge/filebot/format/MediaBindingBean.java index c333df01..ca5f3963 100644 --- a/source/net/sourceforge/filebot/format/MediaBindingBean.java +++ b/source/net/sourceforge/filebot/format/MediaBindingBean.java @@ -526,13 +526,19 @@ public class MediaBindingBean { } else if (!VIDEO_FILES.accept(mediaFile)) { // file is a subtitle, or nfo, etc String baseName = stripReleaseInfo(FileUtilities.getName(mediaFile)).toLowerCase(); + File[] videos = mediaFile.getParentFile().listFiles(VIDEO_FILES); // find corresponding movie file - for (File movieFile : mediaFile.getParentFile().listFiles(VIDEO_FILES)) { - if (stripReleaseInfo(FileUtilities.getName(movieFile)).toLowerCase().startsWith(baseName)) { + for (File movieFile : videos) { + if (!baseName.isEmpty() && stripReleaseInfo(FileUtilities.getName(movieFile)).toLowerCase().startsWith(baseName)) { return movieFile; } } + + // still no good match found -> just take any video from the same folder + if (videos.length > 0) { + return videos[0]; + } } return mediaFile; diff --git a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java index c2e9474a..204d0dc8 100644 --- a/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/sourceforge/filebot/ui/rename/MovieHashMatcher.java @@ -144,7 +144,7 @@ class MovieHashMatcher implements AutoCompleteMatcher { String baseName = stripReleaseInfo(getName(nfo)).toLowerCase(); for (File movieFile : siblingMovieFiles) { - if (stripReleaseInfo(getName(movieFile)).toLowerCase().startsWith(baseName)) { + if (!baseName.isEmpty() && stripReleaseInfo(getName(movieFile)).toLowerCase().startsWith(baseName)) { movieByFile.put(movieFile, movie); } }