import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
import be.nikiroo.utils.MarkableFileInputStream;
// not complete: no "description" tag
meta.setCover(BasicSupportHelper.getImage(null, sourceInfoFile,
infoTag));
}
- // Second chance: try to check for a cover next to the info file
if (meta.getCover() == null) {
- String info = sourceInfoFile.getFile().toString();
- if (info.endsWith(".info")) {
- info = info.substring(0, info.length() - ".info".length());
- String ext = "."
- + Instance.getConfig()
- .getString(Config.IMAGE_FORMAT_COVER)
- .toLowerCase();
- meta.setCover(BasicSupportHelper.getImage(null,
- sourceInfoFile, info + ext));
- }
+ // Second chance: try to check for a cover next to the info file
+ meta.setCover(getCoverByName(sourceInfoFile));
}
}
try {
return meta;
}
+ /**
+ * Return the cover image if it is next to the source file.
+ *
+ * @param sourceInfoFile
+ * the source file
+ *
+ * @return the cover if present, NULL if not
+ */
+ public static Image getCoverByName(URL sourceInfoFile) {
+ Image cover = null;
+
+ File basefile = new File(sourceInfoFile.getFile());
+
+ String ext = "."
+ + Instance.getConfig().getString(Config.IMAGE_FORMAT_COVER)
+ .toLowerCase();
+
+ // Without removing ext
+ cover = BasicSupportHelper.getImage(null, sourceInfoFile,
+ basefile.getAbsolutePath() + ext);
+
+ // Try without ext
+ String name = basefile.getName();
+ int pos = name.lastIndexOf(".");
+ if (cover == null && pos > 0) {
+ name = name.substring(0, pos);
+ basefile = new File(basefile.getParent(), name);
+
+ cover = BasicSupportHelper.getImage(null, sourceInfoFile,
+ basefile.getAbsolutePath() + ext);
+ }
+
+ return cover;
+ }
+
private static boolean getInfoTagBoolean(InputStream in, String key,
boolean def) throws IOException {
Boolean value = getInfoTagBoolean(in, key);