mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 08:48:51 -05:00
* n00b counter measures: sample file not set issue
This commit is contained in:
parent
6b05c3f0c6
commit
58da1b2cfc
@ -78,6 +78,14 @@ public class MediaBindingBean {
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getInfoObject() {
|
||||||
|
return infoObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getFileObject() {
|
||||||
|
return mediaFile;
|
||||||
|
}
|
||||||
|
|
||||||
@Define(undefined)
|
@Define(undefined)
|
||||||
public <T> T undefined(String name) {
|
public <T> T undefined(String name) {
|
||||||
// omit expressions that depend on undefined values
|
// omit expressions that depend on undefined values
|
||||||
@ -396,12 +404,12 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
@Define("original")
|
@Define("original")
|
||||||
public String getOriginalFileName() throws Exception {
|
public String getOriginalFileName() throws Exception {
|
||||||
return getOriginalFileName(mediaFile);
|
return getOriginalFileName(getMediaFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("xattr")
|
@Define("xattr")
|
||||||
public Object getMetaAttributesObject() throws Exception {
|
public Object getMetaAttributesObject() throws Exception {
|
||||||
return new MetaAttributes(mediaFile).getObject();
|
return new MetaAttributes(getMediaFile()).getObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("crc32")
|
@Define("crc32")
|
||||||
@ -442,20 +450,14 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
@Define("fn")
|
@Define("fn")
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
// make sure media file is defined
|
// name without file extension
|
||||||
checkMediaFile();
|
return FileUtilities.getName(getMediaFile());
|
||||||
|
|
||||||
// file extension
|
|
||||||
return FileUtilities.getName(mediaFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("ext")
|
@Define("ext")
|
||||||
public String getExtension() {
|
public String getExtension() {
|
||||||
// make sure media file is defined
|
|
||||||
checkMediaFile();
|
|
||||||
|
|
||||||
// file extension
|
// file extension
|
||||||
return FileUtilities.getExtension(mediaFile);
|
return FileUtilities.getExtension(getMediaFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("source")
|
@Define("source")
|
||||||
@ -509,15 +511,12 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
@Define("lang")
|
@Define("lang")
|
||||||
public Language detectSubtitleLanguage() throws Exception {
|
public Language detectSubtitleLanguage() throws Exception {
|
||||||
// make sure media file is defined
|
Locale languageSuffix = releaseInfo.getLanguageSuffix(FileUtilities.getName(getMediaFile()));
|
||||||
checkMediaFile();
|
|
||||||
|
|
||||||
Locale languageSuffix = releaseInfo.getLanguageSuffix(FileUtilities.getName(mediaFile));
|
|
||||||
if (languageSuffix != null)
|
if (languageSuffix != null)
|
||||||
return Language.getLanguage(languageSuffix);
|
return Language.getLanguage(languageSuffix);
|
||||||
|
|
||||||
// require subtitle file
|
// require subtitle file
|
||||||
if (!SUBTITLE_FILES.accept(mediaFile)) {
|
if (!SUBTITLE_FILES.accept(getMediaFile())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -745,6 +744,11 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
@Define("file")
|
@Define("file")
|
||||||
public File getMediaFile() {
|
public File getMediaFile() {
|
||||||
|
// make sure file is not null, and that it is an existing file
|
||||||
|
if (mediaFile == null) {
|
||||||
|
throw new IllegalStateException("Path to media file not set. Click \"Change Sample\" and select a sample file.");
|
||||||
|
}
|
||||||
|
|
||||||
return mediaFile;
|
return mediaFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -785,11 +789,6 @@ public class MediaBindingBean {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("object")
|
|
||||||
public Object getInfoObject() {
|
|
||||||
return infoObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Define("i")
|
@Define("i")
|
||||||
public Integer getModelIndex() {
|
public Integer getModelIndex() {
|
||||||
return 1 + identityIndexOf(context.values(), getInfoObject());
|
return 1 + identityIndexOf(context.values(), getInfoObject());
|
||||||
@ -826,16 +825,13 @@ public class MediaBindingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public File getInferredMediaFile() {
|
public File getInferredMediaFile() {
|
||||||
// make sure media file is defined
|
if (getMediaFile().isDirectory()) {
|
||||||
checkMediaFile();
|
|
||||||
|
|
||||||
if (mediaFile.isDirectory()) {
|
|
||||||
// just select the first video file in the folder as media sample
|
// just select the first video file in the folder as media sample
|
||||||
SortedSet<File> videos = new TreeSet<File>(filter(listFiles(mediaFile), VIDEO_FILES));
|
SortedSet<File> videos = new TreeSet<File>(filter(listFiles(getMediaFile()), VIDEO_FILES));
|
||||||
if (videos.size() > 0) {
|
if (videos.size() > 0) {
|
||||||
return videos.iterator().next();
|
return videos.iterator().next();
|
||||||
}
|
}
|
||||||
} else if (SUBTITLE_FILES.accept(mediaFile) || ((infoObject instanceof Episode || infoObject instanceof Movie) && !VIDEO_FILES.accept(mediaFile))) {
|
} else if (SUBTITLE_FILES.accept(getMediaFile()) || ((infoObject instanceof Episode || infoObject instanceof Movie) && !VIDEO_FILES.accept(getMediaFile()))) {
|
||||||
// prefer equal match from current context if possible
|
// prefer equal match from current context if possible
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
for (Entry<File, Object> it : context.entrySet()) {
|
for (Entry<File, Object> it : context.entrySet()) {
|
||||||
@ -846,8 +842,8 @@ public class MediaBindingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// file is a subtitle, or nfo, etc
|
// file is a subtitle, or nfo, etc
|
||||||
String baseName = stripReleaseInfo(FileUtilities.getName(mediaFile)).toLowerCase();
|
String baseName = stripReleaseInfo(FileUtilities.getName(getMediaFile())).toLowerCase();
|
||||||
List<File> videos = getChildren(mediaFile.getParentFile(), VIDEO_FILES);
|
List<File> videos = getChildren(getMediaFile().getParentFile(), VIDEO_FILES);
|
||||||
|
|
||||||
// find corresponding movie file
|
// find corresponding movie file
|
||||||
for (File movieFile : videos) {
|
for (File movieFile : videos) {
|
||||||
@ -858,7 +854,7 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
// still no good match found -> just take the most probable video from the same folder
|
// still no good match found -> just take the most probable video from the same folder
|
||||||
if (videos.size() > 0) {
|
if (videos.size() > 0) {
|
||||||
sort(videos, new SimilarityComparator(FileUtilities.getName(mediaFile)) {
|
sort(videos, new SimilarityComparator(FileUtilities.getName(getMediaFile())) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(Object o1, Object o2) {
|
||||||
@ -869,22 +865,12 @@ public class MediaBindingBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mediaFile;
|
return getMediaFile();
|
||||||
}
|
|
||||||
|
|
||||||
private void checkMediaFile() {
|
|
||||||
// make sure file is not null, and that it is an existing file
|
|
||||||
if (mediaFile == null) {
|
|
||||||
throw new IllegalStateException("Path to media file not set. Click (x)= and select a sample file.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Map<File, MediaInfo> sharedMediaInfoObjects = new WeakValueHashMap<File, MediaInfo>(64);
|
private static final Map<File, MediaInfo> sharedMediaInfoObjects = new WeakValueHashMap<File, MediaInfo>(64);
|
||||||
|
|
||||||
private synchronized MediaInfo getMediaInfo() {
|
private synchronized MediaInfo getMediaInfo() {
|
||||||
// make sure media file is defined
|
|
||||||
checkMediaFile();
|
|
||||||
|
|
||||||
// lazy initialize
|
// lazy initialize
|
||||||
if (mediaInfo == null) {
|
if (mediaInfo == null) {
|
||||||
// use inferred media file (e.g. actual movie file instead of subtitle file)
|
// use inferred media file (e.g. actual movie file instead of subtitle file)
|
||||||
|
@ -235,8 +235,8 @@ public class FormatDialog extends JDialog {
|
|||||||
@Override
|
@Override
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
if (isMacSandbox()) {
|
if (isMacSandbox()) {
|
||||||
if (sample != null && sample.getMediaFile() != null && sample.getMediaFile().exists()) {
|
if (sample != null && sample.getFileObject() != null && sample.getFileObject().exists()) {
|
||||||
MacAppUtilities.askUnlockFolders(getWindow(evt.getSource()), singleton(sample.getMediaFile()));
|
MacAppUtilities.askUnlockFolders(getWindow(evt.getSource()), singleton(sample.getFileObject()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
checkFormatInBackground();
|
checkFormatInBackground();
|
||||||
@ -283,7 +283,7 @@ public class FormatDialog extends JDialog {
|
|||||||
|
|
||||||
if (locked) {
|
if (locked) {
|
||||||
this.setTitle(String.format("%s Format", mode));
|
this.setTitle(String.format("%s Format", mode));
|
||||||
title.setText(String.format("%s ⇔ %s", mode, bindings.getInfoObject(), bindings.getMediaFile() == null ? null : bindings.getMediaFile().getName()));
|
title.setText(String.format("%s ⇔ %s", mode, bindings.getInfoObject(), bindings.getFileObject() == null ? null : bindings.getFileObject().getName()));
|
||||||
} else {
|
} else {
|
||||||
this.setTitle(String.format("%s Format", mode));
|
this.setTitle(String.format("%s Format", mode));
|
||||||
title.setText(String.format("%s Format", mode));
|
title.setText(String.format("%s Format", mode));
|
||||||
@ -651,7 +651,7 @@ public class FormatDialog extends JDialog {
|
|||||||
BindingDialog dialog = new BindingDialog(getWindow(evt.getSource()), String.format("%s Bindings", mode), mode.getFormat(), !locked);
|
BindingDialog dialog = new BindingDialog(getWindow(evt.getSource()), String.format("%s Bindings", mode), mode.getFormat(), !locked);
|
||||||
|
|
||||||
dialog.setInfoObject(sample.getInfoObject());
|
dialog.setInfoObject(sample.getInfoObject());
|
||||||
dialog.setMediaFile(sample.getMediaFile());
|
dialog.setMediaFile(sample.getFileObject());
|
||||||
|
|
||||||
// open dialog
|
// open dialog
|
||||||
dialog.setLocationRelativeTo((Component) evt.getSource());
|
dialog.setLocationRelativeTo((Component) evt.getSource());
|
||||||
@ -667,7 +667,7 @@ public class FormatDialog extends JDialog {
|
|||||||
// remember sample
|
// remember sample
|
||||||
try {
|
try {
|
||||||
mode.persistentSample().setValue(info == null ? "" : JsonWriter.objectToJson(info));
|
mode.persistentSample().setValue(info == null ? "" : JsonWriter.objectToJson(info));
|
||||||
persistentSampleFile.setValue(file == null ? "" : sample.getMediaFile().getAbsolutePath());
|
persistentSampleFile.setValue(file == null ? "" : sample.getFileObject().getAbsolutePath());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(FormatDialog.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
Logger.getLogger(FormatDialog.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user