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;
12 import eu.svjatoslav.commons.file.CommonPathResolver;
13 import eu.svjatoslav.commons.file.FilePathParser;
14 import eu.svjatoslav.meviz.Module;
15 import eu.svjatoslav.meviz.encoder.BitrateParameter;
16 import eu.svjatoslav.meviz.encoder.EncodingOptions;
17 import eu.svjatoslav.meviz.encoder.EncodingPlan;
18 import eu.svjatoslav.meviz.encoder.EncodingTask;
19 import eu.svjatoslav.meviz.encoder.converters.AbstractConverter;
20 import eu.svjatoslav.meviz.encoder.converters.AvconvVideo;
23 import java.io.IOException;
24 import java.util.Date;
25 import java.util.GregorianCalendar;
27 public class Main implements Module {
30 public String getDescription() {
31 return "Convenience helper to retrieve contents of inserted memory card.";
34 private File[] getDiskVideos(final File file) {
35 final String videosPath = file.getAbsolutePath() + "/AVCHD/BDMV/STREAM/";
36 final File videosDirectory = new File(videosPath);
38 if (!videosDirectory.exists())
41 return videosDirectory.listFiles();
44 private String getDoubleDigit(final int value) {
45 String valueString = Integer.toString(value);
46 if (valueString.length() == 1)
47 valueString = "0" + valueString;
51 private EncodingOptions getEncodingOptions() {
52 final EncodingOptions options = new EncodingOptions();
53 options.setVideoBitrate(BitrateParameter.bitrate.COPY);
54 options.setAudioBitrate(BitrateParameter.bitrate.COPY);
59 public String getModuleCommand() {
63 @SuppressWarnings("deprecation")
64 private File getTargetDirectory() {
65 final Date now = new Date();
66 final GregorianCalendar calendar = new GregorianCalendar();
68 String directoryName = (calendar.get(GregorianCalendar.YEAR) + "." + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
69 + "." + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH)) + " ") +
70 getDoubleDigit(now.getHours()) + ":" + getDoubleDigit(now.getMinutes()) + ":"
71 + getDoubleDigit(now.getSeconds());
73 final String targetDirectoryPath = CommonPathResolver.getDesktopDirectory().getAbsolutePath() + "/"
74 + directoryName + "/";
76 System.out.println("Target directory path: " + targetDirectoryPath);
78 return new File(targetDirectoryPath);
81 private File getTargetFile(final File targetDirectory, final File sourceFile) {
82 // compute target file path
83 final StringBuilder targetFilePath = new StringBuilder();
84 targetFilePath.append(targetDirectory.getAbsolutePath());
85 targetFilePath.append("/");
86 targetFilePath.append(FilePathParser.getFileNameWithoutExtension(sourceFile));
87 targetFilePath.append(".mp4");
88 return new File(targetFilePath.toString());
92 public void run(final String[] args) throws IOException {
94 final File targetDirectory = getTargetDirectory();
95 targetDirectory.mkdirs();
97 final AbstractConverter converter = new AvconvVideo();
98 final EncodingPlan encodingPlan = new EncodingPlan();
100 final String userName = System.getProperty("user.name");
102 final File file = new File("/media/" + userName + "/");
104 for (final File insertedDisk : file.listFiles()) {
105 final File[] diskVideos = getDiskVideos(insertedDisk);
107 for (final File sourceFile : diskVideos) {
109 final File targetFile = getTargetFile(targetDirectory, sourceFile);
111 final EncodingTask encodingTask = new EncodingTask(sourceFile, targetFile, converter, "mp4");
112 encodingTask.setUseTerminal(true);
113 encodingPlan.scheduleTask(encodingTask);
117 encodingPlan.execute(getEncodingOptions());
121 public void showCommandlineHelp() {
122 System.out.println("memory card grabber has no commandline options");