1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-01-08 12:28:04 -05:00

// try to place embedded media title first

This commit is contained in:
Reinhard Pointner 2018-12-06 15:35:05 +07:00
parent 49b22e4137
commit 05700c63c6

View File

@ -535,15 +535,15 @@ public class MediaBindingBean {
}
@Define("source")
public String getVideoSource() {
public String getVideoSource() throws Exception {
// look for video source patterns in media file and it's parent folder (use inferred media file)
return releaseInfo.getVideoSource(getMediaTitles());
return releaseInfo.getVideoSource(mediaTitles.get());
}
@Define("tags")
public List<String> getVideoTags() {
public List<String> getVideoTags() throws Exception {
// look for video source patterns in media file and it's parent folder (use inferred media file)
List<String> matches = releaseInfo.getVideoTags(getMediaTitles());
List<String> matches = releaseInfo.getVideoTags(mediaTitles.get());
if (matches.isEmpty()) {
return null;
}
@ -555,8 +555,8 @@ public class MediaBindingBean {
}
@Define("s3d")
public String getStereoscopic3D() {
return releaseInfo.getStereoscopic3D(getMediaTitles());
public String getStereoscopic3D() throws Exception {
return releaseInfo.getStereoscopic3D(mediaTitles.get());
}
@Define("group")
@ -565,7 +565,7 @@ public class MediaBindingBean {
Pattern[] nonGroupPattern = { getKeywordExcludePattern(), releaseInfo.getVideoSourcePattern(), releaseInfo.getVideoFormatPattern(true), releaseInfo.getResolutionPattern(), releaseInfo.getStructureRootPattern() };
// consider foldername, filename and original filename of inferred media file
String[] filenames = stream(getMediaTitles()).map(s -> releaseInfo.clean(s, nonGroupPattern)).filter(s -> s.length() > 0).toArray(String[]::new);
String[] filenames = stream(mediaTitles.get()).map(s -> releaseInfo.clean(s, nonGroupPattern)).filter(s -> s.length() > 0).toArray(String[]::new);
// look for release group names in media file and it's parent folder
return releaseInfo.getReleaseGroup(filenames);
@ -1293,50 +1293,33 @@ public class MediaBindingBean {
return getMediaInfo().snapshot().get(kind).stream().map(m -> new AssociativeScriptObject(m, this::undefined)).collect(toList());
}
private final Resource<String[]> mediaTitles = Resource.lazy(() -> {
// try to place embedded media title first
try {
String mediaTitle = getMediaInfo().getTitle();
if (mediaTitle.length() > 0) {
return Stream.concat(Stream.of(mediaTitle), stream(getFileNames(getInferredMediaFile()))).toArray(String[]::new);
}
} catch (Exception e) {
debug.warning("Failed to read media title: " + e.getMessage());
}
// default to file name and xattr
return getFileNames(getInferredMediaFile());
});
private String[] getFileNames(File file) {
List<String> names = new ArrayList<String>();
// current file name
names.add(getNameWithoutExtension(file.getName()));
// original file name via xattr
String original = xattr.getOriginalName(file);
if (original != null) {
names.add(getNameWithoutExtension(original));
}
// current folder name
File parent = file.getParentFile();
if (parent != null && parent.getParent() != null) {
names.add(parent.getName());
}
return names.toArray(new String[0]);
}
private String[] getMediaTitles() {
File file = getInferredMediaFile();
List<String> names = new ArrayList<String>();
// current file name
names.add(getNameWithoutExtension(file.getName()));
// media title via embedded tags
try {
String title = getMediaInfo().get(StreamKind.General, 0, "Title");
if (title.length() > 0) {
names.add(title);
}
} catch (Exception e) {
debug.fine(e::toString);
}
// original file name via xattr
String original = xattr.getOriginalName(file);
if (original != null) {
names.add(getNameWithoutExtension(original));
}
// current folder name
File parent = file.getParentFile();
if (parent != null && parent.getParent() != null) {