Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ target/

# Gradle
.gradle
gradle
gradle

# eclipse
.settings/
.classpath
.project
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,29 @@ dependencies {
}
```

### Maven

*Step 1 :* Add jitpack repository to your pom.xml file

```
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```

*Step 2:* Add the dependency

```
<dependency>
<groupId>com.github.sapher</groupId>
<artifactId>youtubedl-java</artifactId>
<version>1.+</version>
</dependency>
```

## Make request

```java
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.sapher</groupId>
<artifactId>youtubedl</artifactId>
<version>1.1</version>
<version>1.3-print-info</version>
<packaging>jar</packaging>

<name>YoutubeDL wrapper</name>
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/sapher/youtubedl/YoutubeDL.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ public static VideoInfo getVideoInfo(String url) throws YoutubeDLException {
// Parse result
ObjectMapper objectMapper = new ObjectMapper();
VideoInfo videoInfo;

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());
}
Expand Down
133 changes: 133 additions & 0 deletions src/main/java/com/sapher/youtubedl/YoutubeDLProxychains.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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);
System.out.println("videoInfo="+videoInfo.toString());
} 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<VideoFormat> 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<VideoThumbnail> 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<String> 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<String> getTags(String url) throws YoutubeDLException {
//We use proxychains, here
setExecutablePath("proxychains youtube-dl");

VideoInfo info = getVideoInfo(url);
return info.tags;
}
}
118 changes: 118 additions & 0 deletions src/main/java/com/sapher/youtubedl/mapper/VideoInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,63 @@ 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;
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;
Expand All @@ -44,4 +97,69 @@ public class VideoInfo {
public ArrayList<VideoFormat> formats;
public ArrayList<VideoThumbnail> thumbnails;
//public ArrayList<VideoSubtitle> 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 + "\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 + "]";
}



}
Loading