Skip to content

Commit 5bca24e

Browse files
committed
Great refactoring
1 parent b0059cf commit 5bca24e

5 files changed

Lines changed: 51 additions & 1388 deletions

File tree

src/main/java/com/sapher/youtubedl/YoutubeDL.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.sapher.youtubedl.mapper.VideoFormat;
55
import com.sapher.youtubedl.mapper.VideoInfo;
6-
import com.sapher.youtubedl.mapper.VideoSubtitle;
76
import com.sapher.youtubedl.mapper.VideoThumbnail;
87
import com.sapher.youtubedl.utils.StreamGobbler;
98

109
import java.io.File;
1110
import java.io.IOException;
1211
import java.io.InputStream;
1312
import java.util.List;
13+
import java.util.Map;
1414

1515
public class YoutubeDL {
1616
public static final String executableName = "youtube-dl";
@@ -19,7 +19,11 @@ private static String buildCommand(String command) {
1919
return String.format("%s %s", executableName, command);
2020
}
2121

22-
public static YoutubeDLResponse execute(String command, String directory) throws YoutubeDLException {
22+
public static YoutubeDLResponse execute(YoutubeDLRequest request) throws YoutubeDLException {
23+
24+
String command = buildCommand(request.buildOptions());
25+
String directory = request.getDirectory();
26+
Map<String, String> options = request.getOption();
2327

2428
YoutubeDLResponse youtubeDLResponse;
2529
Process process;
@@ -59,16 +63,11 @@ public static YoutubeDLResponse execute(String command, String directory) throws
5963

6064
int elapsedTime = (int) ((System.nanoTime() - startTime) / 1000000);
6165

62-
youtubeDLResponse = new YoutubeDLResponse(command, directory, exitCode , elapsedTime, outBuffer.toString(), errBuffer.toString());
66+
youtubeDLResponse = new YoutubeDLResponse(command, options, directory, exitCode , elapsedTime, outBuffer.toString(), errBuffer.toString());
6367

6468
return youtubeDLResponse;
6569
}
6670

67-
public static YoutubeDLResponse execute(YoutubeDLRequest request) throws YoutubeDLException {
68-
String command = request.buildOptions();
69-
return execute(buildCommand(command), request.getDirectory());
70-
}
71-
7271
/**
7372
* Retrieve all information available on a video
7473
* @param url Video url
@@ -79,7 +78,8 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException {
7978

8079
// Build request
8180
YoutubeDLRequest request = new YoutubeDLRequest(url);
82-
request.setDumpJson(true);
81+
//request.setDumpJson(true);
82+
request.setOption("dump-json");
8383
YoutubeDLResponse response = YoutubeDL.execute(request);
8484

8585
// Parse result
@@ -121,7 +121,7 @@ public static List<String> getTags(String url) throws YoutubeDLException {
121121
}**/
122122

123123
/**public static void d(String url, String dir, String format, int quality, String output) throws YoutubeDLException {
124-
YoutubeDLRequest request = new YoutubeDLRequest(dir, url);
124+
YoutubeDLRequest request = new YoutubeDLRequest(url, dir);
125125
request.setDirectory(dir);
126126
request.setExtractAudio(true);
127127
request.setFormat(format);

0 commit comments

Comments
 (0)