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.EncodingOptions;
21 import eu.svjatoslav.meviz.encoder.EncodingPlan;
22 import eu.svjatoslav.meviz.encoder.EncodingTask;
23 import eu.svjatoslav.meviz.encoder.converters.Converter;
24 import eu.svjatoslav.meviz.encoder.converters.Mts2Mp4;
26 public class Main implements Module {
29 public String getDescription() {
30 return "Convenience helper to retrieve contents of inserted memory card.";
33 public File[] getDiskVideos(final File file) {
34 final String videosPath = file.getAbsolutePath()
35 + "/AVCHD/BDMV/STREAM/";
36 final File videosDirectory = new File(videosPath);
38 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;
54 public String getModuleCommand() {
58 @SuppressWarnings("deprecation")
59 public File getTargetDirectory() {
60 final Date now = new Date();
61 final GregorianCalendar calendar = new GregorianCalendar();
63 final StringBuffer directoryName = new StringBuffer();
64 directoryName.append(calendar.get(GregorianCalendar.YEAR) + "."
65 + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1)
67 + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH))
70 directoryName.append(getDoubleDigit(now.getHours()) + ":"
71 + getDoubleDigit(now.getMinutes()) + ":"
72 + getDoubleDigit(now.getSeconds()));
74 final String targetDirectoryPath = CommonPathResolver
75 .getDesktopDirectory().getAbsolutePath()
77 + directoryName.toString() + "/";
79 System.out.println("Target directory path: " + targetDirectoryPath);
81 return new File(targetDirectoryPath);
85 public void run(final String[] args) throws IOException {
87 final File targetDirectory = getTargetDirectory();
88 targetDirectory.mkdirs();
90 final Converter converter = new Mts2Mp4();
91 final EncodingPlan encodingPlan = new EncodingPlan();
93 final String userName = System.getProperty("user.name");
95 // final File file = new File("/media/" + userName + "/");
97 final File file = new File("/media/");
99 for (final File insertedDisk : file.listFiles()) {
100 final File[] diskVideos = getDiskVideos(insertedDisk);
102 for (final File sourceFile : diskVideos) {
104 // compute target file path
105 final StringBuffer targetFilePath = new StringBuffer();
106 targetFilePath.append(targetDirectory.getAbsolutePath());
107 targetFilePath.append("/");
108 targetFilePath.append(FilePathParser
109 .getFileNameWithoutExtension(sourceFile));
110 targetFilePath.append(".mp4");
111 final File targetFile = new File(targetFilePath.toString());
113 final EncodingTask encodingTask = new EncodingTask(sourceFile,
114 targetFile, converter);
115 encodingPlan.scheduleTask(encodingTask);
119 final EncodingOptions options = new EncodingOptions();
121 encodingPlan.execute(options);
125 public void showCommandlineHelp() {
126 System.out.println("memory card grabber has no commandline options");