use of org.fagu.fmv.media.FileType in project fmv by f-agu.
the class OpenFile method open.
/**
* @param fileSource
*/
public void open(FileSource fileSource) {
File file = fileSource.getFile();
FileType fileType = fileSource.getFileType();
open(file, fileType);
}
use of org.fagu.fmv.media.FileType in project fmv by f-agu.
the class Project method saveExtensions.
/**
* @param root
*/
private void saveExtensions(Element root) {
Element extensionsElement = root.addElement("extensions");
for (Entry<FileType, SortedSet<String>> entry : getExtensions().entrySet()) {
Element extensionElement = extensionsElement.addElement("extension");
extensionElement.addAttribute("type", entry.getKey().name());
extensionElement.setText(StringUtils.join(entry.getValue(), ','));
}
}
use of org.fagu.fmv.media.FileType in project fmv by f-agu.
the class Project method loadSources.
/**
* @param root
*/
private void loadSources(Element root) {
Element sourcesElement = root.element("sources");
TreeMap<Integer, FileSource> srcMap = new TreeMap<>();
for (Element element : LoadUtils.elements(sourcesElement, "source")) {
// number
int number = NumberUtils.toInt(element.attributeValue("n"), Integer.MIN_VALUE);
if (number == Integer.MIN_VALUE) {
System.out.println("Number 'n' undefined");
continue;
}
// type
FileType fileType = null;
try {
fileType = FileType.valueOf(element.attributeValue("type").trim().toUpperCase());
} catch (Exception e) {
System.out.println("FileType undefined for number: " + number);
continue;
}
// path
File file = new File(element.element("path").getTextTrim());
if (!file.exists()) {
System.out.println("File not found: " + file);
continue;
}
FileSource fileSource = new FileSource(fileType, file, number);
srcMap.put(number, fileSource);
// metadatas
String metadatas = element.element("metadatas").getTextTrim();
if (fileSource.isImage()) {
fileSource.setImageMetadatas(ImageMetadatas.parseJSON(metadatas));
} else if (fileSource.isAudioOrVideo()) {
fileSource.setVideoMetadatas(MovieMetadatas.parseJSON(metadatas));
}
}
for (FileSource fileSource : srcMap.values()) {
addSource(fileSource);
}
}
use of org.fagu.fmv.media.FileType in project fmv by f-agu.
the class Project method loadExtensions.
/**
* @param root
*/
private void loadExtensions(Element root) {
extensions.clear();
Element extensionsElement = root.element("extensions");
for (Element element : LoadUtils.elements(extensionsElement, "extension")) {
String type = element.attributeValue("type");
FileType fileType = null;
try {
fileType = FileType.valueOf(type.toUpperCase());
} catch (IllegalArgumentException e) {
System.out.println("Undefined extension type: " + type);
continue;
}
String[] text = element.getText().split(",");
for (int i = 0; i < text.length; ++i) {
text[i] = text[i].trim();
}
extensions.addAll(fileType, Arrays.asList(text));
}
}
use of org.fagu.fmv.media.FileType in project fmv by f-agu.
the class ConsoleOutput method forOutput.
/**
* @param fileSource
* @param fromFile
* @return
*/
public static String forOutput(FileSource fileSource, File fromFile) {
StringBuilder buf = new StringBuilder(100);
buf.append(StringUtils.rightPad(Integer.toString(fileSource.getNumber()), 3)).append(' ').append(' ');
FileType fileType = fileSource.getFileType();
if (fileType != null) {
buf.append(fileType.name().charAt(0)).append(' ');
}
String meta = null;
if (fileSource.isImage()) {
ImageMetadatas imageMetadatas = fileSource.getImageMetadatas();
if (imageMetadatas != null) {
meta = imageMetadatas.getDimension().toString();
}
}
if (fileSource.isAudioOrVideo()) {
MovieMetadatas videoMetadatas = fileSource.getVideoMetadatas();
if (videoMetadatas != null) {
AudioStream audioStream = videoMetadatas.getAudioStream();
VideoStream videoStream = videoMetadatas.getVideoStream();
if (videoStream != null) {
Optional<Duration> duration = videoStream.duration();
String sd = duration.isPresent() ? duration.get().toString() : "";
meta = videoStream.size().toString() + " " + sd;
} else if (audioStream != null) {
Optional<Duration> duration = audioStream.duration();
meta = duration.isPresent() ? duration.get().toString() : "";
}
}
}
String subPath = null;
if (fromFile != null) {
subPath = StringUtils.substringAfter(fileSource.getFile().getPath(), fromFile.getPath() + File.separator);
} else {
subPath = fileSource.getFile().getName();
}
buf.append(StringUtils.rightPad(meta, 25)).append(' ').append(' ').append(subPath);
return buf.toString();
}
Aggregations