2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.grabmemcard;
13 import java.io.IOException;
14 import java.util.Date;
15 import java.util.GregorianCalendar;
17 import eu.svjatoslav.commons.file.CommonPathResolver;
18 import eu.svjatoslav.commons.file.FilePathParser;
19 import eu.svjatoslav.meviz.Module;
20 import eu.svjatoslav.meviz.encoder.BitrateParameter;
21 import eu.svjatoslav.meviz.encoder.EncodingOptions;
22 import eu.svjatoslav.meviz.encoder.EncodingPlan;
23 import eu.svjatoslav.meviz.encoder.EncodingTask;
24 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
25 import eu.svjatoslav.meviz.encoder.converters.Ffmpeg;
27 public class Main implements Module {
30 public String getDescription() {
31 return "Convenience helper to retrieve contents of inserted memory card.";
34 public File[] getDiskVideos(final File file) {
35 final String videosPath = file.getAbsolutePath()
36 + "/AVCHD/BDMV/STREAM/";
37 final File videosDirectory = new File(videosPath);
39 if (!videosDirectory.exists())
42 return videosDirectory.listFiles();
45 public String getDoubleDigit(final int value) {
46 String valueString = Integer.toString(value);
47 if (valueString.length() == 1)
48 valueString = "0" + valueString;
53 public String getModuleCommand() {
57 @SuppressWarnings("deprecation")
58 public File getTargetDirectory() {
59 final Date now = new Date();
60 final GregorianCalendar calendar = new GregorianCalendar();
62 final StringBuffer directoryName = new StringBuffer();
63 directoryName.append(calendar.get(GregorianCalendar.YEAR) + "."
64 + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
66 + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH))
69 directoryName.append(getDoubleDigit(now.getHours()) + ":"
70 + getDoubleDigit(now.getMinutes()) + ":"
71 + getDoubleDigit(now.getSeconds()));
73 final String targetDirectoryPath = CommonPathResolver
74 .getDesktopDirectory().getAbsolutePath()
76 + directoryName.toString() + "/";
78 System.out.println("Target directory path: " + targetDirectoryPath);
80 return new File(targetDirectoryPath);
84 public void run(final String[] args) throws IOException {
86 final File targetDirectory = getTargetDirectory();
87 targetDirectory.mkdirs();
89 final AbstractConverter converter = new Ffmpeg();
90 final EncodingPlan encodingPlan = new EncodingPlan();
92 final String userName = System.getProperty("user.name");
94 // final File file = new File("/media/" + userName + "/");
96 final File file = new File("/media/");
98 for (final File insertedDisk : file.listFiles()) {
99 final File[] diskVideos = getDiskVideos(insertedDisk);
101 for (final File sourceFile : diskVideos) {
103 // compute target file path
104 final StringBuffer targetFilePath = new StringBuffer();
105 targetFilePath.append(targetDirectory.getAbsolutePath());
106 targetFilePath.append("/");
107 targetFilePath.append(FilePathParser
108 .getFileNameWithoutExtension(sourceFile));
109 targetFilePath.append(".mp4");
110 final File targetFile = new File(targetFilePath.toString());
112 final EncodingTask encodingTask = new EncodingTask(sourceFile,
113 targetFile, converter);
114 encodingPlan.scheduleTask(encodingTask);
118 final EncodingOptions options = new EncodingOptions();
119 options.videoBitrate = BitrateParameter.bitrate.COPY;
121 encodingPlan.execute(options);
125 public void showCommandlineHelp() {
126 System.out.println("memory card grabber has no commandline options");