+++ /dev/null
-/*
- * Meviz - Various tools collection to work with multimedia.
- * Copyright (C) 2012 -- 2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 3 of the GNU Lesser General Public License
- * or later as published by the Free Software Foundation.
-*/
-
-package eu.svjatoslav.meviz.grabmemcard;
-
-import eu.svjatoslav.commons.file.CommonPathResolver;
-import eu.svjatoslav.commons.file.FilePathParser;
-import eu.svjatoslav.meviz.Module;
-import eu.svjatoslav.meviz.encoder.BitrateParameter;
-import eu.svjatoslav.meviz.encoder.EncodingOptions;
-import eu.svjatoslav.meviz.encoder.EncodingPlan;
-import eu.svjatoslav.meviz.encoder.EncodingTask;
-import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
-import eu.svjatoslav.meviz.encoder.converters.FFMpegVideo;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
-public class Main implements Module {
-
- @Override
- public String getDescription() {
- return "Convenience helper to retrieve contents of inserted memory card.";
- }
-
- private File[] getDiskVideos(final File file) {
- final String videosPath = file.getAbsolutePath() + "/AVCHD/BDMV/STREAM/";
- final File videosDirectory = new File(videosPath);
-
- if (!videosDirectory.exists())
- return new File[0];
-
- return videosDirectory.listFiles();
- }
-
- private String getDoubleDigit(final int value) {
- String valueString = Integer.toString(value);
- if (valueString.length() == 1)
- valueString = "0" + valueString;
- return valueString;
- }
-
- private EncodingOptions getEncodingOptions() {
- final EncodingOptions options = new EncodingOptions();
- options.setVideoBitrate(BitrateParameter.Bitrate.COPY);
- options.setAudioBitrate(BitrateParameter.Bitrate.COPY);
- return options;
- }
-
- @Override
- public String getModuleCommand() {
- return "grabmemcard";
- }
-
- @SuppressWarnings("deprecation")
- private File getTargetDirectory() {
- final Date now = new Date();
- final GregorianCalendar calendar = new GregorianCalendar();
-
- String directoryName = (calendar.get(GregorianCalendar.YEAR) + "." + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
- + "." + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH)) + " ") +
- getDoubleDigit(now.getHours()) + ":" + getDoubleDigit(now.getMinutes()) + ":"
- + getDoubleDigit(now.getSeconds());
-
- final String targetDirectoryPath = CommonPathResolver.getDesktopDirectory().getAbsolutePath() + "/"
- + directoryName + "/";
-
- System.out.println("Target directory path: " + targetDirectoryPath);
-
- return new File(targetDirectoryPath);
- }
-
- private File getTargetFile(final File targetDirectory, final File sourceFile) {
- // compute target file path
- final StringBuilder targetFilePath = new StringBuilder();
- targetFilePath.append(targetDirectory.getAbsolutePath());
- targetFilePath.append("/");
- targetFilePath.append(FilePathParser.getFileNameWithoutExtension(sourceFile));
- targetFilePath.append(".mp4");
- return new File(targetFilePath.toString());
- }
-
- @Override
- public void run(final String[] args) throws IOException {
-
- final File targetDirectory = getTargetDirectory();
- targetDirectory.mkdirs();
-
- final AbstractConverter converter = new FFMpegVideo();
- final EncodingPlan encodingPlan = new EncodingPlan();
-
- final String userName = System.getProperty("user.name");
-
- final File file = new File("/media/" + userName + "/");
-
- for (final File insertedDisk : file.listFiles()) {
- final File[] diskVideos = getDiskVideos(insertedDisk);
-
- for (final File sourceFile : diskVideos) {
-
- final File targetFile = getTargetFile(targetDirectory, sourceFile);
-
- final EncodingTask encodingTask = new EncodingTask(sourceFile, targetFile, converter, "mp4");
- encodingTask.setUseTerminal(true);
- encodingPlan.scheduleTask(encodingTask);
- }
- }
-
- encodingPlan.execute(getEncodingOptions());
- }
-
- @Override
- public void showCommandlineHelp() {
- System.out.println("memory card grabber has no commandline options");
- }
-
-}