Search in sources :

Example 1 with FileType

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);
}
Also used : FileType(org.fagu.fmv.media.FileType) File(java.io.File)

Example 2 with 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(), ','));
    }
}
Also used : FileType(org.fagu.fmv.media.FileType) Element(org.dom4j.Element) SortedSet(java.util.SortedSet) MapSortedSet(org.fagu.fmv.utils.collection.MapSortedSet)

Example 3 with FileType

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);
    }
}
Also used : FileType(org.fagu.fmv.media.FileType) Element(org.dom4j.Element) TreeMap(java.util.TreeMap) File(java.io.File) DocumentException(org.dom4j.DocumentException) IOException(java.io.IOException)

Example 4 with FileType

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));
    }
}
Also used : FileType(org.fagu.fmv.media.FileType) Element(org.dom4j.Element)

Example 5 with FileType

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();
}
Also used : ImageMetadatas(org.fagu.fmv.im.ImageMetadatas) AudioStream(org.fagu.fmv.ffmpeg.metadatas.AudioStream) Optional(java.util.Optional) FileType(org.fagu.fmv.media.FileType) MovieMetadatas(org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas) VideoStream(org.fagu.fmv.ffmpeg.metadatas.VideoStream) Duration(org.fagu.fmv.utils.time.Duration)

Aggregations

FileType (org.fagu.fmv.media.FileType)7 Element (org.dom4j.Element)3 File (java.io.File)2 Options (org.apache.commons.cli.Options)2 IOException (java.io.IOException)1 Optional (java.util.Optional)1 SortedSet (java.util.SortedSet)1 TreeMap (java.util.TreeMap)1 Predicate (java.util.function.Predicate)1 CommandLine (org.apache.commons.cli.CommandLine)1 DocumentException (org.dom4j.DocumentException)1 ConsoleOutput (org.fagu.fmv.cli.ConsoleOutput)1 Alias (org.fagu.fmv.cli.annotation.Alias)1 Aliases (org.fagu.fmv.cli.annotation.Aliases)1 Command (org.fagu.fmv.cli.annotation.Command)1 FileSource (org.fagu.fmv.core.project.FileSource)1 AudioStream (org.fagu.fmv.ffmpeg.metadatas.AudioStream)1 MovieMetadatas (org.fagu.fmv.ffmpeg.metadatas.MovieMetadatas)1 VideoStream (org.fagu.fmv.ffmpeg.metadatas.VideoStream)1 ImageMetadatas (org.fagu.fmv.im.ImageMetadatas)1