diff --git a/importPicture/AdjustTime.ini b/importPicture/AdjustTime.ini index ad911f6..f3fed27 100644 --- a/importPicture/AdjustTime.ini +++ b/importPicture/AdjustTime.ini @@ -1,17 +1,17 @@ #by AdjustTime -#Sat May 20 20:05:59 JST 2017 +#Sat Jun 03 22:01:29 JST 2017 GPX.BASETIME=FILE_UPDATE IMG.OUTPUT_EXIF=true GPX.OUTPUT_WPT=false -GPX.OUTPUT_SPEED=false +GPX.OUTPUT_SPEED=true IMG.OUTPUT_ALL=false GPX.noFirstNode=true IMG.OUTPUT=true GPX.gpxSplit=true -IMG.TIME=2017-05-18T09\:20\:30 -GPX.OVERWRITE_MAGVAR=false +IMG.TIME=2017-05-29T10\:31\:46 +GPX.OVERWRITE_MAGVAR=true GPX.REUSE=false -IMG.BASE_FILE=20170518_092031A.jpg -IMG.SOURCE_FOLDER=./testdata/cameradata -GPX.SOURCE_FOLDER=./testdata/cameradata/20170518.gpx +IMG.BASE_FILE=20170529_103146A.jpg +IMG.SOURCE_FOLDER=./testdata/cameradata/separate +GPX.SOURCE_FOLDER=./testdata/cameradata/separate.gpx IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/output diff --git a/importPicture/AdjustTime.ini.org b/importPicture/AdjustTime.ini.org index 0ca8258..16100cd 100644 --- a/importPicture/AdjustTime.ini.org +++ b/importPicture/AdjustTime.ini.org @@ -1,17 +1,17 @@ #by AdjustTime -#Sat May 20 20:05:52 JST 2017 -GPX.BASETIME=FILE_UPDATE +#Sat Jun 03 22:00:34 JST 2017 +GPX.BASETIME=EXIF_TIME IMG.OUTPUT_EXIF=true GPX.OUTPUT_WPT=false -GPX.OUTPUT_SPEED=false -IMG.OUTPUT_ALL=true +GPX.OUTPUT_SPEED=true +IMG.OUTPUT_ALL=false GPX.noFirstNode=true IMG.OUTPUT=true GPX.gpxSplit=true -IMG.TIME=2017-05-18T09\:20\:30 -GPX.OVERWRITE_MAGVAR=false +IMG.TIME=2017-05-29T10\:31\:46 +GPX.OVERWRITE_MAGVAR=true GPX.REUSE=false -IMG.BASE_FILE=20170518_092031A.jpg -IMG.SOURCE_FOLDER=./testdata/cameradata -GPX.SOURCE_FOLDER=./testdata/cameradata/20170518.gpx +IMG.BASE_FILE=20170529_103146A.jpg +IMG.SOURCE_FOLDER=./testdata/cameradata/separate +GPX.SOURCE_FOLDER=./testdata/cameradata/separate.gpx IMG.OUTPUT_FOLDER=/home/yuu/workspace/AdjustTime/importPicture/testdata/output diff --git a/importPicture/src/osm/jp/gpx/ImportPicture.java b/importPicture/src/osm/jp/gpx/ImportPicture.java index c53411a..c3b4f35 100644 --- a/importPicture/src/osm/jp/gpx/ImportPicture.java +++ b/importPicture/src/osm/jp/gpx/ImportPicture.java @@ -249,14 +249,15 @@ if ((paramStr != null) && (paramStr.equals(Boolean.toString(true)))) { obj.exif = true; } - + System.out.println(" - param: imgDir = '"+ obj.imgDir.getAbsolutePath() +"'"); System.out.println(" - param: outDir = '"+ (obj.outDir == null ? "" : obj.outDir.getAbsolutePath()) +"'"); System.out.println(" - param: gpxDir = '"+ (obj.gpxDir == null ? "" : obj.gpxDir.getAbsolutePath()) +"'"); System.out.println(" - param: number of gpxFiles = '"+ obj.gpxFiles.size() +"'"); System.out.println(" - param: "+ AppParameters.GPX_GPXSPLIT +"="+ obj.param_GpxSplit); System.out.println(" - param: "+ AppParameters.GPX_NO_FIRST_NODE +"="+ obj.param_GpxNoFirstNode); - System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ obj.param_GpxReuse); + System.out.println(" - param: "+ AppParameters.GPX_REUSE +"="+ obj.param_GpxReuse); + System.out.println(" - param: "+ AppParameters.IMG_BASE_FILE +"="+ obj.params.getProperty(AppParameters.IMG_BASE_FILE) ); System.out.println(" - param: "+ AppParameters.GPX_BASETIME +"="+ obj.params.getProperty(AppParameters.GPX_BASETIME) ); System.out.println(" - param: "+ AppParameters.IMG_OUTPUT +"="+ obj.params.getProperty(AppParameters.IMG_OUTPUT)); System.out.println(" - param: "+ AppParameters.IMG_OUTPUT_ALL +"="+ obj.param_ImgOutputAll); @@ -466,11 +467,11 @@ System.out.println("GPX start time: "+ dfjp.format(new Date(gpxStartTime)) + "\t[GMT " + dfuk.format(new Date(gpxStartTime))+"]"); System.out.println(" GPX end time: "+ dfjp.format(new Date(gpxEndTime)) + "\t[GMT " + dfuk.format(new Date(gpxEndTime))+"]"); - System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|"); - System.out.println(" name | UpdateTime | GPStime | Latitude | Longitude | ele |magvar| km/h |"); - System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|"); + System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); + System.out.println(" name | UpdateTime | GPStime | Latitude | Longitude | ele |magvar| km/h |"); + System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); proc(imgDir, delta, gpxStartTime, gpxEndTime, map, exif, gpx); - System.out.println("------------------------|--------------------|--------------------|------------|------------|--------|------|------|"); + System.out.println("------------------------|--------------------|--------------------|--------------|--------------|--------|------|------|"); // 出力 outputFile.getParentFile().mkdirs(); @@ -581,7 +582,7 @@ if (trkptT.speedStr != null) { speedStr = new String(trkptT.speedStr); } - System.out.print(String.format("%12s %12s|", (new Double(latitude)).toString(), (new Double(longitude)).toString())); + System.out.print(String.format("%-14s %-14s|", (new Double(latitude)).toString(), (new Double(longitude)).toString())); System.out.println(String.format("%8s|%6s|%6s|", eleStr, magvarStr, speedStr)); } diff --git a/importPicture/test/osm/jp/gpx/ImportPictureTest.java b/importPicture/test/osm/jp/gpx/ImportPictureTest.java index 5eb6292..83bf1f3 100644 --- a/importPicture/test/osm/jp/gpx/ImportPictureTest.java +++ b/importPicture/test/osm/jp/gpx/ImportPictureTest.java @@ -3,17 +3,24 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.nio.channels.FileChannel; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.junit.Before; import org.junit.Test; import org.junit.runner.*; import org.junit.experimental.runners.Enclosed; import hayashi.tools.files.DeleteDir; +import osm.jp.gpx.utils.TarGz; @RunWith(Enclosed.class) public class ImportPictureTest { @@ -34,7 +41,7 @@ outDir.mkdir(); // カメラディレクトリを作成する - TarGz.uncompress(new File("testdata", "Sony20170518.tar.gz"), dir); + uncompress(new File("testdata", "Sony20170518.tar.gz"), dir); // GPXファイルをセット try ( FileInputStream inStream = new FileInputStream(new File("testdata", "20170518.gpx")); @@ -251,4 +258,166 @@ } } } + + public static class GPXが複数のTRKSEGに分割している場合 { + + @Before + public void setUp() throws Exception { + // カメラディレクトリを削除する + File dir = new File("testdata/cameradata"); + if (dir.exists()) { + DeleteDir.delete(dir); + } + File outDir = new File("testdata/output"); + if (outDir.exists()) { + DeleteDir.delete(outDir); + } + outDir.mkdir(); + + // カメラディレクトリを作成する + TarGz.uncompress(new File("testdata", "separate.tar.gz"), dir); + + // GPXファイルをセット + try ( FileInputStream inStream = new FileInputStream(new File("testdata", "separate.gpx")); + FileOutputStream outStream = new FileOutputStream(new File("testdata/cameradata/separate.gpx")); + FileChannel inChannel = inStream.getChannel(); + FileChannel outChannel = outStream.getChannel(); ) + { + inChannel.transferTo(0, inChannel.size(), outChannel); + } + + // プロパティファイルを設定 + File iniFile = new File("AdjustTime.ini"); + File orgFile = new File("AdjustTime.ini.org"); + File testFile = new File("testdata", "AdjustTime.separate.ini"); + if (orgFile.exists()) { + orgFile.delete(); + } + if (iniFile.exists()) { + iniFile.renameTo(orgFile); + } + try ( FileInputStream inStream = new FileInputStream(testFile); + FileOutputStream outStream = new FileOutputStream(new File("AdjustTime.ini")); + FileChannel inChannel = inStream.getChannel(); + FileChannel outChannel = outStream.getChannel(); ) + { + inChannel.transferTo(0, inChannel.size(),outChannel); + } + + AppParameters params = new AppParameters(); + params.setProperty(AppParameters.IMG_TIME, "2017-05-29T10:31:46"); + params.setProperty(AppParameters.IMG_BASE_FILE, "20170529_103146A.jpg"); + params.setProperty(AppParameters.IMG_SOURCE_FOLDER, "./testdata/cameradata/separate"); + params.setProperty(AppParameters.GPX_SOURCE_FOLDER, "./testdata/cameradata/separate.gpx"); + params.store(); + } + + @Test + public void FILE_UPDATE時間を基準にして時間外のファイルはコピー対象外の時() throws Exception { + AppParameters params = new AppParameters(); + params.setProperty(AppParameters.GPX_BASETIME, "FILE_UPDATE"); + params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false"); + params.store(); + + // 実行する + testdo(); + + File gpxfile = new File("./testdata/output/cameradata/separate", "separate_.gpx"); + assertThat(gpxfile.exists(), is(true)); + File file0 = new File("./testdata/output/cameradata/separate", "20170529_102305A.jpg"); + assertThat(file0.exists(), is(false)); + File file1 = new File("./testdata/output/cameradata/separate", "20170529_103146A.jpg"); + assertThat(file1.exists(), is(true)); + File file3 = new File("./testdata/output/cameradata/separate", "20170529_103515A.jpg"); + assertThat(file3.exists(), is(true)); + File file4 = new File("./testdata/output/cameradata/separate", "20170529_104119A.jpg"); + assertThat(file4.exists(), is(true)); + } + + @Test + public void EXIF時間を基準にして時間外のファイルはコピー対象外の時() throws Exception { + AppParameters params = new AppParameters(); + params.setProperty(AppParameters.GPX_BASETIME, "EXIF_TIME"); + params.setProperty(AppParameters.IMG_OUTPUT_ALL, "false"); + params.store(); + + // 実行する + testdo(); + + File gpxfile = new File("./testdata/output/cameradata/separate", "separate_.gpx"); + assertThat(gpxfile.exists(), is(true)); + File file0 = new File("./testdata/output/cameradata/separate", "20170529_102305A.jpg"); + assertThat(file0.exists(), is(false)); + File file1 = new File("./testdata/output/cameradata/separate", "20170529_103146A.jpg"); + assertThat(file1.exists(), is(true)); + File file3 = new File("./testdata/output/cameradata/separate", "20170529_103515A.jpg"); + assertThat(file3.exists(), is(true)); + File file4 = new File("./testdata/output/cameradata/separate", "20170529_104119A.jpg"); + assertThat(file4.exists(), is(true)); + } + + /** + * 実行する + * @throws Exception + */ + public void testdo() { + try { + String[] argv = { + "./testdata/cameradata/separate", + "20170529_103146A.jpg", + "2017-05-29T10:31:46", + "./testdata/output", + "./testdata/cameradata/separate.gpx" + }; + ImportPicture.main(argv); + } + catch (Exception e) { + e.printStackTrace(); + fail("Exceptionが発生した。"); + } + } + } + + /** + * *.tar.gz解凍 + * ファイル更新日時をオリジナルと同じにします。 + * @param tazFile 解凍する*.tar.gzファイル + * @param dest 解凍先フォルダ + * @throws IOException + */ + public static void uncompress(File tazFile, File dest) throws IOException { + dest.mkdir(); + + TarArchiveInputStream tarIn = null; + tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tazFile)))); + + TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); + while (tarEntry != null) { + File destPath = new File(dest, tarEntry.getName()); + System.out.println("uncompress: " + destPath.getCanonicalPath()); + if (tarEntry.isDirectory()) { + destPath.mkdirs(); + } + else { + File dir = new File(destPath.getParent()); + if (!dir.exists()) { + dir.mkdirs(); + } + destPath.createNewFile(); + byte[] btoRead = new byte[1024]; + BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath)); + int len = 0; + + while ((len = tarIn.read(btoRead)) != -1) { + bout.write(btoRead, 0, len); + } + + bout.close(); + destPath.setLastModified(tarEntry.getLastModifiedDate().getTime()); + btoRead = null; + } + tarEntry = tarIn.getNextTarEntry(); + } + tarIn.close(); + } } diff --git a/importPicture/test/osm/jp/gpx/TarGz.java b/importPicture/test/osm/jp/gpx/TarGz.java deleted file mode 100644 index 19559b3..0000000 --- a/importPicture/test/osm/jp/gpx/TarGz.java +++ /dev/null @@ -1,70 +0,0 @@ -package osm.jp.gpx; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; -import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; - -/** - * 「*.tar.gz」を解凍する。 - * ファイル更新日時をオリジナルと同じにします。 - * Apache Commons Compressライブラリ - * commons-compress-1.14.jar - */ -public abstract class TarGz -{ - public static void main(String[] args) throws IOException { - File baseDir = new File("testdata/cameradata"); - File tazFile = new File("testdata", "Sony20170518.tar.gz"); - TarGz.uncompress(tazFile, baseDir); - } - - /** - * *.tar.gz解凍 - * ファイル更新日時をオリジナルと同じにします。 - * @param tazFile 解凍する*.tar.gzファイル - * @param dest 解凍先フォルダ - * @throws IOException - */ - public static void uncompress(File tazFile, File dest) throws IOException { - dest.mkdir(); - - TarArchiveInputStream tarIn = null; - tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tazFile)))); - - TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); - while (tarEntry != null) { - File destPath = new File(dest, tarEntry.getName()); - System.out.println("uncompress: " + destPath.getCanonicalPath()); - if (tarEntry.isDirectory()) { - destPath.mkdirs(); - } - else { - File dir = new File(destPath.getParent()); - if (!dir.exists()) { - dir.mkdirs(); - } - destPath.createNewFile(); - byte[] btoRead = new byte[1024]; - BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath)); - int len = 0; - - while ((len = tarIn.read(btoRead)) != -1) { - bout.write(btoRead, 0, len); - } - - bout.close(); - destPath.setLastModified(tarEntry.getLastModifiedDate().getTime()); - btoRead = null; - } - tarEntry = tarIn.getNextTarEntry(); - } - tarIn.close(); - } -} diff --git a/importPicture/test/osm/jp/gpx/utils/TarGz.java b/importPicture/test/osm/jp/gpx/utils/TarGz.java new file mode 100644 index 0000000..069c02f --- /dev/null +++ b/importPicture/test/osm/jp/gpx/utils/TarGz.java @@ -0,0 +1,71 @@ +package osm.jp.gpx.utils; + + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; + +/** + * 「*.tar.gz」を解凍する。 + * ファイル更新日時をオリジナルと同じにします。 + * Apache Commons Compressライブラリ + * commons-compress-1.14.jar + */ +public abstract class TarGz +{ + public static void main(String[] args) throws IOException { + File baseDir = new File("testdata/cameradata"); + File tazFile = new File("testdata", "Sony20170518.tar.gz"); + TarGz.uncompress(tazFile, baseDir); + } + + /** + * *.tar.gz解凍 + * ファイル更新日時をオリジナルと同じにします。 + * @param tazFile 解凍する*.tar.gzファイル + * @param dest 解凍先フォルダ + * @throws IOException + */ + public static void uncompress(File tazFile, File dest) throws IOException { + dest.mkdir(); + + TarArchiveInputStream tarIn = null; + tarIn = new TarArchiveInputStream(new GzipCompressorInputStream(new BufferedInputStream(new FileInputStream(tazFile)))); + + TarArchiveEntry tarEntry = tarIn.getNextTarEntry(); + while (tarEntry != null) { + File destPath = new File(dest, tarEntry.getName()); + System.out.println("uncompress: " + destPath.getCanonicalPath()); + if (tarEntry.isDirectory()) { + destPath.mkdirs(); + } + else { + File dir = new File(destPath.getParent()); + if (!dir.exists()) { + dir.mkdirs(); + } + destPath.createNewFile(); + byte[] btoRead = new byte[1024]; + BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath)); + int len = 0; + + while ((len = tarIn.read(btoRead)) != -1) { + bout.write(btoRead, 0, len); + } + + bout.close(); + destPath.setLastModified(tarEntry.getLastModifiedDate().getTime()); + btoRead = null; + } + tarEntry = tarIn.getNextTarEntry(); + } + tarIn.close(); + } +}