From dd20a5bec2246281663d0756717a5c9bd8eeecd2 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sun, 22 Jul 2018 16:21:22 +0200 Subject: [PATCH 01/13] Added fields and getters into VideoInfo so we could catch view_count, like_count, dislike_count, repost_count, average_rating and more. Also updated the test class YoutubeDLTest.java accordingly. --- .../sapher/youtubedl/mapper/VideoInfo.java | 70 +++++++++++++++++++ .../com/sapher/youtubedl/YoutubeDLTest.java | 22 ++++++ 2 files changed, 92 insertions(+) diff --git a/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java b/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java index ddbdf8d..cd738ce 100644 --- a/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java +++ b/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java @@ -19,6 +19,18 @@ public class VideoInfo { public String description; public String thumbnail; public String license; + + @JsonProperty("view_count") + public String viewCount; + @JsonProperty("like_count") + public String likeCount; + @JsonProperty("dislike_count") + public String dislikeCount; + @JsonProperty("repost_count") + public String repostCount; + @JsonProperty("average_rating") + public String averageRating; + @JsonProperty("uploader_id") public String uploaderId; @@ -44,4 +56,62 @@ public class VideoInfo { public ArrayList formats; public ArrayList thumbnails; //public ArrayList subtitles; + + //some useful getters + public String getViewCount() { + return viewCount; + } + public String getLikeCount() { + return likeCount; + } + public String getDislikeCount() { + return dislikeCount; + } + public String getRepostCount() { + return repostCount; + } + public String getAverageRating() { + return averageRating; + } + public String getId() { + return id; + } + public String getFulltitle() { + return fulltitle; + } + public String getTitle() { + return title; + } + public String getUploadDate() { + return uploadDate; + } + public int getDuration() { + return duration; + } + public String getDescription() { + return description; + } + public String getThumbnail() { + return thumbnail; + } + public String getUploaderId() { + return uploaderId; + } + public String getUploader() { + return uploader; + } + @Override + public String toString() { + return "VideoInfo [id=" + id + ", fulltitle=" + fulltitle + ", title=" + title + ", uploadDate=" + uploadDate + + ", displayId=" + displayId + ", duration=" + duration + ", description=" + description + + ", thumbnail=" + thumbnail + ", license=" + license + ", viewCount=" + viewCount + ", likeCount=" + + likeCount + ", dislikeCount=" + dislikeCount + ", repostCount=" + repostCount + ", averageRating=" + + averageRating + ", uploaderId=" + uploaderId + ", uploader=" + uploader + ", playerUrl=" + playerUrl + + ", webpageUrl=" + webpageUrl + ", webpageUrlBasename=" + webpageUrlBasename + ", resolution=" + + resolution + ", width=" + width + ", height=" + height + ", format=" + format + ", ext=" + ext + + ", httpHeader=" + httpHeader + ", categories=" + categories + ", tags=" + tags + ", formats=" + + formats + ", thumbnails=" + thumbnails + "]"; + } + + } diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java index ca8d5e7..ac522af 100644 --- a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java @@ -68,6 +68,28 @@ public void testGetVideoInfo() throws YoutubeDLException { VideoInfo videoInfo = YoutubeDL.getVideoInfo(VIDEO_URL); Assert.assertNotNull(videoInfo); } + + @Test + public void testGetVideoInfoInDetails() throws YoutubeDLException { + VideoInfo videoInfo = YoutubeDL.getVideoInfo(VIDEO_URL); + Assert.assertNotNull(videoInfo); + //Let's check we can access key elements from video info + Assert.assertNotNull(videoInfo.getId()); + Assert.assertNotNull(videoInfo.getTitle()); + Assert.assertNotNull(videoInfo.getFulltitle()); + Assert.assertNotNull(videoInfo.getDescription()); + Assert.assertNotNull(videoInfo.getThumbnail()); + Assert.assertNotNull(videoInfo.getUploaderId()); + Assert.assertNotNull(videoInfo.getUploader()); + Assert.assertNotNull(videoInfo.getUploadDate()); + Assert.assertNotNull(videoInfo.getDuration()); + Assert.assertNotNull(videoInfo.getViewCount()); + Assert.assertNotNull(videoInfo.getLikeCount()); + Assert.assertNotNull(videoInfo.getDislikeCount()); + Assert.assertNotNull(videoInfo.getAverageRating()); + + + } @Test public void testGetFormats() throws YoutubeDLException { From 2252704a468b4f399dbd2064d71aa25a79f11c99 Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 22 Jul 2018 16:27:37 +0200 Subject: [PATCH 02/13] Update README.md Added the way to import the project dependency into a maven project --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index f40153b..d24d4de 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,29 @@ dependencies { } ``` +### Maven + +*Step 1 :* Add jitpack repository to your pom.xml file + +``` + + + jitpack.io + https://jitpack.io + + +``` + +*Step 2:* Add the dependency + +``` + + com.github.sapher + youtubedl-java + 1.1 + +``` + ## Make request ```java From c60909ad4393382a6244531944a4d18147394fbf Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 22 Jul 2018 16:30:41 +0200 Subject: [PATCH 03/13] Update README.md Corrected version 1.1 to 1.+ To import, check what's in the tag here https://github.com/sapher/youtubedl-java/blob/master/pom.xml --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d24d4de..1dcd23e 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ dependencies { com.github.sapher youtubedl-java - 1.1 + 1.+ ``` From c2077467a089f6ccda452551563e0f9deb52dd88 Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 22 Jul 2018 17:00:00 +0200 Subject: [PATCH 04/13] Update pom.xml I forgot to increment version ;) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 58c79ee..64902cb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sapher youtubedl - 1.1 + 1.2 jar YoutubeDL wrapper From 05bc2e7567d20d6107ecd89cb2bc9bb56e34c8ba Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sat, 30 Nov 2019 03:20:06 +0100 Subject: [PATCH 05/13] Added some mapping fields and also add verbosity to test class --- pom.xml | 2 +- .../sapher/youtubedl/mapper/VideoInfo.java | 66 ++++++++++++++++--- .../com/sapher/youtubedl/YoutubeDLTest.java | 2 + 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 64902cb..edc8cd8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sapher youtubedl - 1.2 + 1.2.1 jar YoutubeDL wrapper diff --git a/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java b/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java index cd738ce..0495804 100644 --- a/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java +++ b/src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java @@ -35,6 +35,47 @@ public class VideoInfo { @JsonProperty("uploader_id") public String uploaderId; public String uploader; + + @JsonProperty("channel_url") + public String channelUrl; + + @JsonProperty("channel_id") + public String channelId; + + @JsonProperty("uploader_url") + public String uploaderUrl; + + public String track; + public String playlist; + @JsonProperty("playlist_index") + public String playlistIndex; + @JsonProperty("episode_number") + public String episodeNumber; + @JsonProperty("season_number") + public String seasonNumber; + + @JsonProperty("is_live") + public String isLive; + public String series; + + @JsonProperty("release_date") + public String releaseDate; + @JsonProperty("release_year") + public String releaseYear; + + + @JsonProperty("scan_date") + public String scanDate; + + public String creator; + public String artist; + @JsonProperty("alt_title") + public String altTitle; + @JsonProperty("extractor_key") + public String extractorKey; + public String chapters; + public String album; + @JsonProperty("player_url") public String playerUrl; @@ -102,16 +143,23 @@ public String getUploader() { } @Override public String toString() { - return "VideoInfo [id=" + id + ", fulltitle=" + fulltitle + ", title=" + title + ", uploadDate=" + uploadDate - + ", displayId=" + displayId + ", duration=" + duration + ", description=" + description - + ", thumbnail=" + thumbnail + ", license=" + license + ", viewCount=" + viewCount + ", likeCount=" - + likeCount + ", dislikeCount=" + dislikeCount + ", repostCount=" + repostCount + ", averageRating=" - + averageRating + ", uploaderId=" + uploaderId + ", uploader=" + uploader + ", playerUrl=" + playerUrl - + ", webpageUrl=" + webpageUrl + ", webpageUrlBasename=" + webpageUrlBasename + ", resolution=" - + resolution + ", width=" + width + ", height=" + height + ", format=" + format + ", ext=" + ext - + ", httpHeader=" + httpHeader + ", categories=" + categories + ", tags=" + tags + ", formats=" - + formats + ", thumbnails=" + thumbnails + "]"; + return "VideoInfo [id=" + id + "\n, fulltitle=" + fulltitle + "\n, title=" + title + "\n, uploadDate=" + uploadDate + + "\n, displayId=" + displayId + "\n, duration=" + duration + "\n, description=" + description + + "\n, thumbnail=" + thumbnail + "\n, license=" + license + "\n, viewCount=" + viewCount + "\n, likeCount=" + + likeCount + "\n, dislikeCount=" + dislikeCount + "\n, repostCount=" + repostCount + "\n, averageRating=" + + averageRating + "\n, uploaderId=" + uploaderId + "\n, uploader=" + uploader + "\n, channelUrl=" + channelUrl + + "\n, channelId=" + channelId + "\n, uploaderUrl=" + uploaderUrl + "\n, track=" + track + "\n, playlist=" + + playlist + "\n, playlistIndex=" + playlistIndex + "\n, episodeNumber=" + episodeNumber + "\n, seasonNumber=" + + seasonNumber + "\n, isLive=" + isLive + "\n, series=" + series + "\n, releaseDate=" + releaseDate + + "\n, releaseYear=" + releaseYear + "\n, scanDate=" + scanDate + "\n, creator=" + creator + "\n, artist=" + + artist + "\n, altTitle=" + altTitle + "\n, extractorKey=" + extractorKey + "\n, chapters=" + chapters + + "\n, album=" + album + "\n, playerUrl=" + playerUrl + "\n, webpageUrl=" + webpageUrl + + "\n, webpageUrlBasename=" + webpageUrlBasename + "\n, resolution=" + resolution + "\n, width=" + width + + "\n, height=" + height + "\n, format=" + format + "\n, ext=" + ext + "\n, httpHeader=" + httpHeader + + "\n, categories=" + categories + "\n, tags=" + tags + "\n, formats=" + formats + "\n, thumbnails=" + + thumbnails + "]"; } + } diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java index ac522af..3033139 100644 --- a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java @@ -87,6 +87,8 @@ public void testGetVideoInfoInDetails() throws YoutubeDLException { Assert.assertNotNull(videoInfo.getLikeCount()); Assert.assertNotNull(videoInfo.getDislikeCount()); Assert.assertNotNull(videoInfo.getAverageRating()); + //Let's print the whole object + System.out.println("videoInfo:"+videoInfo.toString()); } From 10638b5b42c4f9f1cf61e62098d1e394b0b030d6 Mon Sep 17 00:00:00 2001 From: Alexandre Date: Sat, 30 Nov 2019 03:28:42 +0100 Subject: [PATCH 06/13] modified the version number to better stick to the release version history --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index edc8cd8..9be4d69 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sapher youtubedl - 1.2.1 + 1.3 jar YoutubeDL wrapper From 3357a02782f0f817570d3e0217511d6e0b6a3bdc Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 1 Dec 2019 21:54:20 +0100 Subject: [PATCH 07/13] updated .gitignore --- .gitignore | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6d4941d..71d2f22 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,9 @@ target/ # Gradle .gradle -gradle \ No newline at end of file +gradle + +# eclipse +.settings/ +.classpath +.project \ No newline at end of file From daab3f5152c8ba04c5ef7f9c19721d3f2ea25c94 Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 1 Dec 2019 21:55:28 +0100 Subject: [PATCH 08/13] This version uses proxychains Here, proxychains is mandatory --- pom.xml | 2 +- src/main/java/com/sapher/youtubedl/YoutubeDL.java | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 9be4d69..f773c5b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sapher youtubedl - 1.3 + 1.3-with-proxychains jar YoutubeDL wrapper diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDL.java b/src/main/java/com/sapher/youtubedl/YoutubeDL.java index 6cb26ec..8604fb9 100644 --- a/src/main/java/com/sapher/youtubedl/YoutubeDL.java +++ b/src/main/java/com/sapher/youtubedl/YoutubeDL.java @@ -26,7 +26,7 @@ public class YoutubeDL { /** * Youtube-dl executable name */ - protected static String executablePath = "youtube-dl"; + protected static String executablePath = "proxychains youtube-dl"; /** * Append executable name to command @@ -140,9 +140,13 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { // Parse result ObjectMapper objectMapper = new ObjectMapper(); VideoInfo videoInfo; + + //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" + String outputWihtoutHeader = response.getOut(); + outputWihtoutHeader = outputWihtoutHeader.substring(outputWihtoutHeader.indexOf("{")); try { - videoInfo = objectMapper.readValue(response.getOut(), VideoInfo.class); + videoInfo = objectMapper.readValue(outputWihtoutHeader, VideoInfo.class); } catch (IOException e) { throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); } From 7e39965871c46cde6c5f43a1e34aa347995b8264 Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 1 Dec 2019 22:29:04 +0100 Subject: [PATCH 09/13] 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) --- .../java/com/sapher/youtubedl/YoutubeDL.java | 16 +++++++---- .../com/sapher/youtubedl/YoutubeDLTest.java | 27 +++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDL.java b/src/main/java/com/sapher/youtubedl/YoutubeDL.java index 8604fb9..a859364 100644 --- a/src/main/java/com/sapher/youtubedl/YoutubeDL.java +++ b/src/main/java/com/sapher/youtubedl/YoutubeDL.java @@ -26,7 +26,7 @@ public class YoutubeDL { /** * Youtube-dl executable name */ - protected static String executablePath = "proxychains youtube-dl"; + protected static String executablePath = "youtube-dl"; /** * Append executable name to command @@ -141,12 +141,18 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { ObjectMapper objectMapper = new ObjectMapper(); VideoInfo videoInfo; - //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" - String outputWihtoutHeader = response.getOut(); - outputWihtoutHeader = outputWihtoutHeader.substring(outputWihtoutHeader.indexOf("{")); + String output; + if(executablePath.contains("proxychains")) { + //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" + output = response.getOut(); + output = output.substring(output.indexOf("{")); + }else { + output = response.getOut(); + } + try { - videoInfo = objectMapper.readValue(outputWihtoutHeader, VideoInfo.class); + videoInfo = objectMapper.readValue(output, VideoInfo.class); } catch (IOException e) { throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); } diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java index 3033139..78b803f 100644 --- a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java @@ -91,6 +91,33 @@ public void testGetVideoInfoInDetails() throws YoutubeDLException { System.out.println("videoInfo:"+videoInfo.toString()); + } + + @Test + public void testGetVideoInfoInDetailsWithProxychains() throws YoutubeDLException { + YoutubeDL youtubeDL = new YoutubeDL(); + youtubeDL.setExecutablePath("proxychains youtube-dl"); + + VideoInfo videoInfo = youtubeDL.getVideoInfo(VIDEO_URL); + Assert.assertNotNull(videoInfo); + //Let's check we can access key elements from video info + Assert.assertNotNull(videoInfo.getId()); + Assert.assertNotNull(videoInfo.getTitle()); + Assert.assertNotNull(videoInfo.getFulltitle()); + Assert.assertNotNull(videoInfo.getDescription()); + Assert.assertNotNull(videoInfo.getThumbnail()); + Assert.assertNotNull(videoInfo.getUploaderId()); + Assert.assertNotNull(videoInfo.getUploader()); + Assert.assertNotNull(videoInfo.getUploadDate()); + Assert.assertNotNull(videoInfo.getDuration()); + Assert.assertNotNull(videoInfo.getViewCount()); + Assert.assertNotNull(videoInfo.getLikeCount()); + Assert.assertNotNull(videoInfo.getDislikeCount()); + Assert.assertNotNull(videoInfo.getAverageRating()); + //Let's print the whole object + System.out.println("videoInfo:"+videoInfo.toString()); + + } @Test From e1754032e6109a8008ba937aad4e3f2ea04c4efa Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 1 Dec 2019 22:56:16 +0100 Subject: [PATCH 10/13] Bless inheritance! Use YoutubeDL or YoutubeDLProchains, in a static way! --- .../java/com/sapher/youtubedl/YoutubeDL.java | 12 +----- .../sapher/youtubedl/YoutubeDLProchains.java | 43 +++++++++++++++++++ .../com/sapher/youtubedl/YoutubeDLTest.java | 5 +-- 3 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDL.java b/src/main/java/com/sapher/youtubedl/YoutubeDL.java index a859364..7c60902 100644 --- a/src/main/java/com/sapher/youtubedl/YoutubeDL.java +++ b/src/main/java/com/sapher/youtubedl/YoutubeDL.java @@ -141,18 +141,8 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { ObjectMapper objectMapper = new ObjectMapper(); VideoInfo videoInfo; - String output; - if(executablePath.contains("proxychains")) { - //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" - output = response.getOut(); - output = output.substring(output.indexOf("{")); - }else { - output = response.getOut(); - } - - try { - videoInfo = objectMapper.readValue(output, VideoInfo.class); + videoInfo = objectMapper.readValue(response.getOut(), VideoInfo.class); } catch (IOException e) { throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); } diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java b/src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java new file mode 100644 index 0000000..df0513b --- /dev/null +++ b/src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java @@ -0,0 +1,43 @@ +package com.sapher.youtubedl; + +import java.io.IOException; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sapher.youtubedl.mapper.VideoInfo; + +public class YoutubeDLProchains extends YoutubeDL{ + + /** + * Retrieve all information available on a video + * @param url Video url + * @return Video info + * @throws YoutubeDLException + */ + public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { + + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + + // Build request + YoutubeDLRequest request = new YoutubeDLRequest(url); + request.setOption("dump-json"); + request.setOption("no-playlist"); + YoutubeDLResponse response = YoutubeDL.execute(request); + + // Parse result + ObjectMapper objectMapper = new ObjectMapper(); + VideoInfo videoInfo; + + //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" + String output = response.getOut(); + output = output.substring(output.indexOf("{")); + + try { + videoInfo = objectMapper.readValue(output, VideoInfo.class); + } catch (IOException e) { + throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); + } + + return videoInfo; + } +} diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java index 78b803f..8618ca8 100644 --- a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java @@ -95,10 +95,7 @@ public void testGetVideoInfoInDetails() throws YoutubeDLException { @Test public void testGetVideoInfoInDetailsWithProxychains() throws YoutubeDLException { - YoutubeDL youtubeDL = new YoutubeDL(); - youtubeDL.setExecutablePath("proxychains youtube-dl"); - - VideoInfo videoInfo = youtubeDL.getVideoInfo(VIDEO_URL); + VideoInfo videoInfo = YoutubeDLProchains.getVideoInfo(VIDEO_URL); Assert.assertNotNull(videoInfo); //Let's check we can access key elements from video info Assert.assertNotNull(videoInfo.getId()); From 7d289a677466d9638afae0e23b9f2fd26159d43f Mon Sep 17 00:00:00 2001 From: memento Date: Mon, 2 Dec 2019 01:33:48 +0100 Subject: [PATCH 11/13] more comments, unit testing, some corrections --- .../sapher/youtubedl/YoutubeDLProchains.java | 43 ----- .../youtubedl/YoutubeDLProxychains.java | 132 +++++++++++++++ .../youtubedl/YoutubeDLProxychainsTest.java | 154 ++++++++++++++++++ .../com/sapher/youtubedl/YoutubeDLTest.java | 24 --- 4 files changed, 286 insertions(+), 67 deletions(-) delete mode 100644 src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java create mode 100644 src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java create mode 100644 src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java b/src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java deleted file mode 100644 index df0513b..0000000 --- a/src/main/java/com/sapher/youtubedl/YoutubeDLProchains.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.sapher.youtubedl; - -import java.io.IOException; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.sapher.youtubedl.mapper.VideoInfo; - -public class YoutubeDLProchains extends YoutubeDL{ - - /** - * Retrieve all information available on a video - * @param url Video url - * @return Video info - * @throws YoutubeDLException - */ - public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { - - //We use proxychains, here - setExecutablePath("proxychains youtube-dl"); - - // Build request - YoutubeDLRequest request = new YoutubeDLRequest(url); - request.setOption("dump-json"); - request.setOption("no-playlist"); - YoutubeDLResponse response = YoutubeDL.execute(request); - - // Parse result - ObjectMapper objectMapper = new ObjectMapper(); - VideoInfo videoInfo; - - //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" - String output = response.getOut(); - output = output.substring(output.indexOf("{")); - - try { - videoInfo = objectMapper.readValue(output, VideoInfo.class); - } catch (IOException e) { - throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); - } - - return videoInfo; - } -} diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java b/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java new file mode 100644 index 0000000..753722d --- /dev/null +++ b/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java @@ -0,0 +1,132 @@ +package com.sapher.youtubedl; + +import java.io.IOException; +import java.util.List; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sapher.youtubedl.mapper.VideoFormat; +import com.sapher.youtubedl.mapper.VideoInfo; +import com.sapher.youtubedl.mapper.VideoThumbnail; + +/** + * @author memento + * This class is child class from YoutubeDL that allows to use youtube-dl behind a Tor "Proxychains" software to avoid BAN for example. + * + * Test class: YoutubeDLProxychainsTest + * + * Before using this class, be sure you have installed proxychains on your machine + * If you're using debian/ubuntu, install this powerful tool by typing this in your terminal : + * > sudo apt-get install proxychains tor obfsproxy + * + * (Other linux distributions : https://www.linuxsecrets.com/3372-install-setup-proxychains-on-linux ) + * + * Normally, to use youtube-dl behind proxychains, you'd execute (example) : + * > proxychains youtube-dl https://www.youtube.com/watch?v=nMfPqeZjc2c + * + * pros : you stay anonymous and you avoid being ban + * cons : the queries take longer + * + */ +public class YoutubeDLProxychains extends YoutubeDL{ + + /** + * Execute youtube-dl request + * @param request request object + * @return response object + * @throws YoutubeDLException + */ + public static YoutubeDLResponse execute(YoutubeDLRequest request) throws YoutubeDLException { + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + return execute(request, null); + } + + /** + * Retrieve all information available on a video + * @param url Video url + * @return Video info + * @throws YoutubeDLException + */ + public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + + // Build request + YoutubeDLRequest request = new YoutubeDLRequest(url); + request.setOption("dump-json"); + request.setOption("no-playlist"); + YoutubeDLResponse response = execute(request); + + // Parse result + ObjectMapper objectMapper = new ObjectMapper(); + VideoInfo videoInfo; + + //Proxychains : remove proxychains header ex: "ProxyChains-3.1 (http://proxychains.sf.net)\n" + String output = response.getOut(); + output = output.substring(output.indexOf("{")); + + try { + videoInfo = objectMapper.readValue(output, VideoInfo.class); + } catch (IOException e) { + throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); + } + + return videoInfo; + } + + /** + * List formats + * @param url Video url + * @return list of formats + * @throws YoutubeDLException + */ + public static List getFormats(String url) throws YoutubeDLException { + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + + VideoInfo info = getVideoInfo(url); + return info.formats; + } + + /** + * List thumbnails + * @param url Video url + * @return list of thumbnail + * @throws YoutubeDLException + */ + public static List getThumbnails(String url) throws YoutubeDLException { + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + + VideoInfo info = getVideoInfo(url); + return info.thumbnails; + } + + /** + * List categories + * @param url Video url + * @return list of category + * @throws YoutubeDLException + */ + public static List getCategories(String url) throws YoutubeDLException { + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + + VideoInfo info = getVideoInfo(url); + return info.categories; + } + + /** + * List tags + * @param url Video url + * @return list of tag + * @throws YoutubeDLException + */ + public static List getTags(String url) throws YoutubeDLException { + //We use proxychains, here + setExecutablePath("proxychains youtube-dl"); + + VideoInfo info = getVideoInfo(url); + return info.tags; + } +} diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java new file mode 100644 index 0000000..97046ac --- /dev/null +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java @@ -0,0 +1,154 @@ +package com.sapher.youtubedl; + +import com.sapher.youtubedl.mapper.VideoFormat; +import com.sapher.youtubedl.mapper.VideoInfo; +import com.sapher.youtubedl.mapper.VideoThumbnail; +import com.sapher.youtubedl.YoutubeDLProxychains; +import org.junit.Test; +import org.junit.Assert; + +import java.util.List; + +public class YoutubeDLProxychainsTest{ + + private final static String DIRECTORY = System.getProperty("java.io.tmpdir"); + private final static String VIDEO_URL = "https://www.youtube.com/watch?v=nMfPqeZjc2c"; + private final static String NONE_EXISTENT_VIDEO_URL = "https://www.youtube.com/watch?v=dQw4w9WgXcZ"; + + /**@Test + public void testUsingOwnExecutablePath() throws YoutubeDLException { + YoutubeDLProxychains.setExecutablePath("/usr/bin/youtube-dl"); + Assert.assertNotNull(YoutubeDLProxychains.getVersion()); + }**/ + + @Test + public void testGetVersion() throws YoutubeDLException { + Assert.assertNotNull(YoutubeDLProxychains.getVersion()); + } + + @Test + public void testElapsedTime() throws YoutubeDLException { + + long startTime = System.nanoTime(); + + YoutubeDLRequest request = new YoutubeDLRequest(); + request.setOption("version"); + YoutubeDLResponse response = YoutubeDLProxychains.execute(request); + + int elapsedTime = (int) (System.nanoTime() - startTime); + + Assert.assertTrue(elapsedTime > response.getElapsedTime()); + } + + + @Test + public void testSimulateDownload() throws YoutubeDLException { + + YoutubeDLRequest request = new YoutubeDLRequest(); + request.setUrl(VIDEO_URL); + request.setOption("simulate"); + + YoutubeDLResponse response = YoutubeDLProxychains.execute(request); + System.out.println(response.getCommand()); + Assert.assertEquals("proxychains youtube-dl " + VIDEO_URL + " --simulate", response.getCommand()); + } + + @Test + public void testDirectory() throws YoutubeDLException { + + YoutubeDLRequest request = new YoutubeDLRequest(VIDEO_URL, DIRECTORY); + request.setOption("simulate"); + + YoutubeDLResponse response = YoutubeDLProxychains.execute(request); + + Assert.assertEquals(DIRECTORY, response.getDirectory()); + } + + @Test + public void testGetVideoInfo() throws YoutubeDLException { + VideoInfo videoInfo = YoutubeDLProxychains.getVideoInfo(VIDEO_URL); + Assert.assertNotNull(videoInfo); + } + + @Test + public void testGetVideoInfoInDetails() throws YoutubeDLException { + VideoInfo videoInfo = YoutubeDLProxychains.getVideoInfo(VIDEO_URL); + Assert.assertNotNull(videoInfo); + //Let's check we can access key elements from video info + Assert.assertNotNull(videoInfo.getId()); + Assert.assertNotNull(videoInfo.getTitle()); + Assert.assertNotNull(videoInfo.getFulltitle()); + Assert.assertNotNull(videoInfo.getDescription()); + Assert.assertNotNull(videoInfo.getThumbnail()); + Assert.assertNotNull(videoInfo.getUploaderId()); + Assert.assertNotNull(videoInfo.getUploader()); + Assert.assertNotNull(videoInfo.getUploadDate()); + Assert.assertNotNull(videoInfo.getDuration()); + Assert.assertNotNull(videoInfo.getViewCount()); + Assert.assertNotNull(videoInfo.getLikeCount()); + Assert.assertNotNull(videoInfo.getDislikeCount()); + Assert.assertNotNull(videoInfo.getAverageRating()); + //Let's print the whole object + System.out.println("videoInfo:"+videoInfo.toString()); + + + } + + @Test + public void testGetVideoInfoInDetailsWithProxychains() throws YoutubeDLException { + VideoInfo videoInfo = YoutubeDLProxychains.getVideoInfo(VIDEO_URL); + Assert.assertNotNull(videoInfo); + //Let's check we can access key elements from video info + Assert.assertNotNull(videoInfo.getId()); + Assert.assertNotNull(videoInfo.getTitle()); + Assert.assertNotNull(videoInfo.getFulltitle()); + Assert.assertNotNull(videoInfo.getDescription()); + Assert.assertNotNull(videoInfo.getThumbnail()); + Assert.assertNotNull(videoInfo.getUploaderId()); + Assert.assertNotNull(videoInfo.getUploader()); + Assert.assertNotNull(videoInfo.getUploadDate()); + Assert.assertNotNull(videoInfo.getDuration()); + Assert.assertNotNull(videoInfo.getViewCount()); + Assert.assertNotNull(videoInfo.getLikeCount()); + Assert.assertNotNull(videoInfo.getDislikeCount()); + Assert.assertNotNull(videoInfo.getAverageRating()); + //Let's print the whole object + System.out.println("videoInfo:"+videoInfo.toString()); + + + } + + @Test + public void testGetFormats() throws YoutubeDLException { + List formats = YoutubeDLProxychains.getFormats(VIDEO_URL); + System.out.println("formats : "+formats); + Assert.assertNotNull(formats); + Assert.assertTrue(formats.size() > 0); + } + + @Test + public void testGetThumbnails() throws YoutubeDLException { + List thumbnails = YoutubeDLProxychains.getThumbnails(VIDEO_URL); + Assert.assertNotNull(thumbnails); + Assert.assertTrue(thumbnails.size() > 0); + } + + @Test + public void testGetTags() throws YoutubeDLException { + List tags = YoutubeDLProxychains.getTags(VIDEO_URL); + Assert.assertNotNull(tags); + Assert.assertTrue(tags.size() > 0); + } + + @Test + public void testGetCategories() throws YoutubeDLException { + List categories = YoutubeDLProxychains.getCategories(VIDEO_URL); + Assert.assertNotNull(categories); + Assert.assertTrue(categories.size() > 0); + } + + @Test(expected = YoutubeDLException.class) + public void testFailGetNonExistentVideoInfo() throws YoutubeDLException { + YoutubeDLProxychains.getVideoInfo(NONE_EXISTENT_VIDEO_URL); + } +} \ No newline at end of file diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java index 8618ca8..3033139 100644 --- a/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLTest.java @@ -91,30 +91,6 @@ public void testGetVideoInfoInDetails() throws YoutubeDLException { System.out.println("videoInfo:"+videoInfo.toString()); - } - - @Test - public void testGetVideoInfoInDetailsWithProxychains() throws YoutubeDLException { - VideoInfo videoInfo = YoutubeDLProchains.getVideoInfo(VIDEO_URL); - Assert.assertNotNull(videoInfo); - //Let's check we can access key elements from video info - Assert.assertNotNull(videoInfo.getId()); - Assert.assertNotNull(videoInfo.getTitle()); - Assert.assertNotNull(videoInfo.getFulltitle()); - Assert.assertNotNull(videoInfo.getDescription()); - Assert.assertNotNull(videoInfo.getThumbnail()); - Assert.assertNotNull(videoInfo.getUploaderId()); - Assert.assertNotNull(videoInfo.getUploader()); - Assert.assertNotNull(videoInfo.getUploadDate()); - Assert.assertNotNull(videoInfo.getDuration()); - Assert.assertNotNull(videoInfo.getViewCount()); - Assert.assertNotNull(videoInfo.getLikeCount()); - Assert.assertNotNull(videoInfo.getDislikeCount()); - Assert.assertNotNull(videoInfo.getAverageRating()); - //Let's print the whole object - System.out.println("videoInfo:"+videoInfo.toString()); - - } @Test From 7aa82ea4c57bef6d3236a51eda045f2f388124e7 Mon Sep 17 00:00:00 2001 From: memento Date: Mon, 2 Dec 2019 01:43:09 +0100 Subject: [PATCH 12/13] 1.3 was useless before. THIS is the new 1.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f773c5b..9be4d69 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sapher youtubedl - 1.3-with-proxychains + 1.3 jar YoutubeDL wrapper From a62c4bec6af6a69ae4ff3bc6f589df81aa0d9d5a Mon Sep 17 00:00:00 2001 From: Alexandre Date: Thu, 5 Dec 2019 00:08:51 +0100 Subject: [PATCH 13/13] just a release that prints the videoInfo when retrieved. Used for debugging only --- pom.xml | 2 +- src/main/java/com/sapher/youtubedl/YoutubeDL.java | 1 + src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java | 1 + .../java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java | 3 ++- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9be4d69..4b54264 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.sapher youtubedl - 1.3 + 1.3-print-info jar YoutubeDL wrapper diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDL.java b/src/main/java/com/sapher/youtubedl/YoutubeDL.java index 7c60902..00925be 100644 --- a/src/main/java/com/sapher/youtubedl/YoutubeDL.java +++ b/src/main/java/com/sapher/youtubedl/YoutubeDL.java @@ -143,6 +143,7 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { try { videoInfo = objectMapper.readValue(response.getOut(), VideoInfo.class); + System.out.println("videoInfo="+videoInfo.toString()); } catch (IOException e) { throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); } diff --git a/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java b/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java index 753722d..4344795 100644 --- a/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java +++ b/src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java @@ -67,6 +67,7 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException { try { videoInfo = objectMapper.readValue(output, VideoInfo.class); + System.out.println("videoInfo="+videoInfo.toString()); } catch (IOException e) { throw new YoutubeDLException("Unable to parse video information: " + e.getMessage()); } diff --git a/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java b/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java index 97046ac..9af2ace 100644 --- a/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java +++ b/src/test/java/com/sapher/youtubedl/YoutubeDLProxychainsTest.java @@ -12,7 +12,8 @@ public class YoutubeDLProxychainsTest{ private final static String DIRECTORY = System.getProperty("java.io.tmpdir"); - private final static String VIDEO_URL = "https://www.youtube.com/watch?v=nMfPqeZjc2c"; + //private final static String VIDEO_URL = "https://www.youtube.com/watch?v=nMfPqeZjc2c"; + private final static String VIDEO_URL = "https://www.youtube.com/watch?v=x3hGMgd2X14"; private final static String NONE_EXISTENT_VIDEO_URL = "https://www.youtube.com/watch?v=dQw4w9WgXcZ"; /**@Test