File tree Expand file tree Collapse file tree
main/java/com/sapher/youtubedl
test/java/com/sapher/youtubedl Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -141,18 +141,8 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException {
141141 ObjectMapper objectMapper = new ObjectMapper ();
142142 VideoInfo videoInfo ;
143143
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-
153-
154144 try {
155- videoInfo = objectMapper .readValue (output , VideoInfo .class );
145+ videoInfo = objectMapper .readValue (response . getOut () , VideoInfo .class );
156146 } catch (IOException e ) {
157147 throw new YoutubeDLException ("Unable to parse video information: " + e .getMessage ());
158148 }
Original file line number Diff line number Diff line change 1+ package com .sapher .youtubedl ;
2+
3+ import java .io .IOException ;
4+
5+ import com .fasterxml .jackson .databind .ObjectMapper ;
6+ import com .sapher .youtubedl .mapper .VideoInfo ;
7+
8+ public class YoutubeDLProchains extends YoutubeDL {
9+
10+ /**
11+ * Retrieve all information available on a video
12+ * @param url Video url
13+ * @return Video info
14+ * @throws YoutubeDLException
15+ */
16+ public static VideoInfo getVideoInfo (String url ) throws YoutubeDLException {
17+
18+ //We use proxychains, here
19+ setExecutablePath ("proxychains youtube-dl" );
20+
21+ // Build request
22+ YoutubeDLRequest request = new YoutubeDLRequest (url );
23+ request .setOption ("dump-json" );
24+ request .setOption ("no-playlist" );
25+ YoutubeDLResponse response = YoutubeDL .execute (request );
26+
27+ // Parse result
28+ ObjectMapper objectMapper = new ObjectMapper ();
29+ VideoInfo videoInfo ;
30+
31+ //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n"
32+ String output = response .getOut ();
33+ output = output .substring (output .indexOf ("{" ));
34+
35+ try {
36+ videoInfo = objectMapper .readValue (output , VideoInfo .class );
37+ } catch (IOException e ) {
38+ throw new YoutubeDLException ("Unable to parse video information: " + e .getMessage ());
39+ }
40+
41+ return videoInfo ;
42+ }
43+ }
Original file line number Diff line number Diff line change @@ -95,10 +95,7 @@ public void testGetVideoInfoInDetails() throws YoutubeDLException {
9595
9696 @ Test
9797 public void testGetVideoInfoInDetailsWithProxychains () throws YoutubeDLException {
98- YoutubeDL youtubeDL = new YoutubeDL ();
99- youtubeDL .setExecutablePath ("proxychains youtube-dl" );
100-
101- VideoInfo videoInfo = youtubeDL .getVideoInfo (VIDEO_URL );
98+ VideoInfo videoInfo = YoutubeDLProchains .getVideoInfo (VIDEO_URL );
10299 Assert .assertNotNull (videoInfo );
103100 //Let's check we can access key elements from video info
104101 Assert .assertNotNull (videoInfo .getId ());
You can’t perform that action at this time.
0 commit comments