Downloader: change timeout to 300 seconds, and fix destination parsing.
This commit is contained in:
parent
603b7e2cd8
commit
2412d57f4d
|
@ -6,7 +6,6 @@
|
||||||
package moe.nekojimi.chords;
|
package moe.nekojimi.chords;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
@ -59,7 +58,7 @@ public class Downloader implements Consumer<Song>
|
||||||
System.out.println("Running command: " + cmd);
|
System.out.println("Running command: " + cmd);
|
||||||
// Process exec = Runtime.getRuntime().exec().split(" "));
|
// Process exec = Runtime.getRuntime().exec().split(" "));
|
||||||
Process exec = new ProcessBuilder(cmd.split(" ")).redirectOutput(ProcessBuilder.Redirect.PIPE).start();
|
Process exec = new ProcessBuilder(cmd.split(" ")).redirectOutput(ProcessBuilder.Redirect.PIPE).start();
|
||||||
boolean done = exec.waitFor(30, TimeUnit.SECONDS);
|
boolean done = exec.waitFor(300, TimeUnit.SECONDS);
|
||||||
if (!done)
|
if (!done)
|
||||||
{
|
{
|
||||||
exec.destroyForcibly();
|
exec.destroyForcibly();
|
||||||
|
@ -68,7 +67,7 @@ public class Downloader implements Consumer<Song>
|
||||||
InputStream in = exec.getInputStream();
|
InputStream in = exec.getInputStream();
|
||||||
String output = new String(in.readAllBytes(), Charset.defaultCharset());
|
String output = new String(in.readAllBytes(), Charset.defaultCharset());
|
||||||
System.out.println(output);
|
System.out.println(output);
|
||||||
Matcher matcher = Pattern.compile("Destination: (.*)$").matcher(output);
|
Matcher matcher = Pattern.compile("Destination: (.*\\.wav)").matcher(output);
|
||||||
if (matcher.find())
|
if (matcher.find())
|
||||||
song.setLocation(new File(matcher.group(1)));
|
song.setLocation(new File(matcher.group(1)));
|
||||||
else if (exec.exitValue() != 0)
|
else if (exec.exitValue() != 0)
|
||||||
|
|
Loading…
Reference in New Issue