Add support for downloading tracks to a permanent location.
This commit is contained in:
parent
3da1c95453
commit
88c51129d2
|
@ -60,7 +60,8 @@ public class Downloader extends QueueThing<TrackRequest, Track>
|
|||
// private Consumer<Track> next;
|
||||
private BiConsumer<TrackRequest, Exception> 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<TrackRequest, Track>
|
|||
|
||||
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<TrackRequest, Track>
|
|||
{
|
||||
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<TrackRequest, Track>
|
|||
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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue