Search in sources :

Example 1 with Project

use of org.fagu.fmv.core.project.Project in project fmv by f-agu.

the class Bootstrap method newProject.

/**
 * @param printStream
 * @return
 */
private static Project newProject(PrintStream printStream) {
    try (Scanner scanner = new Scanner(new UnclosedInputStream(System.in))) {
        // name
        printStream.print("Name: ");
        String name = scanner.nextLine();
        // save file
        final File defaultSaveFile = new File(name);
        printStream.print("SaveFolder: [" + defaultSaveFile.getAbsolutePath() + "] ");
        File saveFile = null;
        String ssavefile = scanner.nextLine();
        if (StringUtils.isBlank(ssavefile)) {
            saveFile = defaultSaveFile;
        } else {
            saveFile = new File(ssavefile);
        }
        saveFile = new File(saveFile, name + ".fmv");
        saveFile.getParentFile().mkdirs();
        // format
        final String defaultFormat = "mp4";
        printStream.print("Format: [" + defaultFormat + "] ");
        String format = scanner.nextLine();
        if (StringUtils.isBlank(format)) {
            format = defaultFormat;
        }
        // size
        final Size defaultSize = Size.HD720;
        printStream.print("Size: [" + defaultSize + "] ");
        Size size = null;
        while (size == null) {
            String ssize = scanner.nextLine();
            if (StringUtils.isBlank(ssize)) {
                size = defaultSize;
            } else {
                try {
                    size = Size.parse(ssize);
                } catch (IllegalArgumentException e) {
                    printStream.println("Don't understand: " + ssize);
                }
            }
        }
        // rate
        final FrameRate defaultRate = FrameRate.valueOf(30, 1);
        printStream.print("Rate: [" + defaultRate + "] ");
        FrameRate frameRate = null;
        while (frameRate == null) {
            String srate = scanner.nextLine();
            if (StringUtils.isBlank(srate)) {
                frameRate = defaultRate;
            } else {
                try {
                    frameRate = FrameRate.parse(srate);
                } catch (IllegalArgumentException e) {
                    printStream.println("Don't understand: " + srate);
                }
            }
        }
        OutputInfos outputInfos = new OutputInfos();
        outputInfos.setSize(size);
        outputInfos.setFrameRate(frameRate);
        // TODO
        outputInfos.setAudioSampling(44100);
        outputInfos.setFormat(format);
        Project project = new Project(saveFile, outputInfos);
        project.setName(name);
        try {
            project.save();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return project;
    }
}
Also used : Scanner(java.util.Scanner) Project(org.fagu.fmv.core.project.Project) FrameRate(org.fagu.fmv.ffmpeg.utils.FrameRate) UnclosedInputStream(org.fagu.fmv.utils.io.UnclosedInputStream) Size(org.fagu.fmv.utils.media.Size) OutputInfos(org.fagu.fmv.core.project.OutputInfos) IOException(java.io.IOException) File(java.io.File)

Example 2 with Project

use of org.fagu.fmv.core.project.Project in project fmv by f-agu.

the class DefaultCommandBuilder method add.

/**
 * @see org.fagu.fmv.cli.CommandBuilder#add(java.lang.Class)
 */
@Override
public void add(final Class<? extends Command> cmdClass) {
    final org.fagu.fmv.cli.annotation.Command cmd = cmdClass.getAnnotation(org.fagu.fmv.cli.annotation.Command.class);
    if (cmd == null) {
        throw new RuntimeException("Annotation @Command not found: " + cmdClass.getName());
    }
    add(new CommandFactory() {

        /**
         * @see org.fagu.fmv.cli.CommandFactory#getCommandName()
         */
        @Override
        public String getCommandName() {
            return cmd.value();
        }

        /**
         * @see org.fagu.fmv.cli.CommandFactory#create(jline.console.ConsoleReader, org.fagu.fmv.cli.CommandBuilder,
         *      org.fagu.fmv.core.project.Project, java.lang.String, String[])
         */
        @Override
        public Command create(ConsoleReader consoleReader, CommandBuilder commandBuilder, Project project, String executable, String[] args) throws LineParseException {
            return build(cmdClass);
        }
    });
    // alias
    List<Alias> aliases = new ArrayList<>();
    Aliases aliasesAnno = cmdClass.getAnnotation(Aliases.class);
    if (aliasesAnno != null) {
        aliases.addAll(Arrays.asList(aliasesAnno.value()));
    }
    Alias aliasAnno = cmdClass.getAnnotation(Alias.class);
    if (aliasAnno != null) {
        aliases.add(aliasAnno);
    }
    if (!aliases.isEmpty()) {
        for (Alias alias : aliases) {
            String aliasCommand = alias.command();
            if (StringUtils.isBlank(aliasCommand)) {
                aliasCommand = cmd.value();
            }
            for (String aliasName : alias.value()) {
                addAlias(aliasName, aliasCommand);
            }
        }
    }
    // completion
    Completion completion = cmdClass.getAnnotation(Completion.class);
    if (completion != null) {
        try {
            @SuppressWarnings("unchecked") Class<CompleterFactory> completerFactoryClass = (Class<CompleterFactory>) Class.forName(completion.value());
            CompleterFactory completerFactory = completerFactoryClass.newInstance();
            Completer completer = completerFactory.create(cmd.value());
            completerMap.add(cmd.value(), completer);
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LineParseException(org.fagu.fmv.cli.exception.LineParseException) ConsoleReader(jline.console.ConsoleReader) Completer(jline.console.completer.Completer) Aliases(org.fagu.fmv.cli.annotation.Aliases) AliasCustomCommandFactory(org.fagu.fmv.cli.command.AliasCustomCommandFactory) Project(org.fagu.fmv.core.project.Project) Completion(org.fagu.fmv.cli.annotation.Completion) Alias(org.fagu.fmv.cli.annotation.Alias) CompleterFactory(org.fagu.fmv.cli.completion.CompleterFactory)

Example 3 with Project

use of org.fagu.fmv.core.project.Project in project fmv by f-agu.

the class Bootstrap method loadProject.

/**
 * @param saveFile
 * @return
 */
private static Project loadProject(File saveFile) {
    System.out.println("Loading " + saveFile.getName() + " ...");
    Project project = new Project(saveFile);
    try {
        project.load();
    } catch (LoadException e) {
        throw new RuntimeException(e);
    }
    return project;
}
Also used : Project(org.fagu.fmv.core.project.Project) LoadException(org.fagu.fmv.core.project.LoadException)

Example 4 with Project

use of org.fagu.fmv.core.project.Project in project fmv by f-agu.

the class Bootstrap method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    if (!FFMpeg.search().isFound()) {
        System.out.println("FFMpeg not found !");
        return;
    }
    if (!FFProbe.search().isFound()) {
        System.out.println("FFProbe not found !");
        return;
    }
    CommandLineParser parser = new GnuParser();
    Options options = new Options();
    options.addOption("c", "conf", true, "Conf properties");
    CommandLine commandLine = parser.parse(options, args);
    FMVCLIConfig fmvcliConfig;
    if (commandLine.hasOption('c')) {
        String conf = commandLine.getOptionValue('c');
        fmvcliConfig = openFMVCLIConfig(conf);
    } else {
        fmvcliConfig = new FMVCLIConfig();
    }
    System.out.println("FMV " + FMV.getVersion());
    System.out.println();
    Project project;
    String[] args2 = commandLine.getArgs();
    if (args2.length > 0) {
        project = loadProject(new File(args2[0]));
    } else {
        project = menu(System.out);
    }
    Console console = new Console(new Environnement(project, fmvcliConfig));
    console.run();
}
Also used : Options(org.apache.commons.cli.Options) Project(org.fagu.fmv.core.project.Project) CommandLine(org.apache.commons.cli.CommandLine) FMVCLIConfig(org.fagu.fmv.cli.FMVCLIConfig) GnuParser(org.apache.commons.cli.GnuParser) Console(org.fagu.fmv.cli.Console) Environnement(org.fagu.fmv.cli.Environnement) CommandLineParser(org.apache.commons.cli.CommandLineParser) File(java.io.File)

Aggregations

Project (org.fagu.fmv.core.project.Project)4 File (java.io.File)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 ConsoleReader (jline.console.ConsoleReader)1 Completer (jline.console.completer.Completer)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 GnuParser (org.apache.commons.cli.GnuParser)1 Options (org.apache.commons.cli.Options)1 Console (org.fagu.fmv.cli.Console)1 Environnement (org.fagu.fmv.cli.Environnement)1 FMVCLIConfig (org.fagu.fmv.cli.FMVCLIConfig)1 Alias (org.fagu.fmv.cli.annotation.Alias)1 Aliases (org.fagu.fmv.cli.annotation.Aliases)1 Completion (org.fagu.fmv.cli.annotation.Completion)1 AliasCustomCommandFactory (org.fagu.fmv.cli.command.AliasCustomCommandFactory)1 CompleterFactory (org.fagu.fmv.cli.completion.CompleterFactory)1 LineParseException (org.fagu.fmv.cli.exception.LineParseException)1