X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fmeviz%2Fgrabmemcard%2FMain.java;h=4000e7eb361709045bc51005371094ad0585f5c4;hb=567410640f4e0428caf9de9fc83df4c73f0e5067;hp=e5383387992606d77c22862a074a8c9b94cb0b38;hpb=34e6964d7b230e1943b14a7107fc73861ab65220;p=meviz.git diff --git a/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java b/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java index e538338..4000e7e 100755 --- a/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java +++ b/src/main/java/eu/svjatoslav/meviz/grabmemcard/Main.java @@ -1,19 +1,14 @@ /* * Meviz - Various tools collection to work with multimedia. - * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * 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 2 of the GNU General Public License - * as published by the Free Software Foundation. - */ + * 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 java.io.File; -import java.io.IOException; -import java.util.Date; -import java.util.GregorianCalendar; - import eu.svjatoslav.commons.file.CommonPathResolver; import eu.svjatoslav.commons.file.FilePathParser; import eu.svjatoslav.meviz.Module; @@ -24,106 +19,107 @@ import eu.svjatoslav.meviz.encoder.EncodingTask; import eu.svjatoslav.meviz.encoder.converters.AbstractConverter; import eu.svjatoslav.meviz.encoder.converters.AvconvVideo; -public class Main implements Module { +import java.io.File; +import java.io.IOException; +import java.util.Date; +import java.util.GregorianCalendar; - @Override - public String getDescription() { - return "Convenience helper to retrieve contents of inserted memory card."; - } +public class Main implements Module { - public File[] getDiskVideos(final File file) { - final String videosPath = file.getAbsolutePath() + "/AVCHD/BDMV/STREAM/"; - final File videosDirectory = new File(videosPath); + @Override + public String getDescription() { + return "Convenience helper to retrieve contents of inserted memory card."; + } - if (!videosDirectory.exists()) - return new File[0]; + private File[] getDiskVideos(final File file) { + final String videosPath = file.getAbsolutePath() + "/AVCHD/BDMV/STREAM/"; + final File videosDirectory = new File(videosPath); - return videosDirectory.listFiles(); - } + if (!videosDirectory.exists()) + return new File[0]; - public String getDoubleDigit(final int value) { - String valueString = Integer.toString(value); - if (valueString.length() == 1) - valueString = "0" + valueString; - return valueString; - }; + return videosDirectory.listFiles(); + } - private EncodingOptions getEncodingOptions() { - final EncodingOptions options = new EncodingOptions(); - options.setVideoBitrate(BitrateParameter.bitrate.COPY); - options.setAudioBitrate(BitrateParameter.bitrate.COPY); - return options; - } + private String getDoubleDigit(final int value) { + String valueString = Integer.toString(value); + if (valueString.length() == 1) + valueString = "0" + valueString; + return valueString; + } - @Override - public String getModuleCommand() { - return "grabmemcard"; - } + private EncodingOptions getEncodingOptions() { + final EncodingOptions options = new EncodingOptions(); + options.setVideoBitrate(BitrateParameter.Bitrate.COPY); + options.setAudioBitrate(BitrateParameter.Bitrate.COPY); + return options; + } - @SuppressWarnings("deprecation") - public File getTargetDirectory() { - final Date now = new Date(); - final GregorianCalendar calendar = new GregorianCalendar(); + @Override + public String getModuleCommand() { + return "grabmemcard"; + } - final StringBuffer directoryName = new StringBuffer(); - directoryName.append( - calendar.get(GregorianCalendar.YEAR) + "." + getDoubleDigit(calendar.get(GregorianCalendar.MONTH) + 1) - + "." + getDoubleDigit(calendar.get(GregorianCalendar.DAY_OF_MONTH)) + " "); + @SuppressWarnings("deprecation") + private File getTargetDirectory() { + final Date now = new Date(); + final GregorianCalendar calendar = new GregorianCalendar(); - directoryName.append(getDoubleDigit(now.getHours()) + ":" + getDoubleDigit(now.getMinutes()) + ":" - + getDoubleDigit(now.getSeconds())); + 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.toString() + "/"; + final String targetDirectoryPath = CommonPathResolver.getDesktopDirectory().getAbsolutePath() + "/" + + directoryName + "/"; - System.out.println("Target directory path: " + targetDirectoryPath); + System.out.println("Target directory path: " + targetDirectoryPath); - return new File(targetDirectoryPath); - } + return new File(targetDirectoryPath); + } - private File getTargetFile(final File targetDirectory, final File sourceFile) { - // compute target file path - final StringBuffer targetFilePath = new StringBuffer(); - targetFilePath.append(targetDirectory.getAbsolutePath()); - targetFilePath.append("/"); - targetFilePath.append(FilePathParser.getFileNameWithoutExtension(sourceFile)); - targetFilePath.append(".mp4"); - final File targetFile = new File(targetFilePath.toString()); - return targetFile; - } + 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 { + @Override + public void run(final String[] args) throws IOException { - final File targetDirectory = getTargetDirectory(); - targetDirectory.mkdirs(); + final File targetDirectory = getTargetDirectory(); + targetDirectory.mkdirs(); - final AbstractConverter converter = new AvconvVideo(); - final EncodingPlan encodingPlan = new EncodingPlan(); + final AbstractConverter converter = new AvconvVideo(); + final EncodingPlan encodingPlan = new EncodingPlan(); - final String userName = System.getProperty("user.name"); + final String userName = System.getProperty("user.name"); - final File file = new File("/media/" + userName + "/"); + final File file = new File("/media/" + userName + "/"); - for (final File insertedDisk : file.listFiles()) { - final File[] diskVideos = getDiskVideos(insertedDisk); + for (final File insertedDisk : file.listFiles()) { + final File[] diskVideos = getDiskVideos(insertedDisk); - for (final File sourceFile : diskVideos) { + for (final File sourceFile : diskVideos) { - final File targetFile = getTargetFile(targetDirectory, sourceFile); + final File targetFile = getTargetFile(targetDirectory, sourceFile); - final EncodingTask encodingTask = new EncodingTask(sourceFile, targetFile, converter, "mp4"); - encodingTask.setUseTerminal(true); - encodingPlan.scheduleTask(encodingTask); - } - } + final EncodingTask encodingTask = new EncodingTask(sourceFile, targetFile, converter, "mp4"); + encodingTask.setUseTerminal(true); + encodingPlan.scheduleTask(encodingTask); + } + } - encodingPlan.execute(getEncodingOptions()); - } + encodingPlan.execute(getEncodingOptions()); + } - @Override - public void showCommandlineHelp() { - System.out.println("memory card grabber has no commandline options"); - } + @Override + public void showCommandlineHelp() { + System.out.println("memory card grabber has no commandline options"); + } }