Skip to content

Commit 7e39965

Browse files
committed
use proxychains - clean - we can now use proxychains or not
Though, we still need to use YoutubeDL after an initialization, not in a static way like when not using proxychains. (TODO)
1 parent daab3f5 commit 7e39965

2 files changed

Lines changed: 38 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class YoutubeDL {
2626
/**
2727
* Youtube-dl executable name
2828
*/
29-
protected static String executablePath = "proxychains youtube-dl";
29+
protected static String executablePath = "youtube-dl";
3030

3131
/**
3232
* Append executable name to command
@@ -141,12 +141,18 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException {
141141
ObjectMapper objectMapper = new ObjectMapper();
142142
VideoInfo videoInfo;
143143

144-
//Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n"
145-
String outputWihtoutHeader = response.getOut();
146-
outputWihtoutHeader = outputWihtoutHeader.substring(outputWihtoutHeader.indexOf("{"));
144+
String output;
145+
if(executablePath.contains("proxychains")) {
146+
//Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n"
147+
output = response.getOut();
148+
output = output.substring(output.indexOf("{"));
149+
}else {
150+
output = response.getOut();
151+
}
152+
147153

148154
try {
149-
videoInfo = objectMapper.readValue(outputWihtoutHeader, VideoInfo.class);
155+
videoInfo = objectMapper.readValue(output, VideoInfo.class);
150156
} catch (IOException e) {
151157
throw new YoutubeDLException("Unable to parse video information: " + e.getMessage());
152158
}

src/test/java/com/sapher/youtubedl/YoutubeDLTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,33 @@ public void testGetVideoInfoInDetails() throws YoutubeDLException {
9191
System.out.println("videoInfo:"+videoInfo.toString());
9292

9393

94+
}
95+
96+
@Test
97+
public void testGetVideoInfoInDetailsWithProxychains() throws YoutubeDLException {
98+
YoutubeDL youtubeDL = new YoutubeDL();
99+
youtubeDL.setExecutablePath("proxychains youtube-dl");
100+
101+
VideoInfo videoInfo = youtubeDL.getVideoInfo(VIDEO_URL);
102+
Assert.assertNotNull(videoInfo);
103+
//Let's check we can access key elements from video info
104+
Assert.assertNotNull(videoInfo.getId());
105+
Assert.assertNotNull(videoInfo.getTitle());
106+
Assert.assertNotNull(videoInfo.getFulltitle());
107+
Assert.assertNotNull(videoInfo.getDescription());
108+
Assert.assertNotNull(videoInfo.getThumbnail());
109+
Assert.assertNotNull(videoInfo.getUploaderId());
110+
Assert.assertNotNull(videoInfo.getUploader());
111+
Assert.assertNotNull(videoInfo.getUploadDate());
112+
Assert.assertNotNull(videoInfo.getDuration());
113+
Assert.assertNotNull(videoInfo.getViewCount());
114+
Assert.assertNotNull(videoInfo.getLikeCount());
115+
Assert.assertNotNull(videoInfo.getDislikeCount());
116+
Assert.assertNotNull(videoInfo.getAverageRating());
117+
//Let's print the whole object
118+
System.out.println("videoInfo:"+videoInfo.toString());
119+
120+
94121
}
95122

96123
@Test

0 commit comments

Comments
 (0)