diff --git a/src/main/java/moe/nekojimi/chords/Downloader.java b/src/main/java/moe/nekojimi/chords/Downloader.java index eb09aee..f1a4a52 100644 --- a/src/main/java/moe/nekojimi/chords/Downloader.java +++ b/src/main/java/moe/nekojimi/chords/Downloader.java @@ -60,7 +60,8 @@ public class Downloader extends QueueThing // private Consumer next; private BiConsumer messageHandler; - private File downloadDir = null; + private File temporaryDownloadDir = null; + private File permanentDownloadDir = null; private int trackNumber = 1; @@ -313,9 +314,24 @@ public class Downloader extends QueueThing private File getDownloadDir() throws IOException { - if (downloadDir == null || !downloadDir.exists() || !downloadDir.canWrite()) - downloadDir = Files.createTempDirectory("chords").toFile(); - return downloadDir; + return getDownloadDir(false); + } + + private File getDownloadDir(boolean permanent) throws IOException + { + if (permanent) + { + if (permanentDownloadDir == null) + permanentDownloadDir = new File("tracks"); + if (!permanentDownloadDir.exists()) + Files.createDirectory(permanentDownloadDir.toPath()); + return permanentDownloadDir; + } else + { + if (temporaryDownloadDir == null || !temporaryDownloadDir.exists() || !temporaryDownloadDir.canWrite()) + temporaryDownloadDir = Files.createTempDirectory("chords").toFile(); + return temporaryDownloadDir; + } } private Track getTrackFromRequest(TrackRequest request, int idx) @@ -325,6 +341,7 @@ public class Downloader extends QueueThing { Track track = new Track(request); track.setNumber(trackNumber); + track.setKept(request.isKeepTracks()); trackNumber++; request.addTrack(track); } @@ -368,7 +385,7 @@ public class Downloader extends QueueThing cmd.add("-"); } else { - cmd.add("-o " + getDownloadDir().getAbsolutePath() + "/%(title)s.%(ext)s"); + cmd.add("-o " + getDownloadDir(false).getAbsolutePath() + "/%(title)s.%(ext)s"); } cmd.add(request.getUrl().toString());